Skip to content

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

C#

fix: compatability issues with NZBDonkey (#316)

nzbdav-devb2d0f2a4c6b4
diff --git a/backend/Api/SabControllers/GetStatus/GetStatusController.cs b/backend/Api/SabControllers/GetStatus/GetStatusController.cs
new file mode 100644
index 00000000..7cb990d6
--- /dev/null
+++ b/backend/Api/SabControllers/GetStatus/GetStatusController.cs
@@ -0,0 +1,17 @@
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using NzbWebDAV.Config;
+
+namespace NzbWebDAV.Api.SabControllers.GetStatus;
+
+public class GetStatusController(
+ HttpContext httpContext,
+ ConfigManager configManager
+) : SabApiController.BaseController(httpContext, configManager)
+{
+ protected override Task<IActionResult> Handle()
+ {
+ var response = new GetStatusResponse() { Status = true };
+ return Task.FromResult<IActionResult>(Ok(response));
+ }
+}
\ No newline at end of file
diff --git a/backend/Api/SabControllers/GetStatus/GetStatusResponse.cs b/backend/Api/SabControllers/GetStatus/GetStatusResponse.cs
new file mode 100644
index 00000000..fc802346
--- /dev/null
+++ b/backend/Api/SabControllers/GetStatus/GetStatusResponse.cs
@@ -0,0 +1,5 @@
+namespace NzbWebDAV.Api.SabControllers.GetStatus;
+
+public class GetStatusResponse : SabBaseResponse
+{
+}
\ No newline at end of file
diff --git a/backend/Api/SabControllers/SabApiController.cs b/backend/Api/SabControllers/SabApiController.cs
index 16c85f6d..860594d1 100644
--- a/backend/Api/SabControllers/SabApiController.cs
+++ b/backend/Api/SabControllers/SabApiController.cs
@@ -7,6 +7,7 @@ using NzbWebDAV.Api.SabControllers.GetConfig;
using NzbWebDAV.Api.SabControllers.GetFullStatus;
using NzbWebDAV.Api.SabControllers.GetHistory;
using NzbWebDAV.Api.SabControllers.GetQueue;
+using NzbWebDAV.Api.SabControllers.GetStatus;
using NzbWebDAV.Api.SabControllers.GetVersion;
using NzbWebDAV.Api.SabControllers.RemoveFromHistory;
using NzbWebDAV.Api.SabControllers.RemoveFromQueue;
@@ -65,11 +66,14 @@ public class SabApiController(
public BaseController GetController()
{
- switch (HttpContext.GetQueryParam("mode"))
+ switch (HttpContext.GetRequestParam("mode"))
{
case "version":
return new GetVersionController(
HttpContext, configManager);
+ case "status":
+ return new GetStatusController(
+ HttpContext, configManager);
case "get_cats":
return new GetCategoriesController(
HttpContext, configManager);
diff --git a/backend/Extensions/HttpContextExtensions.cs b/backend/Extensions/HttpContextExtensions.cs
index 15174bfc..3dddce03 100644
--- a/backend/Extensions/HttpContextExtensions.cs
+++ b/backend/Extensions/HttpContextExtensions.cs
@@ -1,12 +1,24 @@
using Microsoft.AspNetCore.Http;
+using NzbWebDAV.Utils;
namespace NzbWebDAV.Extensions;
public static class HttpContextExtensions
{
+ public static string? GetRequestParam(this HttpContext httpContext, string key)
+ {
+ return httpContext.GetQueryParam(key)
+ ?? httpContext.GetFormParam(key);
+ }
+
public static string? GetQueryParam(this HttpContext httpContext, string name)
{
- return httpContext.Request.Query[name].FirstOrDefault();
+ return StringUtil.EmptyToNull(httpContext.Request.Query[name].FirstOrDefault());
+ }
+
+ public static string? GetFormParam(this HttpContext httpContext, string name)
+ {
+ return StringUtil.EmptyToNull(httpContext.Request.Form[name].FirstOrDefault());
}
public static IEnumerable<string> GetQueryParamValues(this HttpContext httpContext, string name)
@@ -19,6 +31,6 @@ public static class HttpContextExtensions
public static string? GetRequestApiKey(this HttpContext httpContext)
{
return httpContext.Request.Headers["x-api-key"].FirstOrDefault()
- ?? httpContext.GetQueryParam("apikey");
+ ?? httpContext.GetRequestParam("apikey");
}
}
\ No newline at end of file