Usenet streaming with a WebDAV server and a SABnzbd-compatible API
C#
Renamed EnvironmentUtil.GetVariable -> EnvironmentUtil.GetRequiredVariable.
nzbdav-dev4711100d164b
diff --git a/backend/Api/Controllers/BaseApiController.cs b/backend/Api/Controllers/BaseApiController.csindex 37963c34..dde14bad 100644--- a/backend/Api/Controllers/BaseApiController.cs+++ b/backend/Api/Controllers/BaseApiController.cs@@ -21,7 +21,7 @@ public abstract class BaseApiController : ControllerBasevar apiKey = HttpContext.GetRequestApiKey();if (apiKey == null)throw new UnauthorizedAccessException("API Key Required");- if (apiKey != EnvironmentUtil.GetVariable("FRONTEND_BACKEND_API_KEY"))+ if (apiKey != EnvironmentUtil.GetRequiredVariable("FRONTEND_BACKEND_API_KEY"))throw new UnauthorizedAccessException("API Key Incorrect");}diff --git a/backend/Api/Controllers/GetWebdavItem/GetWebdavItemRequest.cs b/backend/Api/Controllers/GetWebdavItem/GetWebdavItemRequest.csindex f4639363..1c1699af 100644--- a/backend/Api/Controllers/GetWebdavItem/GetWebdavItemRequest.cs+++ b/backend/Api/Controllers/GetWebdavItem/GetWebdavItemRequest.cs@@ -46,7 +46,7 @@ public class GetWebdavItemRequestreturn true;}- var apiKey = EnvironmentUtil.GetVariable("FRONTEND_BACKEND_API_KEY");+ var apiKey = EnvironmentUtil.GetRequiredVariable("FRONTEND_BACKEND_API_KEY");return downloadKey == GenerateDownloadKey(apiKey, path);}diff --git a/backend/Api/SabControllers/SabApiController.cs b/backend/Api/SabControllers/SabApiController.csindex 6816ca7b..950be13e 100644--- a/backend/Api/SabControllers/SabApiController.cs+++ b/backend/Api/SabControllers/SabApiController.cs@@ -110,7 +110,7 @@ public class SabApiController(var apiKey = httpContext.GetRequestApiKey();var isValidKey = apiKey?.IsAny(configManager.GetApiKey(),- EnvironmentUtil.GetVariable("FRONTEND_BACKEND_API_KEY")+ EnvironmentUtil.GetRequiredVariable("FRONTEND_BACKEND_API_KEY"));if (!isValidKey.HasValue)throw new UnauthorizedAccessException("API Key Required");diff --git a/backend/Config/ConfigManager.cs b/backend/Config/ConfigManager.csindex ff0c4b93..66155d7a 100644--- a/backend/Config/ConfigManager.cs+++ b/backend/Config/ConfigManager.cs@@ -66,7 +66,7 @@ public class ConfigManagerpublic string GetApiKey(){return StringUtil.EmptyToNull(GetConfigValue("api.key"))- ?? EnvironmentUtil.GetVariable("FRONTEND_BACKEND_API_KEY");+ ?? EnvironmentUtil.GetRequiredVariable("FRONTEND_BACKEND_API_KEY");}public string GetStrmKey()diff --git a/backend/Utils/EnvironmentUtil.cs b/backend/Utils/EnvironmentUtil.csindex 4aee2032..0fc7239e 100644--- a/backend/Utils/EnvironmentUtil.cs+++ b/backend/Utils/EnvironmentUtil.cs@@ -2,7 +2,7 @@public static class EnvironmentUtil{- public static string GetVariable(string envVariable)+ public static string GetRequiredVariable(string envVariable){return Environment.GetEnvironmentVariable(envVariable) ??throw new Exception($"The environment variable `{envVariable}` must be set.");diff --git a/backend/Websocket/WebsocketManager.cs b/backend/Websocket/WebsocketManager.csindex 86322c09..d4a72c19 100644--- a/backend/Websocket/WebsocketManager.cs+++ b/backend/Websocket/WebsocketManager.cs@@ -69,7 +69,7 @@ public class WebsocketManagerprivate static async Task<bool> Authenticate(WebSocket socket){var apiKey = await ReceiveAuthToken(socket).ConfigureAwait(false);- return apiKey == EnvironmentUtil.GetVariable("FRONTEND_BACKEND_API_KEY");+ return apiKey == EnvironmentUtil.GetRequiredVariable("FRONTEND_BACKEND_API_KEY");}/// <summary>