Skip to content

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

C#

Fixed `DownloadPath` field of history api response.

nzbdav-dev0fee5fc6dc74
diff --git a/backend/Api/SabControllers/GetHistory/GetHistoryController.cs b/backend/Api/SabControllers/GetHistory/GetHistoryController.cs
index a3c9b5da..3683942a 100644
--- a/backend/Api/SabControllers/GetHistory/GetHistoryController.cs
+++ b/backend/Api/SabControllers/GetHistory/GetHistoryController.cs
@@ -19,17 +19,24 @@ public class GetHistoryController(
.Where(q => q.Category == request.Category || request.Category == null)
.CountAsync(request.CancellationToken);
- // get history items
- var historyItems = await dbClient.Ctx.HistoryItems
+ // get history items with joined DavItem data
+ var historyItemsWithDavItems = await dbClient.Ctx.HistoryItems
.Where(q => q.Category == request.Category || request.Category == null)
- .OrderByDescending(q => q.CreatedAt)
+ .GroupJoin(
+ dbClient.Ctx.Items,
+ h => h.DownloadDirId,
+ d => d.Id,
+ (h, d) => new { HistoryItem = h, DavItem = d.FirstOrDefault() }
+ )
+ .OrderByDescending(q => q.HistoryItem.CreatedAt)
.Skip(request.Start)
.Take(request.Limit)
.ToArrayAsync(request.CancellationToken);
// get slots
- var slots = historyItems
- .Select(x => GetHistoryResponse.HistorySlot.FromHistoryItem(x, configManager.GetRcloneMountDir()))
+ var slots = historyItemsWithDavItems
+ .Select(x => GetHistoryResponse.HistorySlot.FromHistoryItem(
+ x.HistoryItem, x.DavItem, configManager.GetRcloneMountDir()))
.ToList();
// return response
diff --git a/backend/Api/SabControllers/GetHistory/GetHistoryResponse.cs b/backend/Api/SabControllers/GetHistory/GetHistoryResponse.cs
index 98a67f92..395385be 100644
--- a/backend/Api/SabControllers/GetHistory/GetHistoryResponse.cs
+++ b/backend/Api/SabControllers/GetHistory/GetHistoryResponse.cs
@@ -39,7 +39,7 @@ public class GetHistoryResponse : SabBaseResponse
public long SizeInBytes { get; set; }
[JsonPropertyName("storage")]
- public string DownloadPath { get; set; }
+ public string? DownloadPath { get; set; }
[JsonPropertyName("download_time")]
public int DownloadTimeSeconds { get; set; }
@@ -47,7 +47,7 @@ public class GetHistoryResponse : SabBaseResponse
[JsonPropertyName("fail_message")]
public string FailMessage { get; set; }
- public static HistorySlot FromHistoryItem(HistoryItem historyItem, string mountDir)
+ public static HistorySlot FromHistoryItem(HistoryItem historyItem, DavItem? downloadFolder, string mountDir)
{
return new HistorySlot()
{
@@ -57,12 +57,12 @@ public class GetHistoryResponse : SabBaseResponse
Category = historyItem.Category,
Status = historyItem.DownloadStatus,
SizeInBytes = historyItem.TotalSegmentBytes,
- DownloadPath = Path.Join(new[]
+ DownloadPath = downloadFolder == null ? null : Path.Join(new[]
{
mountDir,
DavItem.SymlinkFolder.Name,
historyItem.Category,
- historyItem.JobName
+ downloadFolder.Name
}),
DownloadTimeSeconds = historyItem.DownloadTimeSeconds,
FailMessage = historyItem.FailMessage ?? "",
diff --git a/backend/Queue/QueueItemProcessor.cs b/backend/Queue/QueueItemProcessor.cs
index 4feed35d..46dca6ec 100644
--- a/backend/Queue/QueueItemProcessor.cs
+++ b/backend/Queue/QueueItemProcessor.cs
@@ -323,7 +323,7 @@ public class QueueItemProcessor(
var mountFolder = databaseOperations != null ? await databaseOperations.Invoke() : null;
var mountDirectory = configManager.GetRcloneMountDir();
var historyItem = CreateHistoryItem(mountFolder, startTime, error);
- var historySlot = GetHistoryResponse.HistorySlot.FromHistoryItem(historyItem, mountDirectory);
+ var historySlot = GetHistoryResponse.HistorySlot.FromHistoryItem(historyItem, mountFolder, mountDirectory);
dbClient.Ctx.QueueItems.Remove(queueItem);
dbClient.Ctx.HistoryItems.Add(historyItem);
await dbClient.Ctx.SaveChangesAsync(ct);
diff --git a/frontend/app/routes/queue/components/history-table/history-table.tsx b/frontend/app/routes/queue/components/history-table/history-table.tsx
index b771c85c..e6a71962 100644
--- a/frontend/app/routes/queue/components/history-table/history-table.tsx
+++ b/frontend/app/routes/queue/components/history-table/history-table.tsx
@@ -6,6 +6,7 @@ import { ConfirmModal } from "../confirm-modal/confirm-modal"
import { Link } from "react-router"
import { type TriCheckboxState } from "../tri-checkbox/tri-checkbox"
import type { PresentationHistorySlot } from "../../route"
+import { getDirectoryName, getLeafDirectoryName } from "~/utils/path"
export type HistoryTableProps = {
historySlots: PresentationHistorySlot[],
@@ -137,14 +138,7 @@ export function HistoryRow({ slot, onIsSelectedChanged, onIsRemovingChanged, onR
status={slot.status}
error={slot.fail_message}
fileSizeBytes={slot.bytes}
- actions={
- <>
- <Link to={`/explore/content/${slot.category}/${slot.name}`}>
- <ActionButton type="explore" disabled={!!slot.isRemoving} />
- </Link>
- <ActionButton type="delete" disabled={!!slot.isRemoving} onClick={onRemove} />
- </>
- }
+ actions={<Actions slot={slot} onRemove={onRemove} />}
onRowSelectionChanged={isSelected => onIsSelectedChanged(slot.nzo_id, isSelected)}
/>
<ConfirmModal
@@ -157,3 +151,22 @@ export function HistoryRow({ slot, onIsSelectedChanged, onIsRemovingChanged, onR
</>
)
}
+
+export function Actions({ slot, onRemove }: { slot: PresentationHistorySlot, onRemove: () => void }) {
+ var downloadFolder = slot.storage && getLeafDirectoryName(slot.storage);
+ var isFolderDisabled = !downloadFolder || !!slot.isRemoving || !!slot.fail_message;
+
+ return (
+ <>
+ {!isFolderDisabled &&
+ <Link to={`/explore/content/${slot.category}/${downloadFolder}`} >
+ <ActionButton type="explore" />
+ </Link>
+ }
+ {isFolderDisabled &&
+ <ActionButton type="explore" disabled />
+ }
+ <ActionButton type="delete" disabled={!!slot.isRemoving} onClick={onRemove} />
+ </>
+ );
+}
\ No newline at end of file
diff --git a/frontend/app/utils/path.ts b/frontend/app/utils/path.ts
new file mode 100644
index 00000000..42f97535
--- /dev/null
+++ b/frontend/app/utils/path.ts
@@ -0,0 +1,21 @@
+export function getLeafDirectoryName(fullPath: string): string {
+ // Normalize the path by removing a trailing slash/backslash.
+ let normalizedPath = fullPath.replace(/[/\\]$/, '');
+
+ // Find the index of the last separator.
+ const lastSlash = normalizedPath.lastIndexOf('/');
+ const lastBackslash = normalizedPath.lastIndexOf('\\');
+ const lastSeparatorIndex = Math.max(lastSlash, lastBackslash);
+
+ // Extract the final component.
+ // Start the substring *after* the last separator.
+ const leafName = normalizedPath.substring(lastSeparatorIndex + 1);
+
+ // If the result is empty, it means the path was a root (e.g., '/', 'C:').
+ if (leafName.length === 0) {
+ // Return the root component itself (e.g., '/')
+ return normalizedPath;
+ }
+
+ return leafName;
+}
\ No newline at end of file