Usenet streaming with a WebDAV server and a SABnzbd-compatible API
C#
Limit `/completed-symlinks` dir to completed items in history (#44)
nzbdav-dev1270d0226e8e
diff --git a/backend/Database/DavDatabaseClient.cs b/backend/Database/DavDatabaseClient.csindex ea0fb896..bd605bfe 100644--- a/backend/Database/DavDatabaseClient.cs+++ b/backend/Database/DavDatabaseClient.cs@@ -1,4 +1,4 @@-using Microsoft.EntityFrameworkCore;+using Microsoft.EntityFrameworkCore;using NzbWebDAV.Database.Models;namespace NzbWebDAV.Database;@@ -138,4 +138,17 @@ public sealed class DavDatabaseClient(DavDatabaseContext ctx){public long TotalSize { get; init; }}++ // completed-symlinks+ public async Task<List<DavItem>> GetCompletedSymlinkCategoryChildren(string category, CancellationToken ct = default)+ {+ var query = from historyItem in Ctx.HistoryItems+ where historyItem.Category == category+ && historyItem.DownloadStatus == HistoryItem.DownloadStatusOption.Completed+ && historyItem.DownloadDirId != null+ join davItem in Ctx.Items on historyItem.DownloadDirId equals davItem.Id+ where davItem.Type == DavItem.ItemType.Directory+ select davItem;+ return await query.Distinct().ToListAsync(ct);+ }}\ No newline at end of filediff --git a/backend/WebDav/DatabaseStoreSymlinkCollection.cs b/backend/WebDav/DatabaseStoreSymlinkCollection.csindex 72ce26f0..bc6fd0dc 100644--- a/backend/WebDav/DatabaseStoreSymlinkCollection.cs+++ b/backend/WebDav/DatabaseStoreSymlinkCollection.cs@@ -41,7 +41,14 @@ public class DatabaseStoreSymlinkCollection(protected override async Task<IStoreItem[]> GetAllItemsAsync(CancellationToken cancellationToken){- return (await dbClient.GetDirectoryChildrenAsync(TargetId, cancellationToken))+ // if we are a category folder within the /completed-symlinks dir,+ // then we only want to show children that correspond to Completed History items.+ var isCategoryFolder = davDirectory.ParentId == DavItem.ContentFolder.Id;+ var children = isCategoryFolder+ ? await dbClient.GetCompletedSymlinkCategoryChildren(davDirectory.Name, cancellationToken)+ : await dbClient.GetDirectoryChildrenAsync(TargetId, cancellationToken);++ return children.Select(GetItem).Where(x => !DeletedFiles.IsDeleted(x.Name)) // must appear after Select(GetItem) for correct Name..ToArray();