feat(web): every Collection queue can remove the file and keep the track
release / web (push) Failing after 1m28s
release / go (push) Successful in 1m53s
release / govulncheck (push) Successful in 18s
release / integration (push) Successful in 4m16s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / Build signed APK (push) Canceled after 2m13s
release / android (push) Canceled after 2m59s
release / web (push) Failing after 1m28s
release / go (push) Successful in 1m53s
release / govulncheck (push) Successful in 18s
release / integration (push) Successful in 4m16s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / Build signed APK (push) Canceled after 2m13s
release / android (push) Canceled after 2m59s
Reports offers "Remove the file" ahead of "Remove from library": the bad file goes and the track waits in Needs a file, with its likes and plays, for a good copy. Suspect sources gets "Remove this file", and the Duplicates wrong-slot action and its route are named for what they do (remove-files). Their toasts and copy name Needs a file. Missing files becomes Needs a file in the rail, the Collection header and the Overview counts. Each track says why it waits and who removed it, and can be forgotten one at a time or by folder; the list exports as a CSV or copies to the clipboard. The empty state says how a track gets there and how it leaves. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -452,21 +452,21 @@ func (h *handlers) handleMergeDuplicateGroup(w http.ResponseWriter, r *http.Requ
|
|||||||
writeJSON(w, http.StatusOK, resp)
|
writeJSON(w, http.StatusOK, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
// refetchDuplicateRequest is an admin's answer for one recording filling
|
// wrongSlotRequest is an admin's answer for one recording filling
|
||||||
// several of an album's slots. keep_track_id is the copy whose title the
|
// several of an album's slots. keep_track_id is the copy whose title the
|
||||||
// recording is; empty means they cannot say, and every copy goes.
|
// recording is; empty means they cannot say, and every copy goes.
|
||||||
type refetchDuplicateRequest struct {
|
type wrongSlotRequest struct {
|
||||||
KeepTrackID string `json:"keep_track_id"`
|
KeepTrackID string `json:"keep_track_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// refetchDuplicateResponse reports what went.
|
// wrongSlotResponse reports what went.
|
||||||
type refetchDuplicateResponse struct {
|
type wrongSlotResponse struct {
|
||||||
KeptTrackID *string `json:"kept_track_id"`
|
KeptTrackID *string `json:"kept_track_id"`
|
||||||
RemovedPaths []string `json:"removed_paths"`
|
RemovedPaths []string `json:"removed_paths"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleRefetchDuplicateGroup implements POST
|
// handleRemoveWrongSlotFiles implements POST
|
||||||
// /api/admin/library/duplicates/{id}/refetch: settle a group of one
|
// /api/admin/library/duplicates/{id}/remove-files: settle a group of one
|
||||||
// recording in several slots of an album the way the resolver would, with an
|
// recording in several slots of an album the way the resolver would, with an
|
||||||
// admin's answer. The copies in slots that are not the recording's are
|
// admin's answer. The copies in slots that are not the recording's are
|
||||||
// removed and marked missing, so the slot shows as missing until a good copy
|
// removed and marked missing, so the slot shows as missing until a good copy
|
||||||
@@ -479,7 +479,7 @@ type refetchDuplicateResponse struct {
|
|||||||
// - 404 duplicate_group_not_pending when the group was already resolved
|
// - 404 duplicate_group_not_pending when the group was already resolved
|
||||||
// - 400 not_wrong_slot when the group is not one recording in several slots
|
// - 400 not_wrong_slot when the group is not one recording in several slots
|
||||||
// - 400 survivor_not_in_group, invalid_id, invalid_body
|
// - 400 survivor_not_in_group, invalid_id, invalid_body
|
||||||
func (h *handlers) handleRefetchDuplicateGroup(w http.ResponseWriter, r *http.Request) {
|
func (h *handlers) handleRemoveWrongSlotFiles(w http.ResponseWriter, r *http.Request) {
|
||||||
admin, ok := requireUser(w, r)
|
admin, ok := requireUser(w, r)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
@@ -489,7 +489,7 @@ func (h *handlers) handleRefetchDuplicateGroup(w http.ResponseWriter, r *http.Re
|
|||||||
writeAdminJSONErr(w, http.StatusBadRequest, "invalid_id")
|
writeAdminJSONErr(w, http.StatusBadRequest, "invalid_id")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var body refetchDuplicateRequest
|
var body wrongSlotRequest
|
||||||
if err := json.NewDecoder(http.MaxBytesReader(w, r.Body, mergeRequestBodyLimit)).Decode(&body); err != nil && !errors.Is(err, io.EOF) {
|
if err := json.NewDecoder(http.MaxBytesReader(w, r.Body, mergeRequestBodyLimit)).Decode(&body); err != nil && !errors.Is(err, io.EOF) {
|
||||||
writeAdminJSONErr(w, http.StatusBadRequest, "invalid_body")
|
writeAdminJSONErr(w, http.StatusBadRequest, "invalid_body")
|
||||||
return
|
return
|
||||||
@@ -517,13 +517,13 @@ func (h *handlers) handleRefetchDuplicateGroup(w http.ResponseWriter, r *http.Re
|
|||||||
case errors.Is(err, library.ErrSurvivorNotInGroup):
|
case errors.Is(err, library.ErrSurvivorNotInGroup):
|
||||||
writeAdminJSONErr(w, http.StatusBadRequest, "survivor_not_in_group")
|
writeAdminJSONErr(w, http.StatusBadRequest, "survivor_not_in_group")
|
||||||
default:
|
default:
|
||||||
h.logger.Error("admin: refetch duplicate group", "group_id", uuidToString(groupID), "err", err)
|
h.logger.Error("admin: remove wrong-slot files", "group_id", uuidToString(groupID), "err", err)
|
||||||
writeAdminJSONErr(w, http.StatusInternalServerError, "server_error")
|
writeAdminJSONErr(w, http.StatusInternalServerError, "server_error")
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := refetchDuplicateResponse{RemovedPaths: make([]string, 0, len(res.Removed))}
|
resp := wrongSlotResponse{RemovedPaths: make([]string, 0, len(res.Removed))}
|
||||||
if res.Kept != nil {
|
if res.Kept != nil {
|
||||||
id := uuidToString(res.Kept.TrackID)
|
id := uuidToString(res.Kept.TrackID)
|
||||||
resp.KeptTrackID = &id
|
resp.KeptTrackID = &id
|
||||||
|
|||||||
+1
-1
@@ -247,7 +247,7 @@ func Mount(r chi.Router, pool *pgxpool.Pool, logger *slog.Logger, events *playev
|
|||||||
admin.Post("/library/duplicates/sweep", h.handleRunDuplicateSweep)
|
admin.Post("/library/duplicates/sweep", h.handleRunDuplicateSweep)
|
||||||
admin.Post("/library/duplicates/{id}/dismiss", h.handleDismissDuplicateGroup)
|
admin.Post("/library/duplicates/{id}/dismiss", h.handleDismissDuplicateGroup)
|
||||||
admin.Post("/library/duplicates/{id}/merge", h.handleMergeDuplicateGroup)
|
admin.Post("/library/duplicates/{id}/merge", h.handleMergeDuplicateGroup)
|
||||||
admin.Post("/library/duplicates/{id}/refetch", h.handleRefetchDuplicateGroup)
|
admin.Post("/library/duplicates/{id}/remove-files", h.handleRemoveWrongSlotFiles)
|
||||||
|
|
||||||
admin.Get("/invites", h.handleListInvites)
|
admin.Get("/invites", h.handleListInvites)
|
||||||
admin.Post("/invites", h.handleCreateInvite)
|
admin.Post("/invites", h.handleCreateInvite)
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ export type QueueKey = keyof AdminSummary;
|
|||||||
export type QueueDef = {
|
export type QueueDef = {
|
||||||
key: QueueKey;
|
key: QueueKey;
|
||||||
href: string;
|
href: string;
|
||||||
// How the Overview names a count of them: "2 missing files".
|
// How the Overview names a count of them: "2 tracks need a file".
|
||||||
one: string;
|
one: string;
|
||||||
many: string;
|
many: string;
|
||||||
// How the Overview's healthy line names an empty one: "no missing files".
|
// How the Overview's healthy line names an empty one: "no tracks waiting for a file".
|
||||||
none: string;
|
none: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ export const QUEUES: QueueDef[] = [
|
|||||||
{ key: 'reports', href: '/collection/reports', one: 'broken track reported', many: 'broken tracks reported', none: 'reports' },
|
{ key: 'reports', href: '/collection/reports', one: 'broken track reported', many: 'broken tracks reported', none: 'reports' },
|
||||||
{ key: 'duplicates', href: '/collection/duplicates', one: 'set of duplicates to review', many: 'sets of duplicates to review', none: 'duplicates' },
|
{ key: 'duplicates', href: '/collection/duplicates', one: 'set of duplicates to review', many: 'sets of duplicates to review', none: 'duplicates' },
|
||||||
{ key: 'suspect', href: '/collection/suspect-sources', one: 'track from a suspect source', many: 'tracks from suspect sources', none: 'suspect sources' },
|
{ key: 'suspect', href: '/collection/suspect-sources', one: 'track from a suspect source', many: 'tracks from suspect sources', none: 'suspect sources' },
|
||||||
{ key: 'missing', href: '/collection/missing', one: 'missing file', many: 'missing files', none: 'missing files' }
|
{ key: 'missing', href: '/collection/missing', one: 'track needs a file', many: 'tracks need a file', none: 'tracks waiting for a file' }
|
||||||
];
|
];
|
||||||
|
|
||||||
export function countOf(summary: AdminSummary | undefined, key: QueueKey): number {
|
export function countOf(summary: AdminSummary | undefined, key: QueueKey): number {
|
||||||
|
|||||||
@@ -93,7 +93,8 @@ export type HandledRow = { key: string; title: string; artist: string; what: str
|
|||||||
|
|
||||||
const ACTION_LABELS: Record<QuarantineActionRow['action'], string> = {
|
const ACTION_LABELS: Record<QuarantineActionRow['action'], string> = {
|
||||||
resolved: 'Reports cleared',
|
resolved: 'Reports cleared',
|
||||||
deleted_file: 'File deleted',
|
removed_file: 'File removed, track waits for a good copy',
|
||||||
|
deleted_file: 'Removed from the library',
|
||||||
deleted_album: 'Album deleted'
|
deleted_album: 'Album deleted'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import type {
|
|||||||
AdminDuplicatesResponse,
|
AdminDuplicatesResponse,
|
||||||
DuplicatesView,
|
DuplicatesView,
|
||||||
MergeDuplicateResult,
|
MergeDuplicateResult,
|
||||||
RefetchDuplicateResult,
|
WrongSlotRemoval,
|
||||||
ResolvedDuplicatesResponse,
|
ResolvedDuplicatesResponse,
|
||||||
AdminPlaybackError,
|
AdminPlaybackError,
|
||||||
AdminQuarantineRow,
|
AdminQuarantineRow,
|
||||||
@@ -61,6 +61,13 @@ export async function resolveQuarantine(trackID: string): Promise<ActionResult>
|
|||||||
return api.post<ActionResult>(`/api/admin/quarantine/${trackID}/resolve`, {});
|
return api.post<ActionResult>(`/api/admin/quarantine/${trackID}/resolve`, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Removes the reported file and keeps the track, which waits in Needs a file
|
||||||
|
// for a good copy. Its reports and playback errors are settled with it.
|
||||||
|
export async function removeQuarantineFile(trackID: string): Promise<ActionResult> {
|
||||||
|
return api.post<ActionResult>(`/api/admin/quarantine/${trackID}/remove-file`, {});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Removes the track from the library with its file, history and all.
|
||||||
export async function deleteQuarantineFile(trackID: string): Promise<ActionResult> {
|
export async function deleteQuarantineFile(trackID: string): Promise<ActionResult> {
|
||||||
return api.post<ActionResult>(`/api/admin/quarantine/${trackID}/delete-file`, {});
|
return api.post<ActionResult>(`/api/admin/quarantine/${trackID}/delete-file`, {});
|
||||||
}
|
}
|
||||||
@@ -834,14 +841,15 @@ export async function mergeDuplicateGroup(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// One recording in several of an album's slots: keep the copy whose
|
// One recording in several of an album's slots: keep the copy whose title it
|
||||||
// title it is, or none (empty keep_track_id), and fetch the album again.
|
// is, or none (empty keep_track_id). The other copies' files go and their
|
||||||
export async function refetchDuplicateGroup(
|
// tracks wait in Needs a file for a good copy.
|
||||||
|
export async function removeWrongSlotFiles(
|
||||||
id: string,
|
id: string,
|
||||||
body: { keep_track_id: string }
|
body: { keep_track_id: string }
|
||||||
): Promise<RefetchDuplicateResult> {
|
): Promise<WrongSlotRemoval> {
|
||||||
return api.post<RefetchDuplicateResult>(
|
return api.post<WrongSlotRemoval>(
|
||||||
`/api/admin/library/duplicates/${encodeURIComponent(id)}/refetch`,
|
`/api/admin/library/duplicates/${encodeURIComponent(id)}/remove-files`,
|
||||||
body
|
body
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -850,7 +858,7 @@ export async function dismissDuplicateGroup(id: string): Promise<void> {
|
|||||||
await api.post(`/api/admin/library/duplicates/${encodeURIComponent(id)}/dismiss`, {});
|
await api.post(`/api/admin/library/duplicates/${encodeURIComponent(id)}/dismiss`, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Missing files -----------------------------------------------------
|
// Needs a file ------------------------------------------------------
|
||||||
|
|
||||||
export async function listMissingFiles(
|
export async function listMissingFiles(
|
||||||
offset: number = 0,
|
offset: number = 0,
|
||||||
@@ -876,6 +884,16 @@ export function createMissingFilesQuery(offset: number = 0, limit: number = 50)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Forgets tracks waiting for a file, for good: each goes with its likes, plays
|
||||||
|
// and playlist places. All or nothing; a track whose file is back is refused.
|
||||||
|
export async function forgetMissingTracks(trackIds: string[]): Promise<{ forgotten: number }> {
|
||||||
|
return api.post<{ forgotten: number }>('/api/admin/library/missing/forget', { track_ids: trackIds });
|
||||||
|
}
|
||||||
|
|
||||||
|
// The whole list as a CSV, to hand to whatever finds music. A plain link
|
||||||
|
// downloads it: the session cookie goes with it.
|
||||||
|
export const MISSING_FILES_CSV_URL = '/api/admin/library/missing.csv';
|
||||||
|
|
||||||
// Suspect sources --------------------------------------------------
|
// Suspect sources --------------------------------------------------
|
||||||
|
|
||||||
export const SUSPECT_SOURCES_PAGE_SIZE = 50;
|
export const SUSPECT_SOURCES_PAGE_SIZE = 50;
|
||||||
@@ -910,6 +928,12 @@ export async function setSuspectVerdict(trackId: string, verdict: SuspectVerdict
|
|||||||
await api.put(`/api/admin/library/suspect-sources/${encodeURIComponent(trackId)}`, { verdict });
|
await api.put(`/api/admin/library/suspect-sources/${encodeURIComponent(trackId)}`, { verdict });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Removes a suspect source's file and keeps its track, which waits in Needs a
|
||||||
|
// file for a clean copy.
|
||||||
|
export async function removeSuspectFile(trackId: string): Promise<void> {
|
||||||
|
await api.post(`/api/admin/library/suspect-sources/${encodeURIComponent(trackId)}/remove`, {});
|
||||||
|
}
|
||||||
|
|
||||||
// Notification emails: when the grouped emails go out.
|
// Notification emails: when the grouped emails go out.
|
||||||
export type NotificationEmailSettings = {
|
export type NotificationEmailSettings = {
|
||||||
summary_hour: number;
|
summary_hour: number;
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ export type AdminPlaybackError = {
|
|||||||
|
|
||||||
// deleted_album is history: an album removed whole, before Minstrel filed its
|
// deleted_album is history: an album removed whole, before Minstrel filed its
|
||||||
// own music.
|
// own music.
|
||||||
export type QuarantineAction = 'resolved' | 'deleted_file' | 'deleted_album';
|
export type QuarantineAction = 'resolved' | 'removed_file' | 'deleted_file' | 'deleted_album';
|
||||||
|
|
||||||
export type QuarantineActionRow = {
|
export type QuarantineActionRow = {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -247,13 +247,18 @@ export type HomePayload = {
|
|||||||
you_might_like_artists: ArtistRef[];
|
you_might_like_artists: ArtistRef[];
|
||||||
};
|
};
|
||||||
|
|
||||||
// Missing files -----------------------------------------------------
|
// Needs a file ------------------------------------------------------
|
||||||
|
|
||||||
// One track whose file the scan could not find. The text fields come from the
|
// Which Collection queue a track's file was removed from. A track with none
|
||||||
// tracks row rather than the filesystem — the recording is still a known thing
|
// went missing from disk on its own.
|
||||||
// with a history, only its bytes are absent. last_played_at is null for a file
|
export type RemovedFor = 'report' | 'duplicate' | 'suspect';
|
||||||
// that was never played, which is the signal that separates "worth chasing"
|
|
||||||
// from "let it go".
|
// One track waiting for a file. The text fields come from the tracks row
|
||||||
|
// rather than the filesystem — the recording is still a known thing with a
|
||||||
|
// history, only its bytes are absent. last_played_at is null for a file that
|
||||||
|
// was never played, which is the signal that separates "worth chasing" from
|
||||||
|
// "let it go". removed_by is the admin who removed it, null for the duplicate
|
||||||
|
// checker or a file gone from disk.
|
||||||
export type AdminMissingTrack = {
|
export type AdminMissingTrack = {
|
||||||
track_id: string;
|
track_id: string;
|
||||||
title: string;
|
title: string;
|
||||||
@@ -263,6 +268,12 @@ export type AdminMissingTrack = {
|
|||||||
album_title: string;
|
album_title: string;
|
||||||
file_path: string;
|
file_path: string;
|
||||||
duration_sec: number;
|
duration_sec: number;
|
||||||
|
disc_number: number | null;
|
||||||
|
track_number: number | null;
|
||||||
|
recording_mbid: string | null;
|
||||||
|
release_group_mbid: string | null;
|
||||||
|
removed_for: RemovedFor | null;
|
||||||
|
removed_by: string | null;
|
||||||
missing_since: string;
|
missing_since: string;
|
||||||
last_played_at: string | null;
|
last_played_at: string | null;
|
||||||
};
|
};
|
||||||
@@ -381,7 +392,7 @@ export type MergeDuplicateResult = {
|
|||||||
|
|
||||||
// What settling one recording in several slots did. kept_track_id is
|
// What settling one recording in several slots did. kept_track_id is
|
||||||
// null when every copy went.
|
// null when every copy went.
|
||||||
export type RefetchDuplicateResult = {
|
export type WrongSlotRemoval = {
|
||||||
kept_track_id: string | null;
|
kept_track_id: string | null;
|
||||||
removed_paths: string[];
|
removed_paths: string[];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
// The Collection's sections, down the left: the overview first, then the
|
// The Collection's sections, down the left: the overview first, then the
|
||||||
// library's health queues. Their counts come from the admin summary and are
|
// library's health queues. Their counts come from the admin summary and are
|
||||||
// accented, as they wait on a person. Missing files counts tracks.
|
// accented, as they wait on a person. Needs a file counts tracks.
|
||||||
|
|
||||||
let { summary }: { summary?: AdminSummary } = $props();
|
let { summary }: { summary?: AdminSummary } = $props();
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
{ href: '/collection/reports', label: 'Reports', attention: countOf(summary, 'reports') },
|
{ href: '/collection/reports', label: 'Reports', attention: countOf(summary, 'reports') },
|
||||||
{ href: '/collection/duplicates', label: 'Duplicates', attention: countOf(summary, 'duplicates') },
|
{ href: '/collection/duplicates', label: 'Duplicates', attention: countOf(summary, 'duplicates') },
|
||||||
{ href: '/collection/suspect-sources', label: 'Suspect sources', attention: countOf(summary, 'suspect') },
|
{ href: '/collection/suspect-sources', label: 'Suspect sources', attention: countOf(summary, 'suspect') },
|
||||||
{ href: '/collection/missing', label: 'Missing files', attention: countOf(summary, 'missing') }
|
{ href: '/collection/missing', label: 'Needs a file', attention: countOf(summary, 'missing') }
|
||||||
]);
|
]);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ describe('admin Overview page', () => {
|
|||||||
render(OverviewPage);
|
render(OverviewPage);
|
||||||
expect(screen.getByTestId('verdict').textContent).toMatch(/nothing needs you/i);
|
expect(screen.getByTestId('verdict').textContent).toMatch(/nothing needs you/i);
|
||||||
expect(screen.queryAllByTestId('needs-you')).toHaveLength(0);
|
expect(screen.queryAllByTestId('needs-you')).toHaveLength(0);
|
||||||
expect(screen.getByTestId('all-clear').textContent).toMatch(/no reports, duplicates, suspect sources, missing files/i);
|
expect(screen.getByTestId('all-clear').textContent).toMatch(/no reports, duplicates, suspect sources, tracks waiting for a file/i);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('each queue that waits on you is listed with how long its oldest has waited, and opens its page', () => {
|
test('each queue that waits on you is listed with how long its oldest has waited, and opens its page', () => {
|
||||||
@@ -134,7 +134,7 @@ describe('admin Overview page', () => {
|
|||||||
render(OverviewPage);
|
render(OverviewPage);
|
||||||
expect(screen.getByTestId('verdict').textContent).toMatch(/2 things need you/);
|
expect(screen.getByTestId('verdict').textContent).toMatch(/2 things need you/);
|
||||||
const rows = screen.getAllByTestId('needs-you').map((r) => r.textContent?.replace(/\s+/g, ' ').trim());
|
const rows = screen.getAllByTestId('needs-you').map((r) => r.textContent?.replace(/\s+/g, ' ').trim());
|
||||||
expect(rows).toEqual(['2 broken tracks reported oldest 3d ago Open', '1 missing file oldest 10d ago Open']);
|
expect(rows).toEqual(['2 broken tracks reported oldest 3d ago Open', '1 track needs a file oldest 10d ago Open']);
|
||||||
expect(screen.getByRole('link', { name: /2 broken tracks reported/i }).getAttribute('href')).toBe('/collection/reports');
|
expect(screen.getByRole('link', { name: /2 broken tracks reported/i }).getAttribute('href')).toBe('/collection/reports');
|
||||||
expect(screen.getByTestId('all-clear').textContent).not.toMatch(/reports/);
|
expect(screen.getByTestId('all-clear').textContent).not.toMatch(/reports/);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
<h1 class="font-display text-2xl font-medium text-text-primary">Collection</h1>
|
<h1 class="font-display text-2xl font-medium text-text-primary">Collection</h1>
|
||||||
<p class="text-sm text-text-secondary">
|
<p class="text-sm text-text-secondary">
|
||||||
What in the library needs looking at: tracks people reported, songs held twice, files from
|
What in the library needs looking at: tracks people reported, songs held twice, files from
|
||||||
doubtful sources, and files that went missing.
|
doubtful sources, and the tracks waiting for a good file.
|
||||||
</p>
|
</p>
|
||||||
{#if summary}
|
{#if summary}
|
||||||
{#if waiting.length > 0}
|
{#if waiting.length > 0}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { redirect } from '@sveltejs/kit';
|
|||||||
import { user } from '#lib/auth/store.svelte.js';
|
import { user } from '#lib/auth/store.svelte.js';
|
||||||
import type { LayoutLoad } from './$types';
|
import type { LayoutLoad } from './$types';
|
||||||
|
|
||||||
// Hard route gate: the Wanted view is an admin's. Runs before the
|
// Hard route gate: the Collection is an admin's. Runs before the
|
||||||
// layout renders; auth is bootstrapped by the root +layout.ts, so user.value is
|
// layout renders; auth is bootstrapped by the root +layout.ts, so user.value is
|
||||||
// either a settled User object or null.
|
// either a settled User object or null.
|
||||||
export const load: LayoutLoad = () => {
|
export const load: LayoutLoad = () => {
|
||||||
|
|||||||
@@ -43,9 +43,9 @@ describe('/collection layout', () => {
|
|||||||
['/collection/reports', 'Reports'],
|
['/collection/reports', 'Reports'],
|
||||||
['/collection/duplicates', 'Duplicates'],
|
['/collection/duplicates', 'Duplicates'],
|
||||||
['/collection/suspect-sources', 'Suspect sources'],
|
['/collection/suspect-sources', 'Suspect sources'],
|
||||||
['/collection/missing', 'Missing files']
|
['/collection/missing', 'Needs a file']
|
||||||
]);
|
]);
|
||||||
expect(screen.getByRole('link', { name: /missing files/i })).toHaveAttribute('aria-current', 'page');
|
expect(screen.getByRole('link', { name: /needs a file/i })).toHaveAttribute('aria-current', 'page');
|
||||||
expect(screen.getByRole('link', { name: /^overview/i })).not.toHaveAttribute('aria-current');
|
expect(screen.getByRole('link', { name: /^overview/i })).not.toHaveAttribute('aria-current');
|
||||||
expect(screen.getByTestId('tab-body')).toBeTruthy();
|
expect(screen.getByTestId('tab-body')).toBeTruthy();
|
||||||
});
|
});
|
||||||
@@ -62,7 +62,7 @@ describe('/collection layout', () => {
|
|||||||
expect(dup.textContent?.replace(/\s+/g, ' ').trim()).toBe('Duplicates 5');
|
expect(dup.textContent?.replace(/\s+/g, ' ').trim()).toBe('Duplicates 5');
|
||||||
const health = screen.getByTestId('collection-health');
|
const health = screen.getByTestId('collection-health');
|
||||||
expect(health.textContent?.replace(/\s+/g, ' ').trim()).toBe(
|
expect(health.textContent?.replace(/\s+/g, ' ').trim()).toBe(
|
||||||
'To look at: 2 broken tracks reported, 5 sets of duplicates to review, 9 missing files.'
|
'To look at: 2 broken tracks reported, 5 sets of duplicates to review, 9 tracks need a file.'
|
||||||
);
|
);
|
||||||
expect(Array.from(health.querySelectorAll('a')).map((a) => a.getAttribute('href'))).toEqual([
|
expect(Array.from(health.querySelectorAll('a')).map((a) => a.getAttribute('href'))).toEqual([
|
||||||
'/collection/reports',
|
'/collection/reports',
|
||||||
@@ -83,7 +83,7 @@ describe('/collection overview', () => {
|
|||||||
render(CollectionPage);
|
render(CollectionPage);
|
||||||
const rows = screen.getAllByTestId('collection-queue');
|
const rows = screen.getAllByTestId('collection-queue');
|
||||||
expect(rows).toHaveLength(1);
|
expect(rows).toHaveLength(1);
|
||||||
expect(rows[0].textContent).toMatch(/3 missing files/);
|
expect(rows[0].textContent).toMatch(/3 tracks need a file/);
|
||||||
expect(rows[0].querySelector('a')?.getAttribute('href')).toBe('/collection/missing');
|
expect(rows[0].querySelector('a')?.getAttribute('href')).toBe('/collection/missing');
|
||||||
expect(screen.getByTestId('collection-clear').textContent?.trim()).toBe('No reports, duplicates, suspect sources.');
|
expect(screen.getByTestId('collection-clear').textContent?.trim()).toBe('No reports, duplicates, suspect sources.');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
runDuplicateSweep,
|
runDuplicateSweep,
|
||||||
dismissDuplicateGroup,
|
dismissDuplicateGroup,
|
||||||
mergeDuplicateGroup,
|
mergeDuplicateGroup,
|
||||||
refetchDuplicateGroup
|
removeWrongSlotFiles
|
||||||
} from '#lib/api/admin.js';
|
} from '#lib/api/admin.js';
|
||||||
import { errMessage } from '#lib/api/errors.js';
|
import { errMessage } from '#lib/api/errors.js';
|
||||||
import { pushToast } from '#lib/stores/toast.svelte.js';
|
import { pushToast } from '#lib/stores/toast.svelte.js';
|
||||||
@@ -45,7 +45,7 @@
|
|||||||
// title whether or not it is the audio's. There an admin says which song the
|
// title whether or not it is the audio's. There an admin says which song the
|
||||||
// recording is, or that they can't tell, and the group settles as the
|
// recording is, or that they can't tell, and the group settles as the
|
||||||
// resolver would have: copies in other songs' slots are removed, and those
|
// resolver would have: copies in other songs' slots are removed, and those
|
||||||
// slots show as missing until a good copy is in the library folder.
|
// tracks wait in Needs a file until a good copy is in the library folder.
|
||||||
|
|
||||||
type Tab = DuplicatesView | 'resolved';
|
type Tab = DuplicatesView | 'resolved';
|
||||||
const fromUrl = page.url.searchParams.get('view');
|
const fromUrl = page.url.searchParams.get('view');
|
||||||
@@ -64,8 +64,8 @@
|
|||||||
// Per wrong-slot group: the copy whose title the recording is, absent when
|
// Per wrong-slot group: the copy whose title the recording is, absent when
|
||||||
// an admin can't tell, and the same two-click confirm.
|
// an admin can't tell, and the same two-click confirm.
|
||||||
let slotPick = $state<Record<string, string>>({});
|
let slotPick = $state<Record<string, string>>({});
|
||||||
let confirmingRefetch = $state<string | null>(null);
|
let confirmingRemoveSlots = $state<string | null>(null);
|
||||||
let refetching = $state<string | null>(null);
|
let removingSlots = $state<string | null>(null);
|
||||||
|
|
||||||
const queryStore = $derived(createDuplicatesQuery(groupView));
|
const queryStore = $derived(createDuplicatesQuery(groupView));
|
||||||
const query = $derived($queryStore);
|
const query = $derived($queryStore);
|
||||||
@@ -155,28 +155,28 @@
|
|||||||
// The copies that go: every one when an admin can't tell, else those
|
// The copies that go: every one when an admin can't tell, else those
|
||||||
// under another title. A copy under the picked title is the song held twice,
|
// under another title. A copy under the picked title is the song held twice,
|
||||||
// and the next sweep merges it.
|
// and the next sweep merges it.
|
||||||
function refetchRemoves(g: AdminDuplicateGroup): AdminDuplicateMember[] {
|
function slotRemovals(g: AdminDuplicateGroup): AdminDuplicateMember[] {
|
||||||
const picked = pickedOf(g);
|
const picked = pickedOf(g);
|
||||||
if (!picked) return g.members;
|
if (!picked) return g.members;
|
||||||
return g.members.filter((m) => songKey(m.title) !== songKey(picked.title));
|
return g.members.filter((m) => songKey(m.title) !== songKey(picked.title));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onRefetch(group: AdminDuplicateGroup) {
|
async function onRemoveSlots(group: AdminDuplicateGroup) {
|
||||||
if (confirmingRefetch !== group.id) {
|
if (confirmingRemoveSlots !== group.id) {
|
||||||
confirmingRefetch = group.id;
|
confirmingRemoveSlots = group.id;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
confirmingRefetch = null;
|
confirmingRemoveSlots = null;
|
||||||
refetching = group.id;
|
removingSlots = group.id;
|
||||||
try {
|
try {
|
||||||
const result = await refetchDuplicateGroup(group.id, { keep_track_id: slotPick[group.id] ?? '' });
|
const result = await removeWrongSlotFiles(group.id, { keep_track_id: slotPick[group.id] ?? '' });
|
||||||
const removed = `Removed ${plural(result.removed_paths.length, 'file', 'files')}`;
|
const removed = `Removed ${plural(result.removed_paths.length, 'file', 'files')}`;
|
||||||
pushToast(`${removed}. Their slots show as missing until a good copy is in the library.`);
|
pushToast(`${removed}. Their tracks wait in Needs a file until a good copy is in the library.`);
|
||||||
query.refetch();
|
query.refetch();
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
pushToast(errMessage(e), 'error');
|
pushToast(errMessage(e), 'error');
|
||||||
} finally {
|
} finally {
|
||||||
refetching = null;
|
removingSlots = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,8 +278,8 @@
|
|||||||
<p class="text-text-secondary">
|
<p class="text-text-secondary">
|
||||||
Tracks that hold the same recording more than once. Most settle on their own: a song held twice
|
Tracks that hold the same recording more than once. Most settle on their own: a song held twice
|
||||||
on one album is merged, copies on different releases count as one song, two versions of a song
|
on one album is merged, copies on different releases count as one song, two versions of a song
|
||||||
are left alone, and a file filling another song's track slot is removed, leaving that slot
|
are left alone, and a file filling another song's track slot is removed, its track waiting in
|
||||||
missing. What's left here needs you.
|
Needs a file. What's left here needs you.
|
||||||
</p>
|
</p>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
@@ -339,12 +339,12 @@
|
|||||||
{:else if item.action === 'duplicate_wrong_file' && !item.details.kept_title}
|
{:else if item.action === 'duplicate_wrong_file' && !item.details.kept_title}
|
||||||
<p class="text-text-primary">
|
<p class="text-text-primary">
|
||||||
{item.details.artist}: one recording was filed as {removed.map((r) => r.title).join(' and ')},
|
{item.details.artist}: one recording was filed as {removed.map((r) => r.title).join(' and ')},
|
||||||
and it is none of them. Removed; those slots show as missing.
|
and it is none of them. Removed; those tracks wait in Needs a file.
|
||||||
</p>
|
</p>
|
||||||
{:else if item.action === 'duplicate_wrong_file'}
|
{:else if item.action === 'duplicate_wrong_file'}
|
||||||
<p class="text-text-primary">
|
<p class="text-text-primary">
|
||||||
{item.details.artist}: the recording of {item.details.kept_title} was also filed as
|
{item.details.artist}: the recording of {item.details.kept_title} was also filed as
|
||||||
{removed.map((r) => r.title).join(', ')}. Removed from there; those slots show as missing.
|
{removed.map((r) => r.title).join(', ')}. Removed from there; those tracks wait in Needs a file.
|
||||||
</p>
|
</p>
|
||||||
{:else}
|
{:else}
|
||||||
<p class="text-text-primary">
|
<p class="text-text-primary">
|
||||||
@@ -432,7 +432,7 @@
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onclick={() => onDismiss(group)}
|
onclick={() => onDismiss(group)}
|
||||||
disabled={dismissing === group.id || merging === group.id || refetching === group.id}
|
disabled={dismissing === group.id || merging === group.id || removingSlots === group.id}
|
||||||
class="rounded-md border border-border px-3 py-1.5 text-sm text-text-secondary hover:bg-surface-hover hover:text-text-primary disabled:opacity-50"
|
class="rounded-md border border-border px-3 py-1.5 text-sm text-text-secondary hover:bg-surface-hover hover:text-text-primary disabled:opacity-50"
|
||||||
>
|
>
|
||||||
{tab === 'cross_release' ? 'Not the same song' : 'Not duplicates'}
|
{tab === 'cross_release' ? 'Not the same song' : 'Not duplicates'}
|
||||||
@@ -441,16 +441,16 @@
|
|||||||
{@const picked = pickedOf(group)}
|
{@const picked = pickedOf(group)}
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onclick={() => onRefetch(group)}
|
onclick={() => onRemoveSlots(group)}
|
||||||
disabled={refetching === group.id}
|
disabled={removingSlots === group.id}
|
||||||
class="rounded-md px-3 py-1.5 text-sm disabled:opacity-50 {confirmingRefetch === group.id
|
class="rounded-md px-3 py-1.5 text-sm disabled:opacity-50 {confirmingRemoveSlots === group.id
|
||||||
? 'bg-action-destructive text-action-fg hover:opacity-90'
|
? 'bg-action-destructive text-action-fg hover:opacity-90'
|
||||||
: 'border border-border text-text-primary hover:bg-surface-hover'}"
|
: 'border border-border text-text-primary hover:bg-surface-hover'}"
|
||||||
>
|
>
|
||||||
{#if refetching === group.id}
|
{#if removingSlots === group.id}
|
||||||
Removing…
|
Removing…
|
||||||
{:else if confirmingRefetch === group.id}
|
{:else if confirmingRemoveSlots === group.id}
|
||||||
Remove {plural(refetchRemoves(group).length, 'file', 'files')}
|
Remove {plural(slotRemovals(group).length, 'file', 'files')}
|
||||||
{:else if picked}
|
{:else if picked}
|
||||||
Keep “{picked.title}”…
|
Keep “{picked.title}”…
|
||||||
{:else}
|
{:else}
|
||||||
@@ -512,12 +512,12 @@
|
|||||||
</p>
|
</p>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if confirmingRefetch === group.id}
|
{#if confirmingRemoveSlots === group.id}
|
||||||
{@const picked = pickedOf(group)}
|
{@const picked = pickedOf(group)}
|
||||||
<div class="space-y-2 border-b border-border bg-surface-hover px-4 py-3 text-sm" data-testid="refetch-confirm">
|
<div class="space-y-2 border-b border-border bg-surface-hover px-4 py-3 text-sm" data-testid="refetch-confirm">
|
||||||
<p class="text-text-primary">
|
<p class="text-text-primary">
|
||||||
{#if picked}
|
{#if picked}
|
||||||
The copy titled “{picked.title}” stays, and {plural(refetchRemoves(group).length, 'copy', 'copies')}
|
The copy titled “{picked.title}” stays, and {plural(slotRemovals(group).length, 'copy', 'copies')}
|
||||||
under other titles will be deleted from disk.
|
under other titles will be deleted from disk.
|
||||||
{:else}
|
{:else}
|
||||||
All {plural(group.members.length, 'copy', 'copies')} will be deleted from disk.
|
All {plural(group.members.length, 'copy', 'copies')} will be deleted from disk.
|
||||||
@@ -528,7 +528,7 @@
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="text-xs text-text-secondary underline hover:text-text-primary"
|
class="text-xs text-text-secondary underline hover:text-text-primary"
|
||||||
onclick={() => (confirmingRefetch = null)}
|
onclick={() => (confirmingRemoveSlots = null)}
|
||||||
>
|
>
|
||||||
Cancel
|
Cancel
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ vi.mock('#lib/api/admin.js', () => ({
|
|||||||
survivor_track_id: 'www-01',
|
survivor_track_id: 'www-01',
|
||||||
removed_paths: ['/music/Moe Shop/WWW (2020)/www-02.mp3']
|
removed_paths: ['/music/Moe Shop/WWW (2020)/www-02.mp3']
|
||||||
}),
|
}),
|
||||||
refetchDuplicateGroup: vi.fn().mockResolvedValue({
|
removeWrongSlotFiles: vi.fn().mockResolvedValue({
|
||||||
kept_track_id: null,
|
kept_track_id: null,
|
||||||
removed_paths: ['/music/Moe Shop/WWW (2020)/www-01.mp3', '/music/Moe Shop/WWW (2020)/www-02.mp3']
|
removed_paths: ['/music/Moe Shop/WWW (2020)/www-01.mp3', '/music/Moe Shop/WWW (2020)/www-02.mp3']
|
||||||
})
|
})
|
||||||
@@ -30,7 +30,7 @@ import {
|
|||||||
createResolvedDuplicatesQuery,
|
createResolvedDuplicatesQuery,
|
||||||
dismissDuplicateGroup,
|
dismissDuplicateGroup,
|
||||||
mergeDuplicateGroup,
|
mergeDuplicateGroup,
|
||||||
refetchDuplicateGroup,
|
removeWrongSlotFiles,
|
||||||
runDuplicateSweep
|
runDuplicateSweep
|
||||||
} from '#lib/api/admin.js';
|
} from '#lib/api/admin.js';
|
||||||
|
|
||||||
@@ -292,13 +292,13 @@ describe('admin duplicates', () => {
|
|||||||
test("can't tell: every copy goes, after a second click", async () => {
|
test("can't tell: every copy goes, after a second click", async () => {
|
||||||
renderWith(slots());
|
renderWith(slots());
|
||||||
await fireEvent.click(screen.getByRole('button', { name: 'Remove the copies…' }));
|
await fireEvent.click(screen.getByRole('button', { name: 'Remove the copies…' }));
|
||||||
expect(refetchDuplicateGroup).not.toHaveBeenCalled();
|
expect(removeWrongSlotFiles).not.toHaveBeenCalled();
|
||||||
const confirm = text(screen.getByTestId('refetch-confirm'));
|
const confirm = text(screen.getByTestId('refetch-confirm'));
|
||||||
expect(confirm).toContain('All 2 copies will be deleted from disk');
|
expect(confirm).toContain('All 2 copies will be deleted from disk');
|
||||||
expect(confirm).toContain('until a good copy is in the library folder');
|
expect(confirm).toContain('until a good copy is in the library folder');
|
||||||
|
|
||||||
await fireEvent.click(screen.getByRole('button', { name: 'Remove 2 files' }));
|
await fireEvent.click(screen.getByRole('button', { name: 'Remove 2 files' }));
|
||||||
expect(refetchDuplicateGroup).toHaveBeenCalledWith('g-1', { keep_track_id: '' });
|
expect(removeWrongSlotFiles).toHaveBeenCalledWith('g-1', { keep_track_id: '' });
|
||||||
});
|
});
|
||||||
|
|
||||||
test('naming the song keeps that copy and removes the others', async () => {
|
test('naming the song keeps that copy and removes the others', async () => {
|
||||||
@@ -310,7 +310,7 @@ describe('admin duplicates', () => {
|
|||||||
'The copy titled “WWW (instrumental)” stays, and 1 copy under other titles will be deleted from disk'
|
'The copy titled “WWW (instrumental)” stays, and 1 copy under other titles will be deleted from disk'
|
||||||
);
|
);
|
||||||
await fireEvent.click(screen.getByRole('button', { name: 'Remove 1 file' }));
|
await fireEvent.click(screen.getByRole('button', { name: 'Remove 1 file' }));
|
||||||
expect(refetchDuplicateGroup).toHaveBeenCalledWith('g-1', { keep_track_id: 'www-02' });
|
expect(removeWrongSlotFiles).toHaveBeenCalledWith('g-1', { keep_track_id: 'www-02' });
|
||||||
});
|
});
|
||||||
|
|
||||||
test("I can't tell takes the pick back", async () => {
|
test("I can't tell takes the pick back", async () => {
|
||||||
@@ -490,11 +490,11 @@ describe('admin duplicates', () => {
|
|||||||
const items = screen.getAllByTestId('resolved-item').map(text);
|
const items = screen.getAllByTestId('resolved-item').map(text);
|
||||||
expect(items[0]).toContain('Moe Shop: Lovesick and Lovesick (Instrumental) are different versions, not duplicates. Both kept.');
|
expect(items[0]).toContain('Moe Shop: Lovesick and Lovesick (Instrumental) are different versions, not duplicates. Both kept.');
|
||||||
expect(items[1]).toContain(
|
expect(items[1]).toContain(
|
||||||
'Savant: the recording of Void was also filed as Reach. Removed from there; those slots show as missing.'
|
'Savant: the recording of Void was also filed as Reach. Removed from there; those tracks wait in Needs a file.'
|
||||||
);
|
);
|
||||||
expect(items[1]).toContain('/data/Music/Savant/Void/17 - Reach.m4a');
|
expect(items[1]).toContain('/data/Music/Savant/Void/17 - Reach.m4a');
|
||||||
expect(items[2]).toContain(
|
expect(items[2]).toContain(
|
||||||
'Shnabubula: one recording was filed as Fading Light and Looking for Answers, and it is none of them. Removed; those slots show as missing.'
|
'Shnabubula: one recording was filed as Fading Light and Looking for Answers, and it is none of them. Removed; those tracks wait in Needs a file.'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,17 +1,22 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { plural } from '#lib/utils/plural.js';
|
import { plural } from '#lib/utils/plural.js';
|
||||||
import { pageTitle } from '#lib/branding.js';
|
import { pageTitle } from '#lib/branding.js';
|
||||||
import { FolderX, Music2 } from 'lucide-svelte';
|
import { Copy, Download, FolderX, Music2, Trash2 } from 'lucide-svelte';
|
||||||
import { createMissingFilesQuery } from '#lib/api/admin.js';
|
import Modal from '#lib/components/Modal.svelte';
|
||||||
|
import { createMissingFilesQuery, forgetMissingTracks, MISSING_FILES_CSV_URL } from '#lib/api/admin.js';
|
||||||
|
import { errMessage } from '#lib/api/errors.js';
|
||||||
|
import { pushToast } from '#lib/stores/toast.svelte.js';
|
||||||
import { relativeTime } from '#lib/utils/relativeTime.js';
|
import { relativeTime } from '#lib/utils/relativeTime.js';
|
||||||
import { formatDuration } from '#lib/media/duration.js';
|
import { formatDuration } from '#lib/media/duration.js';
|
||||||
import { coverUrl } from '#lib/media/covers.js';
|
import { coverUrl } from '#lib/media/covers.js';
|
||||||
import type { AdminMissingGroup } from '#lib/api/types.js';
|
import type { AdminMissingGroup, AdminMissingTrack } from '#lib/api/types.js';
|
||||||
|
|
||||||
// Files the scan looked for and could not find, by folder. A missing file
|
// Tracks waiting for a file, by folder: removed from one of the Collection's
|
||||||
// keeps its track row, its play history and its likes, because the file may
|
// queues, or gone from disk. Each keeps its row, its play history and its
|
||||||
// come back: the scanner clears the mark by itself, and adopts the row if it
|
// likes. A good copy that lands in the library takes the track over: the
|
||||||
// returns under a new name. Nothing on this page deletes a track.
|
// scanner adopts a file that comes back under a new name, and folds a new
|
||||||
|
// track on the same album and title into the waiting one. Forget is the
|
||||||
|
// only thing here that deletes a track, and it asks first.
|
||||||
|
|
||||||
const PAGE_SIZE = 50;
|
const PAGE_SIZE = 50;
|
||||||
|
|
||||||
@@ -25,14 +30,62 @@
|
|||||||
const total = $derived(query.data?.total ?? 0);
|
const total = $derived(query.data?.total ?? 0);
|
||||||
const shown = $derived(groups.reduce((n, g) => n + g.tracks.length, 0));
|
const shown = $derived(groups.reduce((n, g) => n + g.tracks.length, 0));
|
||||||
const hasMore = $derived(offset + shown < total);
|
const hasMore = $derived(offset + shown < total);
|
||||||
|
|
||||||
|
// Why a track waits, in a line.
|
||||||
|
function why(t: AdminMissingTrack): string {
|
||||||
|
const by = t.removed_by ? ` by ${t.removed_by}` : '';
|
||||||
|
switch (t.removed_for) {
|
||||||
|
case 'report':
|
||||||
|
return `File removed from a report${by}`;
|
||||||
|
case 'duplicate':
|
||||||
|
return `File removed as a duplicate${by}`;
|
||||||
|
case 'suspect':
|
||||||
|
return `File removed as a suspect source${by}`;
|
||||||
|
default:
|
||||||
|
return 'File went missing from disk';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Forget: one track, or a whole folder's. The tracks go for good, so it
|
||||||
|
// asks first and names what goes.
|
||||||
|
type Forgetting = { label: string; ids: string[] };
|
||||||
|
let forgetting = $state<Forgetting | null>(null);
|
||||||
|
let busy = $state(false);
|
||||||
|
|
||||||
|
async function confirmForget(f: Forgetting) {
|
||||||
|
busy = true;
|
||||||
|
try {
|
||||||
|
const { forgotten } = await forgetMissingTracks(f.ids);
|
||||||
|
pushToast(`Forgot ${plural(forgotten, 'track', 'tracks')}`);
|
||||||
|
} catch (e) {
|
||||||
|
pushToast(`Couldn't forget it: ${errMessage(e)}`, 'error');
|
||||||
|
} finally {
|
||||||
|
busy = false;
|
||||||
|
forgetting = null;
|
||||||
|
}
|
||||||
|
query.refetch();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy list puts the whole list on the clipboard, in the export's columns,
|
||||||
|
// for pasting into whatever finds music.
|
||||||
|
async function copyList() {
|
||||||
|
try {
|
||||||
|
const res = await fetch(MISSING_FILES_CSV_URL, { credentials: 'same-origin', signal: AbortSignal.timeout(15_000) });
|
||||||
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
||||||
|
await navigator.clipboard.writeText(await res.text());
|
||||||
|
pushToast(`Copied ${plural(total, 'track', 'tracks')}`);
|
||||||
|
} catch (e) {
|
||||||
|
pushToast(`Couldn't copy the list: ${errMessage(e)}`, 'error');
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head><title>{pageTitle('Collection · Missing files')}</title></svelte:head>
|
<svelte:head><title>{pageTitle('Collection · Needs a file')}</title></svelte:head>
|
||||||
|
|
||||||
<div class="space-y-6">
|
<div class="space-y-6">
|
||||||
<header class="space-y-1">
|
<header class="space-y-1">
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
<h2 class="font-display text-2xl font-medium text-text-primary">Missing files</h2>
|
<h2 class="font-display text-2xl font-medium text-text-primary">Needs a file</h2>
|
||||||
{#if total > 0}
|
{#if total > 0}
|
||||||
<span
|
<span
|
||||||
class="inline-flex items-center rounded-full bg-accent-tint px-2 py-0.5 text-xs text-accent-fg"
|
class="inline-flex items-center rounded-full bg-accent-tint px-2 py-0.5 text-xs text-accent-fg"
|
||||||
@@ -40,33 +93,49 @@
|
|||||||
>
|
>
|
||||||
{total}
|
{total}
|
||||||
</span>
|
</span>
|
||||||
|
<div class="ml-auto flex gap-2">
|
||||||
|
<a
|
||||||
|
href={MISSING_FILES_CSV_URL}
|
||||||
|
download
|
||||||
|
class="inline-flex items-center gap-1 rounded-md border border-border px-3 py-1.5 text-sm text-text-secondary hover:bg-surface-hover hover:text-text-primary"
|
||||||
|
>
|
||||||
|
<Download size={14} strokeWidth={1.5} /> Export CSV
|
||||||
|
</a>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onclick={copyList}
|
||||||
|
class="inline-flex items-center gap-1 rounded-md border border-border px-3 py-1.5 text-sm text-text-secondary hover:bg-surface-hover hover:text-text-primary"
|
||||||
|
>
|
||||||
|
<Copy size={14} strokeWidth={1.5} /> Copy list
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<p class="text-text-secondary">
|
<p class="text-text-secondary">
|
||||||
Tracks whose audio file the last scan couldn't find. They keep their play
|
Tracks without a file to play: removed from Reports, Duplicates or Suspect sources, or gone
|
||||||
history and likes, and stop being offered anywhere until a file is back in the library
|
from disk. Each keeps its play history and likes, and is not offered anywhere until a good
|
||||||
folder.
|
copy is in the library folder, which it then takes over. Export the list to find them.
|
||||||
</p>
|
</p>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
{#if query.isPending}
|
{#if query.isPending}
|
||||||
<p class="text-text-secondary">Checking what's missing…</p>
|
<p class="text-text-secondary">Reading the list…</p>
|
||||||
{:else if query.isError}
|
{:else if query.isError}
|
||||||
<p class="text-sm text-error-fg">
|
<p class="text-sm text-error-fg">
|
||||||
Couldn't load the missing files.
|
Couldn't load the list.
|
||||||
<button type="button" class="underline hover:no-underline" onclick={() => query.refetch()}>Try again</button>
|
<button type="button" class="underline hover:no-underline" onclick={() => query.refetch()}>Try again</button>
|
||||||
</p>
|
</p>
|
||||||
{:else if groups.length === 0}
|
{:else if groups.length === 0}
|
||||||
<!-- Empty state explains the feature, not just the emptiness: an operator
|
<!-- Empty state explains the feature, not just the emptiness: an operator
|
||||||
who has never seen this page shouldn't have to guess what would put a
|
who has never seen this page shouldn't have to guess what would put a
|
||||||
row here or when it would appear. -->
|
row here or what takes it away. -->
|
||||||
<div class="rounded-lg border border-border bg-surface p-6 text-center">
|
<div class="rounded-lg border border-border bg-surface p-6 text-center">
|
||||||
<FolderX size={28} strokeWidth={1} class="mx-auto text-text-muted" />
|
<FolderX size={28} strokeWidth={1} class="mx-auto text-text-muted" />
|
||||||
<p class="mt-3 text-text-primary">Every track's file is where it should be.</p>
|
<p class="mt-3 text-text-primary">Every track has its file.</p>
|
||||||
<p class="mt-1 text-sm text-text-secondary">
|
<p class="mt-1 text-sm text-text-secondary">
|
||||||
A track lands here when a library scan can't find its file — moved outside
|
A track lands here when its file is removed from one of the Collection's queues, or when a
|
||||||
Minstrel, deleted, or on a drive that didn't mount. It leaves on its own
|
library scan can't find its file. It leaves on its own when a good copy is in the library,
|
||||||
when the file comes back.
|
or when you forget it.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
@@ -75,13 +144,29 @@
|
|||||||
<li class="overflow-hidden rounded-lg border border-border bg-surface">
|
<li class="overflow-hidden rounded-lg border border-border bg-surface">
|
||||||
<!-- The folder is the unit of decision. Three reorganised albums are
|
<!-- The folder is the unit of decision. Three reorganised albums are
|
||||||
three things to think about, not forty. -->
|
three things to think about, not forty. -->
|
||||||
<div class="flex items-baseline justify-between gap-4 border-b border-border px-4 py-3">
|
<div class="flex items-center justify-between gap-4 border-b border-border px-4 py-3">
|
||||||
<h3 class="truncate font-mono text-sm text-text-primary" title={group.directory}>
|
<h3 class="min-w-0 truncate font-mono text-sm text-text-primary" title={group.directory}>
|
||||||
{group.directory}
|
{group.directory}
|
||||||
</h3>
|
</h3>
|
||||||
<span class="shrink-0 text-xs text-text-secondary">
|
<div class="flex shrink-0 items-center gap-3">
|
||||||
{plural(group.tracks.length, 'track', 'tracks')} · gone {relativeTime(group.missing_since)}
|
<span class="text-xs text-text-secondary">
|
||||||
</span>
|
{plural(group.tracks.length, 'track', 'tracks')} · {relativeTime(group.missing_since)}
|
||||||
|
</span>
|
||||||
|
{#if group.tracks.length > 1}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
aria-label={`Forget the ${group.tracks.length} tracks in ${group.directory}`}
|
||||||
|
onclick={() =>
|
||||||
|
(forgetting = {
|
||||||
|
label: `the ${group.tracks.length} tracks in ${group.directory}`,
|
||||||
|
ids: group.tracks.map((t) => t.track_id)
|
||||||
|
})}
|
||||||
|
class="rounded-md px-2 py-1 text-xs text-text-muted hover:bg-surface-hover hover:text-text-primary"
|
||||||
|
>
|
||||||
|
Forget all
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ul class="divide-y divide-border">
|
<ul class="divide-y divide-border">
|
||||||
@@ -108,12 +193,15 @@
|
|||||||
<div class="truncate text-xs text-text-secondary">
|
<div class="truncate text-xs text-text-secondary">
|
||||||
{t.artist_name} · {t.album_title}
|
{t.artist_name} · {t.album_title}
|
||||||
</div>
|
</div>
|
||||||
|
<div class="truncate text-xs text-text-muted" data-testid="missing-track-why">
|
||||||
|
{why(t)} · {relativeTime(t.missing_since)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Last played is the deciding fact: a file gone six months
|
<!-- Last played is the deciding fact: a file gone six months
|
||||||
that nobody ever played is not the same problem as one
|
that nobody ever played is not the same problem as one
|
||||||
played two hundred times last week. -->
|
played two hundred times last week. -->
|
||||||
<span class="shrink-0 text-xs text-text-muted">
|
<span class="hidden shrink-0 text-xs text-text-muted sm:inline">
|
||||||
{#if t.last_played_at}
|
{#if t.last_played_at}
|
||||||
last played {relativeTime(t.last_played_at)}
|
last played {relativeTime(t.last_played_at)}
|
||||||
{:else}
|
{:else}
|
||||||
@@ -121,6 +209,14 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</span>
|
</span>
|
||||||
<span class="shrink-0 text-xs text-text-muted" data-testid="missing-track-length">{formatDuration(t.duration_sec)}</span>
|
<span class="shrink-0 text-xs text-text-muted" data-testid="missing-track-length">{formatDuration(t.duration_sec)}</span>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
aria-label={`Forget ${t.title}`}
|
||||||
|
onclick={() => (forgetting = { label: `“${t.title}”`, ids: [t.track_id] })}
|
||||||
|
class="shrink-0 rounded-md px-2 py-1 text-xs text-text-muted hover:bg-surface-hover hover:text-text-primary"
|
||||||
|
>
|
||||||
|
Forget
|
||||||
|
</button>
|
||||||
</li>
|
</li>
|
||||||
{/each}
|
{/each}
|
||||||
</ul>
|
</ul>
|
||||||
@@ -129,7 +225,7 @@
|
|||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
{#if hasMore || offset > 0}
|
{#if hasMore || offset > 0}
|
||||||
<nav class="flex items-center justify-between" aria-label="Missing files pages">
|
<nav class="flex items-center justify-between" aria-label="Needs a file pages">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="rounded border border-border px-3 py-1.5 text-sm text-text-primary
|
class="rounded border border-border px-3 py-1.5 text-sm text-text-primary
|
||||||
@@ -157,3 +253,28 @@
|
|||||||
{/if}
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<Modal title="Forget for good?" open={forgetting !== null} onClose={() => (forgetting = null)}>
|
||||||
|
{#if forgetting}
|
||||||
|
<p class="-mt-2 text-sm text-text-secondary">
|
||||||
|
Forget {forgetting.label}, with their likes, plays and playlist places. A copy added later
|
||||||
|
comes in as a new track.
|
||||||
|
</p>
|
||||||
|
<div class="mt-5 flex justify-end gap-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-md border border-border px-3 py-1.5 text-sm text-text-secondary hover:text-text-primary"
|
||||||
|
onclick={() => (forgetting = null)}>Cancel</button
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
aria-label="Confirm forget"
|
||||||
|
disabled={busy}
|
||||||
|
class="inline-flex items-center gap-1 rounded-md bg-action-secondary px-3 py-1.5 text-sm text-action-fg disabled:opacity-50"
|
||||||
|
onclick={() => confirmForget(forgetting!)}
|
||||||
|
>
|
||||||
|
<Trash2 size={14} strokeWidth={2} /> Forget
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</Modal>
|
||||||
|
|||||||
@@ -1,16 +1,23 @@
|
|||||||
import { afterEach, describe, expect, test, vi } from 'vitest';
|
import { afterEach, describe, expect, test, vi } from 'vitest';
|
||||||
import { render, screen } from '@testing-library/svelte';
|
import { fireEvent, render, screen, waitFor, within } from '@testing-library/svelte';
|
||||||
import { mockQuery } from '../../../test-utils/query';
|
import { mockQuery } from '../../../test-utils/query';
|
||||||
import type { AdminMissingResponse } from '#lib/api/types.js';
|
import type { AdminMissingResponse, AdminMissingTrack } from '#lib/api/types.js';
|
||||||
|
|
||||||
vi.mock('#lib/api/admin.js', () => ({ createMissingFilesQuery: vi.fn() }));
|
vi.mock('#lib/api/admin.js', () => ({
|
||||||
|
createMissingFilesQuery: vi.fn(),
|
||||||
|
forgetMissingTracks: vi.fn().mockResolvedValue({ forgotten: 1 }),
|
||||||
|
MISSING_FILES_CSV_URL: '/api/admin/library/missing.csv'
|
||||||
|
}));
|
||||||
|
|
||||||
import MissingPage from './+page.svelte';
|
import MissingPage from './+page.svelte';
|
||||||
import { createMissingFilesQuery } from '#lib/api/admin.js';
|
import { createMissingFilesQuery, forgetMissingTracks } from '#lib/api/admin.js';
|
||||||
|
|
||||||
const DAY = 24 * 3_600_000;
|
const DAY = 24 * 3_600_000;
|
||||||
|
|
||||||
function track(title: string, opts: { lastPlayed?: string | null } = {}) {
|
function track(
|
||||||
|
title: string,
|
||||||
|
opts: { lastPlayed?: string | null; removedFor?: AdminMissingTrack['removed_for']; removedBy?: string } = {}
|
||||||
|
): AdminMissingTrack {
|
||||||
return {
|
return {
|
||||||
track_id: `t-${title}`,
|
track_id: `t-${title}`,
|
||||||
title,
|
title,
|
||||||
@@ -20,6 +27,12 @@ function track(title: string, opts: { lastPlayed?: string | null } = {}) {
|
|||||||
album_title: 'Minutes to Midnight',
|
album_title: 'Minutes to Midnight',
|
||||||
file_path: `/music/Linkin Park/Minutes to Midnight/${title}.flac`,
|
file_path: `/music/Linkin Park/Minutes to Midnight/${title}.flac`,
|
||||||
duration_sec: 185,
|
duration_sec: 185,
|
||||||
|
disc_number: 1,
|
||||||
|
track_number: 1,
|
||||||
|
recording_mbid: null,
|
||||||
|
release_group_mbid: null,
|
||||||
|
removed_for: opts.removedFor ?? null,
|
||||||
|
removed_by: opts.removedBy ?? null,
|
||||||
missing_since: new Date(Date.now() - 3 * DAY).toISOString(),
|
missing_since: new Date(Date.now() - 3 * DAY).toISOString(),
|
||||||
last_played_at: opts.lastPlayed === undefined ? null : opts.lastPlayed
|
last_played_at: opts.lastPlayed === undefined ? null : opts.lastPlayed
|
||||||
};
|
};
|
||||||
@@ -35,7 +48,7 @@ const response: AdminMissingResponse = {
|
|||||||
missing_since: new Date(Date.now() - 3 * DAY).toISOString(),
|
missing_since: new Date(Date.now() - 3 * DAY).toISOString(),
|
||||||
tracks: [
|
tracks: [
|
||||||
track('Given Up', { lastPlayed: new Date(Date.now() - 2 * DAY).toISOString() }),
|
track('Given Up', { lastPlayed: new Date(Date.now() - 2 * DAY).toISOString() }),
|
||||||
track('Bleed It Out')
|
track('Bleed It Out', { removedFor: 'report', removedBy: 'alice' })
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -68,10 +81,10 @@ describe('/collection/missing', () => {
|
|||||||
expect(screen.getByTestId('missing-count-pill').textContent?.trim()).toBe('3');
|
expect(screen.getByTestId('missing-count-pill').textContent?.trim()).toBe('3');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('a group states how many tracks and how long gone', () => {
|
test('a group states how many tracks and how long they have waited', () => {
|
||||||
renderWith(response);
|
renderWith(response);
|
||||||
expect(screen.getByText(/2 tracks · gone 3d ago/)).toBeTruthy();
|
expect(screen.getByText(/2 tracks · 3d ago/)).toBeTruthy();
|
||||||
expect(screen.getByText(/1 track · gone 9d ago/)).toBeTruthy();
|
expect(screen.getByText(/1 track · 9d ago/)).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
// The deciding fact for whether a missing file is worth chasing.
|
// The deciding fact for whether a missing file is worth chasing.
|
||||||
@@ -96,35 +109,65 @@ describe('/collection/missing', () => {
|
|||||||
|
|
||||||
// An operator who has never seen this page should not have to guess what
|
// An operator who has never seen this page should not have to guess what
|
||||||
// would put a row here.
|
// would put a row here.
|
||||||
test('the empty state explains what missing means', () => {
|
test('the empty state says how a track gets here and how it leaves', () => {
|
||||||
renderWith({ total: 0, limit: 50, offset: 0, groups: [] });
|
renderWith({ total: 0, limit: 50, offset: 0, groups: [] });
|
||||||
expect(screen.getByText(/every track's file is where it should be/i)).toBeTruthy();
|
expect(screen.getByText(/every track has its file/i)).toBeTruthy();
|
||||||
expect(screen.getByText(/can't find its file/i)).toBeTruthy();
|
expect(screen.getByText(/removed from one of the collection's queues/i)).toBeTruthy();
|
||||||
|
expect(screen.getByText(/when a good copy is in the library/i)).toBeTruthy();
|
||||||
expect(screen.queryByTestId('missing-count-pill')).toBeNull();
|
expect(screen.queryByTestId('missing-count-pill')).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('shows a loading line while pending', () => {
|
test('shows a loading line while pending', () => {
|
||||||
renderWith(undefined, { isPending: true });
|
renderWith(undefined, { isPending: true });
|
||||||
expect(screen.getByText(/checking what's missing/i)).toBeTruthy();
|
expect(screen.getByText(/reading the list/i)).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('shows an error line when the query fails', () => {
|
test('shows an error line when the query fails', () => {
|
||||||
renderWith(undefined, { isError: true });
|
renderWith(undefined, { isError: true });
|
||||||
expect(screen.getByText(/couldn't load the missing files/i)).toBeTruthy();
|
expect(screen.getByText(/couldn't load the list/i)).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Paging only appears when it can do something: a single page of results
|
// Paging only appears when it can do something: a single page of results
|
||||||
// should not render dead Previous/Next buttons.
|
// should not render dead Previous/Next buttons.
|
||||||
test('no pager when everything fits on one page', () => {
|
test('no pager when everything fits on one page', () => {
|
||||||
renderWith(response);
|
renderWith(response);
|
||||||
expect(screen.queryByLabelText('Missing files pages')).toBeNull();
|
expect(screen.queryByLabelText('Needs a file pages')).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('pager appears when the server reports more than this page holds', () => {
|
test('pager appears when the server reports more than this page holds', () => {
|
||||||
renderWith({ ...response, total: 120 });
|
renderWith({ ...response, total: 120 });
|
||||||
expect(screen.getByLabelText('Missing files pages')).toBeTruthy();
|
expect(screen.getByLabelText('Needs a file pages')).toBeTruthy();
|
||||||
expect(screen.getByText('1–3 of 120')).toBeTruthy();
|
expect(screen.getByText('1–3 of 120')).toBeTruthy();
|
||||||
expect(screen.getByRole('button', { name: 'Previous' })).toHaveProperty('disabled', true);
|
expect(screen.getByRole('button', { name: 'Previous' })).toHaveProperty('disabled', true);
|
||||||
expect(screen.getByRole('button', { name: 'Next' })).toHaveProperty('disabled', false);
|
expect(screen.getByRole('button', { name: 'Next' })).toHaveProperty('disabled', false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('each track says why it waits', () => {
|
||||||
|
renderWith(response);
|
||||||
|
const why = screen.getAllByTestId('missing-track-why').map((e) => e.textContent ?? '');
|
||||||
|
expect(why[0]).toMatch(/file went missing from disk/i);
|
||||||
|
expect(why[1]).toMatch(/file removed from a report by alice/i);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Forget asks first, then forgets the one track', async () => {
|
||||||
|
renderWith(response);
|
||||||
|
await fireEvent.click(screen.getByRole('button', { name: 'Forget Given Up' }));
|
||||||
|
expect(forgetMissingTracks).not.toHaveBeenCalled();
|
||||||
|
await fireEvent.click(within(screen.getByRole('dialog')).getByRole('button', { name: /confirm forget/i }));
|
||||||
|
await waitFor(() => expect(forgetMissingTracks).toHaveBeenCalledWith(['t-Given Up']));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Forget all takes the whole folder', async () => {
|
||||||
|
renderWith(response);
|
||||||
|
await fireEvent.click(
|
||||||
|
screen.getByRole('button', { name: 'Forget the 2 tracks in /music/Linkin Park/Minutes to Midnight' })
|
||||||
|
);
|
||||||
|
await fireEvent.click(within(screen.getByRole('dialog')).getByRole('button', { name: /confirm forget/i }));
|
||||||
|
await waitFor(() => expect(forgetMissingTracks).toHaveBeenCalledWith(['t-Given Up', 't-Bleed It Out']));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Export CSV links to the whole list', () => {
|
||||||
|
renderWith(response);
|
||||||
|
expect(screen.getByRole('link', { name: /export csv/i })).toHaveAttribute('href', '/api/admin/library/missing.csv');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { plural } from '#lib/utils/plural.js';
|
import { plural } from '#lib/utils/plural.js';
|
||||||
import { pageTitle } from '#lib/branding.js';
|
import { pageTitle } from '#lib/branding.js';
|
||||||
import { Music2, CheckCircle2, Trash2, Play, Copy, ChevronRight } from 'lucide-svelte';
|
import { Music2, CheckCircle2, Trash2, Play, Copy, ChevronRight, FileX } from 'lucide-svelte';
|
||||||
import { useQueryClient } from '@tanstack/svelte-query';
|
import { useQueryClient } from '@tanstack/svelte-query';
|
||||||
import RowActionsMenu, { type RowAction } from '#lib/components/RowActionsMenu.svelte';
|
import RowActionsMenu, { type RowAction } from '#lib/components/RowActionsMenu.svelte';
|
||||||
import TabStrip from '#lib/components/TabStrip.svelte';
|
import TabStrip from '#lib/components/TabStrip.svelte';
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
createQuarantineActionsQuery,
|
createQuarantineActionsQuery,
|
||||||
resolveQuarantine,
|
resolveQuarantine,
|
||||||
resolvePlaybackError,
|
resolvePlaybackError,
|
||||||
|
removeQuarantineFile,
|
||||||
deleteQuarantineFile
|
deleteQuarantineFile
|
||||||
} from '#lib/api/admin.js';
|
} from '#lib/api/admin.js';
|
||||||
import { qk } from '#lib/api/queries.js';
|
import { qk } from '#lib/api/queries.js';
|
||||||
@@ -112,8 +113,26 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// One delete path for every report: the track and its file go, and its
|
// Remove the file: the bad file goes and the track waits in Needs a file,
|
||||||
// reports and playback errors go with the track row (ON DELETE CASCADE).
|
// with its likes and plays, until a good copy is in the library. Its
|
||||||
|
// reports and playback errors are settled with it.
|
||||||
|
let removeFileId = $state<string | null>(null);
|
||||||
|
const removeFileRow = $derived(removeFileId ? (rows.find((r) => r.track_id === removeFileId) ?? null) : null);
|
||||||
|
|
||||||
|
async function confirmRemoveFile(r: ReportRow) {
|
||||||
|
removeFileId = null;
|
||||||
|
try {
|
||||||
|
await removeQuarantineFile(r.track_id);
|
||||||
|
pushToast(`Removed the file. "${r.title}" waits in Needs a file for a good copy.`);
|
||||||
|
} catch (e) {
|
||||||
|
pushToast(`Couldn't remove the file: ${errMessage(e)}`, 'error');
|
||||||
|
}
|
||||||
|
await Promise.all([refresh(), client.invalidateQueries({ queryKey: ['adminMissingFiles'] })]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove from library: the track and its file go, and its reports and
|
||||||
|
// playback errors go with the track row (ON DELETE CASCADE), with every
|
||||||
|
// like, play and playlist place.
|
||||||
let deleteFileId = $state<string | null>(null);
|
let deleteFileId = $state<string | null>(null);
|
||||||
const deleteFileRow = $derived(deleteFileId ? (rows.find((r) => r.track_id === deleteFileId) ?? null) : null);
|
const deleteFileRow = $derived(deleteFileId ? (rows.find((r) => r.track_id === deleteFileId) ?? null) : null);
|
||||||
|
|
||||||
@@ -121,9 +140,9 @@
|
|||||||
deleteFileId = null;
|
deleteFileId = null;
|
||||||
try {
|
try {
|
||||||
await deleteQuarantineFile(r.track_id);
|
await deleteQuarantineFile(r.track_id);
|
||||||
pushToast(`Deleted "${r.title}"`);
|
pushToast(`Removed "${r.title}" from the library`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
pushToast(`Delete failed: ${errMessage(e)}`, 'error');
|
pushToast(`Couldn't remove it: ${errMessage(e)}`, 'error');
|
||||||
}
|
}
|
||||||
await refresh();
|
await refresh();
|
||||||
}
|
}
|
||||||
@@ -134,10 +153,16 @@
|
|||||||
secondary: [
|
secondary: [
|
||||||
{ icon: Play, label: 'Play', ariaLabel: `Play ${r.title}`, onclick: () => onPlay(r) },
|
{ icon: Play, label: 'Play', ariaLabel: `Play ${r.title}`, onclick: () => onPlay(r) },
|
||||||
{ icon: Copy, label: 'Copy details', ariaLabel: `Copy details for ${r.title}`, onclick: () => onCopy(r) },
|
{ icon: Copy, label: 'Copy details', ariaLabel: `Copy details for ${r.title}`, onclick: () => onCopy(r) },
|
||||||
|
{
|
||||||
|
icon: FileX,
|
||||||
|
label: 'Remove the file',
|
||||||
|
ariaLabel: `Remove the file for ${r.title}`,
|
||||||
|
onclick: () => (removeFileId = r.track_id)
|
||||||
|
},
|
||||||
{
|
{
|
||||||
icon: Trash2,
|
icon: Trash2,
|
||||||
label: 'Delete file',
|
label: 'Remove from library',
|
||||||
ariaLabel: `Delete file for ${r.title}`,
|
ariaLabel: `Remove ${r.title} from the library`,
|
||||||
danger: true,
|
danger: true,
|
||||||
onclick: () => (deleteFileId = r.track_id)
|
onclick: () => (deleteFileId = r.track_id)
|
||||||
}
|
}
|
||||||
@@ -260,11 +285,37 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Modal title="Delete file?" open={deleteFileRow !== null} onClose={() => (deleteFileId = null)}>
|
<Modal title="Remove the file?" open={removeFileRow !== null} onClose={() => (removeFileId = null)}>
|
||||||
|
{#if removeFileRow}
|
||||||
|
<p class="-mt-2 text-sm text-text-secondary">
|
||||||
|
Delete the file of <em class="font-medium text-text-primary">{removeFileRow.title}</em> and keep the track.
|
||||||
|
It waits in Needs a file, with its likes and plays, and takes over a good copy when one is in the
|
||||||
|
library. Its reports are cleared.
|
||||||
|
</p>
|
||||||
|
<div class="mt-5 flex justify-end gap-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-md border border-border px-3 py-1.5 text-sm text-text-secondary hover:text-text-primary"
|
||||||
|
onclick={() => (removeFileId = null)}>Cancel</button
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
aria-label="Confirm remove the file"
|
||||||
|
class="inline-flex items-center gap-1 rounded-md bg-action-secondary px-3 py-1.5 text-sm text-action-fg"
|
||||||
|
onclick={() => confirmRemoveFile(removeFileRow!)}
|
||||||
|
>
|
||||||
|
<FileX size={14} strokeWidth={2} /> Remove the file
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</Modal>
|
||||||
|
|
||||||
|
<Modal title="Remove from library?" open={deleteFileRow !== null} onClose={() => (deleteFileId = null)}>
|
||||||
{#if deleteFileRow}
|
{#if deleteFileRow}
|
||||||
<p class="-mt-2 text-sm text-text-secondary">
|
<p class="-mt-2 text-sm text-text-secondary">
|
||||||
Remove <em class="font-medium text-text-primary">{deleteFileRow.title}</em> from the library and delete its
|
Remove <em class="font-medium text-text-primary">{deleteFileRow.title}</em> and its file for good, with its
|
||||||
file. Its reports and playback errors go with it.
|
likes, plays and playlist places. Its reports and playback errors go with it. To keep the track for a
|
||||||
|
good copy, remove the file instead.
|
||||||
</p>
|
</p>
|
||||||
<div class="mt-5 flex justify-end gap-2">
|
<div class="mt-5 flex justify-end gap-2">
|
||||||
<button
|
<button
|
||||||
@@ -274,11 +325,11 @@
|
|||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
aria-label="Confirm delete file"
|
aria-label="Confirm remove from library"
|
||||||
class="inline-flex items-center gap-1 rounded-md bg-action-secondary px-3 py-1.5 text-sm text-action-fg"
|
class="inline-flex items-center gap-1 rounded-md bg-action-secondary px-3 py-1.5 text-sm text-action-fg"
|
||||||
onclick={() => confirmDeleteFile(deleteFileRow!)}
|
onclick={() => confirmDeleteFile(deleteFileRow!)}
|
||||||
>
|
>
|
||||||
<Trash2 size={14} strokeWidth={2} /> Delete file
|
<Trash2 size={14} strokeWidth={2} /> Remove from library
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ vi.mock('#lib/api/admin.js', () => ({
|
|||||||
createQuarantineActionsQuery: vi.fn(),
|
createQuarantineActionsQuery: vi.fn(),
|
||||||
resolveQuarantine: vi.fn().mockResolvedValue({}),
|
resolveQuarantine: vi.fn().mockResolvedValue({}),
|
||||||
resolvePlaybackError: vi.fn().mockResolvedValue({}),
|
resolvePlaybackError: vi.fn().mockResolvedValue({}),
|
||||||
|
removeQuarantineFile: vi.fn().mockResolvedValue({}),
|
||||||
deleteQuarantineFile: vi.fn().mockResolvedValue({})
|
deleteQuarantineFile: vi.fn().mockResolvedValue({})
|
||||||
}));
|
}));
|
||||||
vi.mock('#lib/player/store.svelte.js', () => ({ playRadio: vi.fn() }));
|
vi.mock('#lib/player/store.svelte.js', () => ({ playRadio: vi.fn() }));
|
||||||
@@ -19,6 +20,7 @@ import {
|
|||||||
createAdminQuarantineQuery,
|
createAdminQuarantineQuery,
|
||||||
createQuarantineActionsQuery,
|
createQuarantineActionsQuery,
|
||||||
deleteQuarantineFile,
|
deleteQuarantineFile,
|
||||||
|
removeQuarantineFile,
|
||||||
resolvePlaybackError,
|
resolvePlaybackError,
|
||||||
resolveQuarantine
|
resolveQuarantine
|
||||||
} from '#lib/api/admin.js';
|
} from '#lib/api/admin.js';
|
||||||
@@ -89,19 +91,30 @@ describe('/collection/reports', () => {
|
|||||||
expect(resolveQuarantine).not.toHaveBeenCalled();
|
expect(resolveQuarantine).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Delete file is one path, whatever the report came from', async () => {
|
test('Remove the file keeps the track, whatever the report came from', async () => {
|
||||||
setup([], [failure('e2', 't2', 'Intro', 2)]);
|
setup([], [failure('e2', 't2', 'Intro', 2)]);
|
||||||
await fireEvent.click(screen.getByRole('button', { name: /delete file for intro/i }));
|
await fireEvent.click(screen.getByRole('button', { name: /remove the file for intro/i }));
|
||||||
await fireEvent.click(within(screen.getByRole('dialog')).getByRole('button', { name: /confirm delete file/i }));
|
await fireEvent.click(within(screen.getByRole('dialog')).getByRole('button', { name: /confirm remove the file/i }));
|
||||||
await waitFor(() => expect(deleteQuarantineFile).toHaveBeenCalledWith('t2'));
|
await waitFor(() => expect(removeQuarantineFile).toHaveBeenCalledWith('t2'));
|
||||||
|
expect(deleteQuarantineFile).not.toHaveBeenCalled();
|
||||||
expect(resolvePlaybackError).not.toHaveBeenCalled();
|
expect(resolvePlaybackError).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Remove from library is the separate, deliberate choice', async () => {
|
||||||
|
setup([], [failure('e2', 't2', 'Intro', 2)]);
|
||||||
|
await fireEvent.click(screen.getByRole('button', { name: /remove intro from the library/i }));
|
||||||
|
await fireEvent.click(within(screen.getByRole('dialog')).getByRole('button', { name: /confirm remove from library/i }));
|
||||||
|
await waitFor(() => expect(deleteQuarantineFile).toHaveBeenCalledWith('t2'));
|
||||||
|
expect(removeQuarantineFile).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
test("on a phone the row's other actions are in its menu", async () => {
|
test("on a phone the row's other actions are in its menu", async () => {
|
||||||
setup([flagged], [failure('e2', 't2', 'Intro', 2)]);
|
setup([flagged], [failure('e2', 't2', 'Intro', 2)]);
|
||||||
const roygbiv = screen.getAllByTestId('report-row').find((r) => r.textContent?.includes('Roygbiv'))!;
|
const roygbiv = screen.getAllByTestId('report-row').find((r) => r.textContent?.includes('Roygbiv'))!;
|
||||||
await fireEvent.click(within(roygbiv).getByRole('button', { name: /more actions/i }));
|
await fireEvent.click(within(roygbiv).getByRole('button', { name: /more actions/i }));
|
||||||
expect(within(screen.getByRole('menu')).getByText('Delete file')).toBeInTheDocument();
|
const menu = within(screen.getByRole('menu'));
|
||||||
|
expect(menu.getByText('Remove the file')).toBeInTheDocument();
|
||||||
|
expect(menu.getByText('Remove from library')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('details show who flagged it, who it failed for, and the file', async () => {
|
test('details show who flagged it, who it failed for, and the file', async () => {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import { plural } from '#lib/utils/plural.js';
|
import { plural } from '#lib/utils/plural.js';
|
||||||
import { pageTitle } from '#lib/branding.js';
|
import { pageTitle } from '#lib/branding.js';
|
||||||
import { FileCheck, Music2 } from 'lucide-svelte';
|
import { FileCheck, Music2 } from 'lucide-svelte';
|
||||||
import { createSuspectSourcesQuery, setSuspectVerdict } from '#lib/api/admin.js';
|
import { createSuspectSourcesQuery, removeSuspectFile, setSuspectVerdict } from '#lib/api/admin.js';
|
||||||
import { errMessage } from '#lib/api/errors.js';
|
import { errMessage } from '#lib/api/errors.js';
|
||||||
import { pushToast } from '#lib/stores/toast.svelte.js';
|
import { pushToast } from '#lib/stores/toast.svelte.js';
|
||||||
import { relativeTime } from '#lib/utils/relativeTime.js';
|
import { relativeTime } from '#lib/utils/relativeTime.js';
|
||||||
@@ -62,6 +62,30 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove this file: the rip goes and its track waits in Needs a file for a
|
||||||
|
// clean copy. Two clicks, as the file is deleted.
|
||||||
|
let confirmingRemove = $state<string | null>(null);
|
||||||
|
let removed = $state<Record<string, boolean>>({});
|
||||||
|
|
||||||
|
async function onRemove(t: AdminSuspectTrack) {
|
||||||
|
if (confirmingRemove !== t.track_id) {
|
||||||
|
confirmingRemove = t.track_id;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
confirmingRemove = null;
|
||||||
|
saving = t.track_id;
|
||||||
|
try {
|
||||||
|
await removeSuspectFile(t.track_id);
|
||||||
|
removed[t.track_id] = true;
|
||||||
|
pushToast(`Removed the file. ${t.title} waits in Needs a file for a clean copy.`);
|
||||||
|
query.refetch();
|
||||||
|
} catch (e: unknown) {
|
||||||
|
pushToast(errMessage(e), 'error');
|
||||||
|
} finally {
|
||||||
|
saving = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function basename(path: string): string {
|
function basename(path: string): string {
|
||||||
return path.slice(path.lastIndexOf('/') + 1);
|
return path.slice(path.lastIndexOf('/') + 1);
|
||||||
}
|
}
|
||||||
@@ -97,7 +121,8 @@
|
|||||||
a video site, and can be the wrong audio: a live take, a music-video edit, or
|
a video site, and can be the wrong audio: a live take, a music-video edit, or
|
||||||
something else entirely. Each one is kept out of radio and the mixes, though it still
|
something else entirely. Each one is kept out of radio and the mixes, though it still
|
||||||
plays when you choose it, and it is merged away where the library has a clean copy of the
|
plays when you choose it, and it is merged away where the library has a clean copy of the
|
||||||
same song. If one is fine, say so and it goes back in.
|
same song. If one is fine, say so and it goes back in. If it is not, remove the file: the
|
||||||
|
track waits in Needs a file until a clean copy is in the library.
|
||||||
</p>
|
</p>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
@@ -199,6 +224,17 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
{#if verdictOf(t) !== 'fine' && !removed[t.track_id]}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onclick={() => onRemove(t)}
|
||||||
|
disabled={saving === t.track_id}
|
||||||
|
aria-label={confirmingRemove === t.track_id ? `Confirm remove the file of ${t.title}` : `Remove the file of ${t.title}`}
|
||||||
|
class="shrink-0 rounded-md border border-border px-2.5 py-1 text-xs text-text-secondary hover:bg-surface-hover hover:text-text-primary disabled:opacity-50"
|
||||||
|
>
|
||||||
|
{confirmingRemove === t.track_id ? 'Remove it?' : 'Remove this file'}
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
</li>
|
</li>
|
||||||
{/each}
|
{/each}
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -5,11 +5,12 @@ import type { AdminSuspectResponse, AdminSuspectTrack } from '#lib/api/types.js'
|
|||||||
|
|
||||||
vi.mock('#lib/api/admin.js', () => ({
|
vi.mock('#lib/api/admin.js', () => ({
|
||||||
createSuspectSourcesQuery: vi.fn(),
|
createSuspectSourcesQuery: vi.fn(),
|
||||||
setSuspectVerdict: vi.fn(async () => {})
|
setSuspectVerdict: vi.fn(async () => {}),
|
||||||
|
removeSuspectFile: vi.fn(async () => {})
|
||||||
}));
|
}));
|
||||||
|
|
||||||
import SuspectSourcesPage from './+page.svelte';
|
import SuspectSourcesPage from './+page.svelte';
|
||||||
import { createSuspectSourcesQuery, setSuspectVerdict } from '#lib/api/admin.js';
|
import { createSuspectSourcesQuery, removeSuspectFile, setSuspectVerdict } from '#lib/api/admin.js';
|
||||||
|
|
||||||
const mocked = createSuspectSourcesQuery as ReturnType<typeof vi.fn>;
|
const mocked = createSuspectSourcesQuery as ReturnType<typeof vi.fn>;
|
||||||
|
|
||||||
@@ -136,4 +137,25 @@ describe('Suspect sources page', () => {
|
|||||||
expect(await screen.findByText('Marked fine')).toBeInTheDocument();
|
expect(await screen.findByText('Marked fine')).toBeInTheDocument();
|
||||||
expect(screen.getByRole('button', { name: 'Hold back again' })).toBeInTheDocument();
|
expect(screen.getByRole('button', { name: 'Hold back again' })).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// A rip that is not fine has its file removed, on a second click; the track
|
||||||
|
// waits for a clean copy.
|
||||||
|
test('Remove this file asks once more, then removes the rip', async () => {
|
||||||
|
mocked.mockReturnValue(
|
||||||
|
infinite([
|
||||||
|
page(0, 1, [
|
||||||
|
{
|
||||||
|
directory: HUMANZ,
|
||||||
|
tracks: [track('Strobelite', 'Gorillaz - Strobelite (Official Video).mp3', ['music video'])]
|
||||||
|
}
|
||||||
|
])
|
||||||
|
])
|
||||||
|
);
|
||||||
|
render(SuspectSourcesPage);
|
||||||
|
|
||||||
|
await fireEvent.click(screen.getByRole('button', { name: 'Remove the file of Strobelite' }));
|
||||||
|
expect(removeSuspectFile).not.toHaveBeenCalled();
|
||||||
|
await fireEvent.click(screen.getByRole('button', { name: 'Confirm remove the file of Strobelite' }));
|
||||||
|
expect(removeSuspectFile).toHaveBeenCalledWith('t-Strobelite');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user