diff --git a/allstarr/Controllers/JellyfinController.cs b/allstarr/Controllers/JellyfinController.cs
index e0a8b23..3179cc1 100644
--- a/allstarr/Controllers/JellyfinController.cs
+++ b/allstarr/Controllers/JellyfinController.cs
@@ -1671,6 +1671,9 @@ public class JellyfinController : ControllerBase
// DEBUG: Log EVERY request to see what's happening
_logger.LogWarning("ProxyRequest called with path: {Path}", path);
+ // Log endpoint usage to file for analysis
+ await LogEndpointUsageAsync(path, Request.Method);
+
// Block dangerous admin endpoints
var blockedPrefixes = new[]
{
@@ -1962,6 +1965,37 @@ public class JellyfinController : ControllerBase
}
}
+ ///
+ /// Logs endpoint usage to a file for analysis.
+ /// Creates a CSV file with timestamp, method, path, and query string.
+ ///
+ private async Task LogEndpointUsageAsync(string path, string method)
+ {
+ try
+ {
+ var logDir = "/app/cache/endpoint-usage";
+ Directory.CreateDirectory(logDir);
+
+ var logFile = Path.Combine(logDir, "endpoints.csv");
+ var timestamp = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss");
+ var queryString = Request.QueryString.HasValue ? Request.QueryString.Value : "";
+
+ // Sanitize path and query for CSV (remove commas, quotes, newlines)
+ var sanitizedPath = path.Replace(",", ";").Replace("\"", "'").Replace("\n", " ").Replace("\r", " ");
+ var sanitizedQuery = queryString.Replace(",", ";").Replace("\"", "'").Replace("\n", " ").Replace("\r", " ");
+
+ var logLine = $"{timestamp},{method},{sanitizedPath},{sanitizedQuery}\n";
+
+ // Append to file (thread-safe)
+ await System.IO.File.AppendAllTextAsync(logFile, logLine);
+ }
+ catch (Exception ex)
+ {
+ // Don't let logging failures break the request
+ _logger.LogDebug(ex, "Failed to log endpoint usage");
+ }
+ }
+
private static string[]? ParseItemTypes(string? includeItemTypes)
{
if (string.IsNullOrWhiteSpace(includeItemTypes))
@@ -2484,5 +2518,114 @@ public class JellyfinController : ControllerBase
}
#endregion
+
+ #region Debug & Monitoring
+
+ ///
+ /// Gets endpoint usage statistics from the log file.
+ /// GET /debug/endpoint-usage?api_key=YOUR_KEY
+ /// Optional query params: top=50 (default 100), since=2024-01-01
+ ///
+ [HttpGet("debug/endpoint-usage")]
+ [ServiceFilter(typeof(ApiKeyAuthFilter))]
+ public async Task GetEndpointUsage(
+ [FromQuery] int top = 100,
+ [FromQuery] string? since = null)
+ {
+ try
+ {
+ var logFile = "/app/cache/endpoint-usage/endpoints.csv";
+
+ if (!System.IO.File.Exists(logFile))
+ {
+ return Ok(new
+ {
+ message = "No endpoint usage data collected yet",
+ endpoints = Array.Empty