Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .tests/history/aurral-history.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,39 @@ test("getAurralHistoryRequests reconciles completed download jobs", async () =>
assert.equal(entry?.inQueue, false);
});

test("getAurralHistoryRequests reconciles pending queued jobs as reused when tracker job is done", async () => {
const jobId = downloadTracker.addJob(
{
artistName: "Artist",
trackName: "Reused Song",
},
"playlist-1",
);
upsertAurralHistory({
referenceId: jobId,
kind: "track_download",
title: "Queueing Reused Song",
subtitle: "Artist · Playlist",
status: "pending",
statusLabel: "Queued",
metadata: {
jobId,
trackName: "Reused Song",
artistName: "Artist",
playlistId: "playlist-1",
},
createdAt: Date.now() - 60 * 1000,
});
downloadTracker.setDone(jobId, "/tmp/reused-song.flac", "Album");

const entries = await getAurralHistoryRequests();
const entry = entries.find((item) => item.jobId === jobId);

assert.equal(entry?.status, "completed");
assert.equal(entry?.statusLabel, "Reused");
assert.equal(entry?.inQueue, false);
});

test("queued library track jobs appear in activity immediately", async () => {
const jobId = downloadTracker.addJob(
{
Expand Down
18 changes: 14 additions & 4 deletions backend/services/aurralHistoryService.js
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,8 @@ export const syncTrackDownloadHistory = async (historyEntries = null) => {
}

if (job.status === "done") {
recordTrackJobCompleted(job);
const isReused = entry.statusLabel === "Queued" || job.sourceType === "aurral" || job.sourceType === "lidarr";
recordTrackJobCompleted(job, isReused ? "Reused" : "Downloaded");
continue;
}
if (job.status === "failed") {
Expand Down Expand Up @@ -936,11 +937,11 @@ export const recordTrackJobMoving = (job) =>
title: `Moving ${job?.trackName || "track"} into playlist library`,
});

export const recordTrackJobCompleted = (job) =>
export const recordTrackJobCompleted = (job, statusLabel = "Downloaded") =>
recordTrackJob(job, {
status: "completed",
statusLabel: "Downloaded",
title: `Downloaded ${job?.trackName || "track"}`,
statusLabel,
title: `${statusLabel === "Reused" ? "Reused" : "Downloaded"} ${job?.trackName || "track"}`,
subtitle: `${job?.artistName || "Artist"} · ${resolvePlaylistName(job?.playlistId || job?.playlistType)}`,
});

Expand Down Expand Up @@ -1087,6 +1088,15 @@ export const getAurralHistoryRequests = async (lidarrClient = null, user = null)
const trackName =
entry.metadata?.trackName ||
(entry.status === "blocked" && job?.trackName ? job.trackName : null);
if (
entry.kind === "track_download" &&
job?.status === "done" &&
(entry.status === "pending" || entry.status === "processing")
) {
const isReused = entry.statusLabel === "Queued" || job.sourceType === "aurral" || job.sourceType === "lidarr";
entry.status = "completed";
entry.statusLabel = isReused ? "Reused" : "Downloaded";
}
return toHistoryRequestItem(entry, { sourceFilename, albumName, trackName });
});
};