Skip to content

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

C#

Added support for nzo_ids param within History api (#129)

nzbdav-deve0e12ff13952
diff --git a/backend/Api/SabControllers/GetHistory/GetHistoryController.cs b/backend/Api/SabControllers/GetHistory/GetHistoryController.cs
index 956bcd67..1f490feb 100644
--- a/backend/Api/SabControllers/GetHistory/GetHistoryController.cs
+++ b/backend/Api/SabControllers/GetHistory/GetHistoryController.cs
@@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using NzbWebDAV.Config;
using NzbWebDAV.Database;
+using NzbWebDAV.Database.Models;
namespace NzbWebDAV.Api.SabControllers.GetHistory;
@@ -14,19 +15,28 @@ public class GetHistoryController(
{
private async Task<GetHistoryResponse> GetHistoryAsync(GetHistoryRequest request)
{
+ // get query
+ IQueryable<HistoryItem> query = dbClient.Ctx.HistoryItems;
+ if (request.NzoIds.Count > 0)
+ query = query.Where(q => request.NzoIds.Contains(q.Id));
+ if (request.Category != null)
+ query = query.Where(q => q.Category == request.Category);
+
// get total count
- var totalCount = await dbClient.Ctx.HistoryItems
- .Where(q => q.Category == request.Category || request.Category == null)
+ var totalCountPromise = query
.CountAsync(request.CancellationToken);
// get history items
- var historyItems = await dbClient.Ctx.HistoryItems
- .Where(q => q.Category == request.Category || request.Category == null)
+ var historyItemsPromise = query
.OrderByDescending(q => q.CreatedAt)
.Skip(request.Start)
.Take(request.Limit)
.ToArrayAsync(request.CancellationToken);
+ // await results
+ var totalCount = await totalCountPromise;
+ var historyItems = await historyItemsPromise;
+
// get download folders
var downloadFolderIds = historyItems.Select(x => x.DownloadDirId).ToHashSet();
var davItems = await dbClient.Ctx.Items
diff --git a/backend/Api/SabControllers/GetHistory/GetHistoryRequest.cs b/backend/Api/SabControllers/GetHistory/GetHistoryRequest.cs
index 5bc719ae..c168ba5e 100644
--- a/backend/Api/SabControllers/GetHistory/GetHistoryRequest.cs
+++ b/backend/Api/SabControllers/GetHistory/GetHistoryRequest.cs
@@ -9,6 +9,7 @@ public class GetHistoryRequest
public int Start { get; init; } = 0;
public int Limit { get; init; } = int.MaxValue;
public string? Category { get; init; }
+ public List<Guid> NzoIds { get; init; } = [];
public CancellationToken CancellationToken { get; set; }
@@ -17,6 +18,7 @@ public class GetHistoryRequest
var startParam = context.GetQueryParam("start");
var limitParam = context.GetQueryParam("limit");
var pageSizeParam = context.GetQueryParam("pageSize");
+ var nzoIdsParam = context.GetQueryParam("nzo_ids");
Category = context.GetQueryParam("category");
CancellationToken = context.RequestAborted;
@@ -52,5 +54,14 @@ public class GetHistoryRequest
if (!isValidPageSize) throw new BadHttpRequestException("Invalid pageSize parameter");
Limit = pageSize;
}
+
+ if (nzoIdsParam is not null)
+ {
+ NzoIds = nzoIdsParam
+ .Split(',')
+ .Select(nzoId => nzoId.Trim())
+ .Select(Guid.Parse)
+ .ToList();
+ }
}
}
\ No newline at end of file