Usenet streaming with a WebDAV server and a SABnzbd-compatible API
C#
Refactor RemoveFromHistory api.
nzbdav-devf9ddc688323f
diff --git a/backend/Api/Controllers/ListWebdavDirectory/ListWebdavDirectoryRequest.cs b/backend/Api/Controllers/ListWebdavDirectory/ListWebdavDirectoryRequest.csindex 27d31a4d..1b7e3aa0 100644--- a/backend/Api/Controllers/ListWebdavDirectory/ListWebdavDirectoryRequest.cs+++ b/backend/Api/Controllers/ListWebdavDirectory/ListWebdavDirectoryRequest.cs@@ -1,5 +1,4 @@using Microsoft.AspNetCore.Http;-using NzbWebDAV.Extensions;namespace NzbWebDAV.Api.Controllers.ListWebdavDirectory;diff --git a/backend/Api/Controllers/ListWebdavDirectory/ListWebdavDirectoryResponse.cs b/backend/Api/Controllers/ListWebdavDirectory/ListWebdavDirectoryResponse.csindex af793828..4977c5f3 100644--- a/backend/Api/Controllers/ListWebdavDirectory/ListWebdavDirectoryResponse.cs+++ b/backend/Api/Controllers/ListWebdavDirectory/ListWebdavDirectoryResponse.cs@@ -1,8 +1,4 @@-using Microsoft.AspNetCore.Http;-using NzbWebDAV.Database.Models;-using NzbWebDAV.Extensions;--namespace NzbWebDAV.Api.Controllers.ListWebdavDirectory;+namespace NzbWebDAV.Api.Controllers.ListWebdavDirectory;public class ListWebdavDirectoryResponse{diff --git a/backend/Api/SabControllers/GetHistory/GetHistoryController.cs b/backend/Api/SabControllers/GetHistory/GetHistoryController.csindex ca768727..da579c1a 100644--- a/backend/Api/SabControllers/GetHistory/GetHistoryController.cs+++ b/backend/Api/SabControllers/GetHistory/GetHistoryController.cs@@ -4,7 +4,6 @@ using Microsoft.EntityFrameworkCore;using NzbWebDAV.Config;using NzbWebDAV.Database;using NzbWebDAV.Database.Models;-using NzbWebDAV.Utils;namespace NzbWebDAV.Api.SabControllers.GetHistory;diff --git a/backend/Api/SabControllers/RemoveFromHistory/RemoveFromHistoryController.cs b/backend/Api/SabControllers/RemoveFromHistory/RemoveFromHistoryController.csindex 69f4b1aa..d4d7d557 100644--- a/backend/Api/SabControllers/RemoveFromHistory/RemoveFromHistoryController.cs+++ b/backend/Api/SabControllers/RemoveFromHistory/RemoveFromHistoryController.cs@@ -1,18 +1,17 @@-using Microsoft.AspNetCore.Http;+using Microsoft.AspNetCore.Http;using Microsoft.AspNetCore.Mvc;-using NWebDav.Server.Stores;+using Microsoft.EntityFrameworkCore;using NzbWebDAV.Config;using NzbWebDAV.Database;using NzbWebDAV.Database.Models;-using NzbWebDAV.WebDav;+using NzbWebDAV.Extensions;namespace NzbWebDAV.Api.SabControllers.RemoveFromHistory;public class RemoveFromHistoryController(HttpContext httpContext,DavDatabaseClient dbClient,- ConfigManager configManager,- DatabaseStore store+ ConfigManager configManager) : SabApiController.BaseController(httpContext, configManager){public async Task<RemoveFromHistoryResponse> RemoveFromHistory(RemoveFromHistoryRequest request)@@ -22,17 +21,18 @@ public class RemoveFromHistoryController(if (historyItem is null) return new RemoveFromHistoryResponse() { Status = true };if (request.DeleteCompletedFiles) await DeleteCompletedFiles(historyItem, request.CancellationToken);dbClient.Ctx.HistoryItems.Remove(historyItem);- await dbClient.Ctx.SaveChangesAsync();- await transaction.CommitAsync();+ await dbClient.Ctx.SaveChangesAsync(request.CancellationToken);+ await transaction.CommitAsync(request.CancellationToken);return new RemoveFromHistoryResponse() { Status = true };}- public async Task DeleteCompletedFiles(HistoryItem historyItem, CancellationToken cancellationToken)+ public async Task DeleteCompletedFiles(HistoryItem historyItem, CancellationToken ct){- var categoryPath = Path.Join(DavItem.ContentFolder.Name, historyItem.Category);- var item = await store.GetItemAsync(categoryPath, cancellationToken);- if (item is not IStoreCollection dir) return;- await dir.DeleteItemAsync(historyItem.JobName, cancellationToken);+ if (historyItem.DownloadDirId is null) return;+ var downloadDir = await dbClient.Ctx.Items.FirstOrDefaultAsync(x => x.Id == historyItem.DownloadDirId, ct);+ if (downloadDir is null) return;+ if (downloadDir.IsProtected()) return;+ dbClient.Ctx.Items.Remove(downloadDir);}protected override async Task<IActionResult> Handle()diff --git a/backend/Api/SabControllers/SabApiController.cs b/backend/Api/SabControllers/SabApiController.csindex 5c667003..de77476a 100644--- a/backend/Api/SabControllers/SabApiController.cs+++ b/backend/Api/SabControllers/SabApiController.cs@@ -14,7 +14,6 @@ using NzbWebDAV.Database;using NzbWebDAV.Extensions;using NzbWebDAV.Queue;using NzbWebDAV.Utils;-using NzbWebDAV.WebDav;namespace NzbWebDAV.Api.SabControllers;@@ -23,8 +22,7 @@ namespace NzbWebDAV.Api.SabControllers;public class SabApiController(DavDatabaseClient dbClient,ConfigManager configManager,- QueueManager queueManager,- DatabaseStore databaseStore+ QueueManager queueManager) : ControllerBase{[HttpGet]@@ -83,7 +81,7 @@ public class SabApiController(return new GetQueueController(HttpContext, dbClient, queueManager, configManager);case "history" when HttpContext.GetQueryParam("name") == "delete":- return new RemoveFromHistoryController(HttpContext, dbClient, configManager, databaseStore);+ return new RemoveFromHistoryController(HttpContext, dbClient, configManager);case "history":return new GetHistoryController(HttpContext, dbClient, configManager);diff --git a/backend/Clients/UsenetStreamingClient.cs b/backend/Clients/UsenetStreamingClient.csindex dc5f0233..ecc1dc64 100644--- a/backend/Clients/UsenetStreamingClient.cs+++ b/backend/Clients/UsenetStreamingClient.cs@@ -1,6 +1,4 @@-using System.Text.Json;-using Microsoft.EntityFrameworkCore.Storage.Json;-using Microsoft.Extensions.Caching.Memory;+using Microsoft.Extensions.Caching.Memory;using NzbWebDAV.Clients.Connections;using NzbWebDAV.Config;using NzbWebDAV.Exceptions;diff --git a/backend/WebDav/Base/GetAndHeadHandlerPatch.cs b/backend/WebDav/Base/GetAndHeadHandlerPatch.csindex 8113372b..6507da05 100644--- a/backend/WebDav/Base/GetAndHeadHandlerPatch.cs+++ b/backend/WebDav/Base/GetAndHeadHandlerPatch.cs@@ -1,5 +1,4 @@-using System.Globalization;-using Microsoft.AspNetCore.Http;+using Microsoft.AspNetCore.Http;using NWebDav.Server;using NWebDav.Server.Handlers;using NWebDav.Server.Helpers;diff --git a/backend/WebDav/DatabaseStoreSymlinkFile.cs b/backend/WebDav/DatabaseStoreSymlinkFile.csindex 0b25f313..cc266dd4 100644--- a/backend/WebDav/DatabaseStoreSymlinkFile.cs+++ b/backend/WebDav/DatabaseStoreSymlinkFile.cs@@ -3,7 +3,6 @@ using NWebDav.Server;using NWebDav.Server.Stores;using NzbWebDAV.Config;using NzbWebDAV.Database.Models;-using NzbWebDAV.Utils;using NzbWebDAV.WebDav.Base;using NzbWebDAV.WebDav.Requests;using Serilog;