Usenet streaming with a WebDAV server and a SABnzbd-compatible API
C#
Refactor backend /view endpoint.
nzbdav-dev190b24ba68ec
diff --git a/backend/Api/Controllers/GetWebdavItem/GetWebdavItemController.cs b/backend/Api/Controllers/GetWebdavItem/GetWebdavItemController.csindex 9e5460a4..4a1c71d3 100644--- a/backend/Api/Controllers/GetWebdavItem/GetWebdavItemController.cs+++ b/backend/Api/Controllers/GetWebdavItem/GetWebdavItemController.cs@@ -9,12 +9,10 @@ namespace NzbWebDAV.Api.Controllers.GetWebdavItem;[ApiController][Route("view/{*path}")]-public class ListWebdavDirectoryController(DatabaseStore store) : BaseApiController+public class ListWebdavDirectoryController(DatabaseStore store) : ControllerBase{private static readonly FileExtensionContentTypeProvider MimeTypeProvider = new();- protected override bool RequiresAuthentication => false;-private async Task<Stream> GetWebdavItem(GetWebdavItemRequest request){var item = await store.GetItemAsync(request.Item, HttpContext.RequestAborted);@@ -52,12 +50,19 @@ public class ListWebdavDirectoryController(DatabaseStore store) : BaseApiControlreturn stream;}- protected override async Task<IActionResult> HandleRequest()+ [HttpGet]+ public async Task HandleRequest(){- var request = new GetWebdavItemRequest(HttpContext);- await using var response = await GetWebdavItem(request);- await response.CopyToAsync(Response.Body, bufferSize: 1024, HttpContext.RequestAborted);- return new EmptyResult();+ try+ {+ var request = new GetWebdavItemRequest(HttpContext);+ await using var response = await GetWebdavItem(request);+ await response.CopyToAsync(Response.Body, bufferSize: 1024, HttpContext.RequestAborted);+ }+ catch (UnauthorizedAccessException)+ {+ Response.StatusCode = 401;+ }}private static string GetContentType(string item)diff --git a/backend/Api/Controllers/GetWebdavItem/GetWebdavItemRequest.cs b/backend/Api/Controllers/GetWebdavItem/GetWebdavItemRequest.csindex d9019fee..3aa1444a 100644--- a/backend/Api/Controllers/GetWebdavItem/GetWebdavItemRequest.cs+++ b/backend/Api/Controllers/GetWebdavItem/GetWebdavItemRequest.cs@@ -23,7 +23,7 @@ public class GetWebdavItemRequest// skip auth check for nowvar downloadKey = context.Request.Query["downloadKey"];if (!VerifyDownloadKey(downloadKey, Item))- throw new BadHttpRequestException("Invalid download key");+ throw new UnauthorizedAccessException("Invalid download key");// parse range header