Skip to content

Usenet streaming with a WebDAV server and a SABnzbd-compatible API

C#

fix: NZBDonkey compatibility issues with nzb category (#316)

nzbdav-dev7059b10c4fb7
diff --git a/backend/Api/SabControllers/AddFile/AddFileRequest.cs b/backend/Api/SabControllers/AddFile/AddFileRequest.cs
index 53df8ed0..49ed8d8a 100644
--- a/backend/Api/SabControllers/AddFile/AddFileRequest.cs
+++ b/backend/Api/SabControllers/AddFile/AddFileRequest.cs
@@ -28,9 +28,9 @@ public class AddFileRequest()
FileName = file.FileName,
ContentType = file.ContentType,
NzbFileStream = file.OpenReadStream(),
- Category = context.GetQueryParam("cat") ?? configManager.GetManualUploadCategory(),
- Priority = MapPriorityOption(context.GetQueryParam("priority")),
- PostProcessing = MapPostProcessingOption(context.GetQueryParam("pp")),
+ Category = context.GetRequestParam("cat") ?? configManager.GetManualUploadCategory(),
+ Priority = MapPriorityOption(context.GetRequestParam("priority")),
+ PostProcessing = MapPostProcessingOption(context.GetRequestParam("pp")),
CancellationToken = context.RequestAborted
};
}
diff --git a/backend/Api/SabControllers/AddUrl/AddUrlRequest.cs b/backend/Api/SabControllers/AddUrl/AddUrlRequest.cs
index 230b9c91..81cc66ed 100644
--- a/backend/Api/SabControllers/AddUrl/AddUrlRequest.cs
+++ b/backend/Api/SabControllers/AddUrl/AddUrlRequest.cs
@@ -13,8 +13,8 @@ public class AddUrlRequest() : AddFileRequest
public static async Task<AddUrlRequest> New(HttpContext context, ConfigManager configManager)
{
- var nzbUrl = context.GetQueryParam("name");
- var nzbName = context.GetQueryParam("nzbname");
+ var nzbUrl = context.GetRequestParam("name");
+ var nzbName = context.GetRequestParam("nzbname");
var userAgent = configManager.GetUserAgent();
var nzbFile = await GetNzbFile(nzbUrl, nzbName, userAgent).ConfigureAwait(false);
return new AddUrlRequest()
@@ -22,9 +22,9 @@ public class AddUrlRequest() : AddFileRequest
FileName = nzbFile.FileName,
ContentType = nzbFile.ContentType,
NzbFileStream = nzbFile.FileStream,
- Category = context.GetQueryParam("cat") ?? configManager.GetManualUploadCategory(),
- Priority = MapPriorityOption(context.GetQueryParam("priority")),
- PostProcessing = MapPostProcessingOption(context.GetQueryParam("pp")),
+ Category = context.GetRequestParam("cat") ?? configManager.GetManualUploadCategory(),
+ Priority = MapPriorityOption(context.GetRequestParam("priority")),
+ PostProcessing = MapPostProcessingOption(context.GetRequestParam("pp")),
CancellationToken = context.RequestAborted
};
}
diff --git a/backend/Api/SabControllers/GetHistory/GetHistoryRequest.cs b/backend/Api/SabControllers/GetHistory/GetHistoryRequest.cs
index c168ba5e..9da41c87 100644
--- a/backend/Api/SabControllers/GetHistory/GetHistoryRequest.cs
+++ b/backend/Api/SabControllers/GetHistory/GetHistoryRequest.cs
@@ -15,11 +15,11 @@ public class GetHistoryRequest
public GetHistoryRequest(HttpContext context, ConfigManager configManager)
{
- var startParam = context.GetQueryParam("start");
- var limitParam = context.GetQueryParam("limit");
- var pageSizeParam = context.GetQueryParam("pageSize");
- var nzoIdsParam = context.GetQueryParam("nzo_ids");
- Category = context.GetQueryParam("category");
+ var startParam = context.GetRequestParam("start");
+ var limitParam = context.GetRequestParam("limit");
+ var pageSizeParam = context.GetRequestParam("pageSize");
+ var nzoIdsParam = context.GetRequestParam("nzo_ids");
+ Category = context.GetRequestParam("category");
CancellationToken = context.RequestAborted;
if (startParam is not null)
diff --git a/backend/Api/SabControllers/GetQueue/GetQueueRequest.cs b/backend/Api/SabControllers/GetQueue/GetQueueRequest.cs
index a895d120..5e13143b 100644
--- a/backend/Api/SabControllers/GetQueue/GetQueueRequest.cs
+++ b/backend/Api/SabControllers/GetQueue/GetQueueRequest.cs
@@ -13,9 +13,9 @@ public class GetQueueRequest
public GetQueueRequest(HttpContext context)
{
- var startParam = context.GetQueryParam("start");
- var limitParam = context.GetQueryParam("limit");
- Category = context.GetQueryParam("category");
+ var startParam = context.GetRequestParam("start");
+ var limitParam = context.GetRequestParam("limit");
+ Category = context.GetRequestParam("category");
CancellationToken = context.RequestAborted;
if (startParam is not null)
diff --git a/backend/Api/SabControllers/RemoveFromHistory/RemoveFromHistoryRequest.cs b/backend/Api/SabControllers/RemoveFromHistory/RemoveFromHistoryRequest.cs
index e903d221..2f1c7ced 100644
--- a/backend/Api/SabControllers/RemoveFromHistory/RemoveFromHistoryRequest.cs
+++ b/backend/Api/SabControllers/RemoveFromHistory/RemoveFromHistoryRequest.cs
@@ -30,7 +30,7 @@ public class RemoveFromHistoryRequest
NzoIds = NzoIdsFromQueryParam(httpContext)
.Concat(await NzoIdsFromRequestBody(httpContext, cancellationToken).ConfigureAwait(false))
.ToList(),
- DeleteCompletedFiles = httpContext.GetQueryParam("del_completed_files") == "1",
+ DeleteCompletedFiles = httpContext.GetRequestParam("del_completed_files") == "1",
CancellationToken = cancellationToken
};
}
diff --git a/backend/Api/SabControllers/SabApiController.cs b/backend/Api/SabControllers/SabApiController.cs
index 860594d1..6eb267aa 100644
--- a/backend/Api/SabControllers/SabApiController.cs
+++ b/backend/Api/SabControllers/SabApiController.cs
@@ -90,14 +90,14 @@ public class SabApiController(
return new AddUrlController(
HttpContext, dbClient, queueManager, configManager, websocketManager);
- case "queue" when HttpContext.GetQueryParam("name") == "delete":
+ case "queue" when HttpContext.GetRequestParam("name") == "delete":
return new RemoveFromQueueController(
HttpContext, dbClient, queueManager, configManager, websocketManager);
case "queue":
return new GetQueueController(
HttpContext, dbClient, queueManager, configManager);
- case "history" when HttpContext.GetQueryParam("name") == "delete":
+ case "history" when HttpContext.GetRequestParam("name") == "delete":
return new RemoveFromHistoryController(
HttpContext, dbClient, configManager, websocketManager);
case "history":
diff --git a/backend/Extensions/HttpContextExtensions.cs b/backend/Extensions/HttpContextExtensions.cs
index 3dddce03..61d6ac35 100644
--- a/backend/Extensions/HttpContextExtensions.cs
+++ b/backend/Extensions/HttpContextExtensions.cs
@@ -18,7 +18,9 @@ public static class HttpContextExtensions
public static string? GetFormParam(this HttpContext httpContext, string name)
{
- return StringUtil.EmptyToNull(httpContext.Request.Form[name].FirstOrDefault());
+ return httpContext.Request.HasFormContentType
+ ? StringUtil.EmptyToNull(httpContext.Request.Form[name].FirstOrDefault())
+ : null;
}
public static IEnumerable<string> GetQueryParamValues(this HttpContext httpContext, string name)