Usenet streaming with a WebDAV server and a SABnzbd-compatible API
C#
Added backend option to ignore sabnzbd-api history limit.
nzbdav-deva37b20ed8b83
diff --git a/backend/Api/SabControllers/GetHistory/GetHistoryController.cs b/backend/Api/SabControllers/GetHistory/GetHistoryController.csindex ca5d70b8..a3c9b5da 100644--- a/backend/Api/SabControllers/GetHistory/GetHistoryController.cs+++ b/backend/Api/SabControllers/GetHistory/GetHistoryController.cs@@ -45,7 +45,7 @@ public class GetHistoryController(protected override async Task<IActionResult> Handle(){- var request = new GetHistoryRequest(httpContext);+ var request = new GetHistoryRequest(httpContext, configManager);return Ok(await GetHistoryAsync(request));}}\ No newline at end of filediff --git a/backend/Api/SabControllers/GetHistory/GetHistoryRequest.cs b/backend/Api/SabControllers/GetHistory/GetHistoryRequest.csindex efb2fadb..5bc719ae 100644--- a/backend/Api/SabControllers/GetHistory/GetHistoryRequest.cs+++ b/backend/Api/SabControllers/GetHistory/GetHistoryRequest.cs@@ -1,4 +1,5 @@using Microsoft.AspNetCore.Http;+using NzbWebDAV.Config;using NzbWebDAV.Extensions;namespace NzbWebDAV.Api.SabControllers.GetHistory;@@ -11,10 +12,11 @@ public class GetHistoryRequestpublic CancellationToken CancellationToken { get; set; }- public GetHistoryRequest(HttpContext context)+ public GetHistoryRequest(HttpContext context, ConfigManager configManager){var startParam = context.GetQueryParam("start");var limitParam = context.GetQueryParam("limit");+ var pageSizeParam = context.GetQueryParam("pageSize");Category = context.GetQueryParam("category");CancellationToken = context.RequestAborted;@@ -25,11 +27,30 @@ public class GetHistoryRequestStart = start;}- if (limitParam is not null)+ // The official Sabnzbd api uses the `limit` param to specify the number of history items+ // that should be returned in the response. However, radarr/sonarr set this param to 60 items+ // which causes problems:+ // * https://github.com/nzbdav-dev/nzbdav/issues/48+ // * https://github.com/Sonarr/Sonarr/issues/5452+ //+ // Because of this, NzbDAV added a setting to ignore the `limit` value specified by the Arrs.+ // When this setting is enabled, we always return all history items.+ if (limitParam is not null && !configManager.IsIgnoreSabHistoryLimitEnabled()){- var isValidLimit = int.TryParse(limitParam, out int limit);+ var isValidLimit = int.TryParse(limitParam, out var limit);if (!isValidLimit) throw new BadHttpRequestException("Invalid limit parameter");Limit = limit;}++ // Even though we may want to ignore the `limit` param from the Arrs, NzbDAV frontend+ // still needs a way to limit the pageSize for pagination. The `pageSize` param is used+ // for this, which takes precedence over the `limit` param. This param is not official to+ // the Sabnzbd api, and is intended to be used only by the NzbDAV frontend.+ if (pageSizeParam is not null)+ {+ var isValidPageSize = int.TryParse(pageSizeParam, out var pageSize);+ if (!isValidPageSize) throw new BadHttpRequestException("Invalid pageSize parameter");+ Limit = pageSize;+ }}}\ No newline at end of filediff --git a/backend/Config/ConfigManager.cs b/backend/Config/ConfigManager.csindex e361760c..7487bf60 100644--- a/backend/Config/ConfigManager.cs+++ b/backend/Config/ConfigManager.cs@@ -156,6 +156,13 @@ public class ConfigManagerreturn (configValue != null ? bool.Parse(configValue) : defaultValue);}+ public bool IsIgnoreSabHistoryLimitEnabled()+ {+ var defaultValue = true;+ var configValue = StringUtil.EmptyToNull(GetConfigValue("api.ignore-history-limit"));+ return (configValue != null ? bool.Parse(configValue) : defaultValue);+ }+public ArrConfig GetArrConfig(){var defaultValue = new ArrConfig();