feat: Minstrel stops acquiring music and drops Discover
release / go (push) Successful in 1m54s
release / web (push) Failing after 5s
release / integration (push) Failing after 3m44s
release / govulncheck (push) Successful in 20s
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 19s
release / android (push) Canceled after 2m37s
release / go (push) Successful in 1m54s
release / web (push) Failing after 5s
release / integration (push) Failing after 3m44s
release / govulncheck (push) Successful in 20s
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 19s
release / android (push) Canceled after 2m37s
Minstrel is now a viewer of the library it is pointed at. Finding, downloading and filing music moves out of it. Removed from the server: - the request flow (requests, approval, auto-approve) and the wanted list, follows, release profiles and release blocks; - searching indexers, the download clients, the importer, the album lifecycle and missing-file re-acquisition; - the catalogue's discography, search and art (the MusicBrainz release and track-list cache stays, for the duplicate resolver); - Discover: its suggestions of artists not in the library, snoozes, the candidate-artist tag enrichment and its tuning scope; - writes to acquisition tables from moving the library folder and from merging duplicates, the want-list join on Suspect sources, the sealing of acquisition credentials, and the release-group lookup only re-acquisition used. Settling a wrong-slot duplicate no longer sets the release aside: the copies go and their slots show as missing until a good copy is in the library. Removed from the web: Admin > Acquisition and Requests, /requests, /discover, Follow on the artist page, the auto-approve toggle, and the Collection's wanted-list tabs. The Collection is now the library's health: an overview, Reports, Duplicates, Suspect sources and Missing files. The README and docs no longer describe getting music. The tables stay for now; a later migration drops them. The request notification kinds and the Android screens are still to go. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -17,8 +17,6 @@ function track(id: string): AdminSuspectTrack {
|
||||
markers: [],
|
||||
verdict: null,
|
||||
verdict_at: null,
|
||||
replacing: false,
|
||||
searched_at: null
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -10,9 +10,6 @@ vi.mock('./client', () => ({
|
||||
}));
|
||||
|
||||
import {
|
||||
listAdminRequests,
|
||||
approveRequest,
|
||||
rejectRequest,
|
||||
listAdminQuarantine,
|
||||
resolveQuarantine,
|
||||
deleteQuarantineFile,
|
||||
@@ -23,111 +20,13 @@ import { qk } from './queries';
|
||||
import type {
|
||||
ActionResult,
|
||||
AdminQuarantineRow,
|
||||
QuarantineActionRow,
|
||||
MusicRequest
|
||||
QuarantineActionRow
|
||||
} from './types';
|
||||
|
||||
const baseRow: MusicRequest = {
|
||||
id: 'r1',
|
||||
user_id: 'u1',
|
||||
status: 'pending',
|
||||
kind: 'album',
|
||||
artist_mbid: 'art-mbid',
|
||||
album_mbid: 'alb-mbid',
|
||||
track_mbid: null,
|
||||
artist_name: 'Aphex Twin',
|
||||
album_title: 'Drukqs',
|
||||
track_title: null,
|
||||
decided_at: null,
|
||||
decided_by: null,
|
||||
notes: null,
|
||||
completed_at: null,
|
||||
matched_track_id: null,
|
||||
matched_album_id: null,
|
||||
matched_artist_id: null,
|
||||
requested_at: '2026-01-01T00:00:00Z',
|
||||
updated_at: '2026-01-01T00:00:00Z',
|
||||
imported_album_count: 0,
|
||||
imported_track_count: 0
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('listAdminRequests', () => {
|
||||
test('no args -> /api/admin/requests with no query string', async () => {
|
||||
(api.get as ReturnType<typeof vi.fn>).mockResolvedValueOnce([baseRow]);
|
||||
await listAdminRequests();
|
||||
expect(api.get).toHaveBeenCalledWith('/api/admin/requests');
|
||||
});
|
||||
|
||||
test('status only -> ?status=', async () => {
|
||||
(api.get as ReturnType<typeof vi.fn>).mockResolvedValueOnce([baseRow]);
|
||||
await listAdminRequests('approved');
|
||||
expect(api.get).toHaveBeenCalledWith('/api/admin/requests?status=approved');
|
||||
});
|
||||
|
||||
test('status + limit -> ?status=&limit=', async () => {
|
||||
(api.get as ReturnType<typeof vi.fn>).mockResolvedValueOnce([baseRow]);
|
||||
await listAdminRequests('pending', 25);
|
||||
expect(api.get).toHaveBeenCalledWith(
|
||||
'/api/admin/requests?status=pending&limit=25'
|
||||
);
|
||||
});
|
||||
|
||||
test('limit only -> ?limit=', async () => {
|
||||
(api.get as ReturnType<typeof vi.fn>).mockResolvedValueOnce([baseRow]);
|
||||
await listAdminRequests(undefined, 10);
|
||||
expect(api.get).toHaveBeenCalledWith('/api/admin/requests?limit=10');
|
||||
});
|
||||
});
|
||||
|
||||
describe('approveRequest', () => {
|
||||
test('POSTs to /api/admin/requests/:id/approve with empty body by default', async () => {
|
||||
(api.post as ReturnType<typeof vi.fn>).mockResolvedValueOnce(baseRow);
|
||||
await approveRequest('r1');
|
||||
expect(api.post).toHaveBeenCalledWith('/api/admin/requests/r1/approve', {});
|
||||
});
|
||||
|
||||
test('sends the chosen release-type profile', async () => {
|
||||
(api.post as ReturnType<typeof vi.fn>).mockResolvedValueOnce(baseRow);
|
||||
await approveRequest('r1', 'p1');
|
||||
expect(api.post).toHaveBeenCalledWith('/api/admin/requests/r1/approve', { profile_id: 'p1' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('rejectRequest', () => {
|
||||
test('POSTs to /api/admin/requests/:id/reject with empty body when no notes', async () => {
|
||||
(api.post as ReturnType<typeof vi.fn>).mockResolvedValueOnce(baseRow);
|
||||
await rejectRequest('r1');
|
||||
expect(api.post).toHaveBeenCalledWith('/api/admin/requests/r1/reject', {});
|
||||
});
|
||||
|
||||
test('includes notes when provided', async () => {
|
||||
(api.post as ReturnType<typeof vi.fn>).mockResolvedValueOnce(baseRow);
|
||||
await rejectRequest('r1', 'duplicate of r0');
|
||||
expect(api.post).toHaveBeenCalledWith('/api/admin/requests/r1/reject', {
|
||||
notes: 'duplicate of r0'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('qk admin keys', () => {
|
||||
test('adminRequests key uses "all" when status omitted', () => {
|
||||
// listAdminRequests sends no status param when called without one (returns
|
||||
// every status), so the cache key must distinguish that from any specific
|
||||
// status — otherwise an unfiltered call would falsely cache as `pending`.
|
||||
expect(qk.adminRequests()).toEqual(['adminRequests', { status: 'all' }]);
|
||||
});
|
||||
test('adminRequests key includes the status filter', () => {
|
||||
expect(qk.adminRequests('approved')).toEqual([
|
||||
'adminRequests',
|
||||
{ status: 'approved' }
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
const baseQuarantineRow: AdminQuarantineRow = {
|
||||
track_id: 't1',
|
||||
track_title: 'Avril 14th',
|
||||
|
||||
+1
-162
@@ -16,8 +16,6 @@ import type {
|
||||
AdminStatus,
|
||||
AdminSummary,
|
||||
QuarantineActionRow,
|
||||
MusicRequest,
|
||||
RequestStatus,
|
||||
PlaybackErrorResolution
|
||||
} from './types';
|
||||
|
||||
@@ -38,7 +36,7 @@ export function createAdminSummaryQuery() {
|
||||
});
|
||||
}
|
||||
|
||||
// Admin status: who is listening, downloads, the library and disk,
|
||||
// Admin status: who is listening, the library and disk,
|
||||
// and the server, for the Overview below its verdict. Polled while open.
|
||||
|
||||
export async function getAdminStatus(): Promise<AdminStatus> {
|
||||
@@ -53,59 +51,6 @@ export function createAdminStatusQuery() {
|
||||
});
|
||||
}
|
||||
|
||||
// Admin request queue -----------------------------------------------------
|
||||
|
||||
export async function listAdminRequests(
|
||||
status?: RequestStatus,
|
||||
limit?: number
|
||||
): Promise<MusicRequest[]> {
|
||||
const params = new URLSearchParams();
|
||||
if (status) params.set('status', status);
|
||||
if (limit !== undefined) params.set('limit', String(limit));
|
||||
const qs = params.toString();
|
||||
return api.get<MusicRequest[]>(
|
||||
qs ? `/api/admin/requests?${qs}` : '/api/admin/requests'
|
||||
);
|
||||
}
|
||||
|
||||
// Approving puts the request on the wanted list. An artist
|
||||
// request is followed on profileId, or the default profile when omitted.
|
||||
export async function approveRequest(id: string, profileId?: string): Promise<MusicRequest> {
|
||||
return api.post<MusicRequest>(
|
||||
`/api/admin/requests/${id}/approve`,
|
||||
profileId ? { profile_id: profileId } : {}
|
||||
);
|
||||
}
|
||||
|
||||
export async function rejectRequest(
|
||||
id: string,
|
||||
notes?: string
|
||||
): Promise<MusicRequest> {
|
||||
const body = notes !== undefined ? { notes } : {};
|
||||
return api.post<MusicRequest>(`/api/admin/requests/${id}/reject`, body);
|
||||
}
|
||||
|
||||
// Query factories ---------------------------------------------------------
|
||||
|
||||
export function createAdminRequestsQuery(status?: RequestStatus) {
|
||||
return createQuery({
|
||||
queryKey: qk.adminRequests(status),
|
||||
queryFn: () => listAdminRequests(status),
|
||||
// Only the 'approved' tab needs polling — that's where in-flight
|
||||
// ingests live. Other tabs (pending/rejected/completed) are static
|
||||
// until an admin acts on them.
|
||||
refetchInterval: (query) => {
|
||||
if (status !== 'approved') return false;
|
||||
const rows = query.state.data as MusicRequest[] | undefined;
|
||||
return hasInFlightRequest(rows) ? 12_000 : false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function hasInFlightRequest(rows: readonly MusicRequest[] | undefined): boolean {
|
||||
return rows?.some((r) => r.status === 'approved') ?? false;
|
||||
}
|
||||
|
||||
// Admin quarantine --------------------------------------------------------
|
||||
|
||||
export async function listAdminQuarantine(): Promise<AdminQuarantineRow[]> {
|
||||
@@ -594,7 +539,6 @@ export type AdminUser = {
|
||||
username: string;
|
||||
display_name: string | null;
|
||||
is_admin: boolean;
|
||||
auto_approve_requests: boolean;
|
||||
debug_mode_enabled: boolean;
|
||||
created_at: string;
|
||||
};
|
||||
@@ -652,10 +596,6 @@ export async function resetUserPassword(id: string, password: string): Promise<v
|
||||
await api.post(`/api/admin/users/${id}/reset-password`, { password });
|
||||
}
|
||||
|
||||
export async function updateUserAutoApprove(id: string, autoApprove: boolean): Promise<AdminUser> {
|
||||
return api.put<AdminUser>(`/api/admin/users/${id}/auto-approve`, { auto_approve: autoApprove });
|
||||
}
|
||||
|
||||
// Flip an account's diagnostics/debug-reporting opt-in. Admin-set;
|
||||
// the client obeys it (with a local per-device OFF switch).
|
||||
export async function updateUserDebugMode(id: string, enabled: boolean): Promise<AdminUser> {
|
||||
@@ -970,28 +910,6 @@ export async function setSuspectVerdict(trackId: string, verdict: SuspectVerdict
|
||||
await api.put(`/api/admin/library/suspect-sources/${encodeURIComponent(trackId)}`, { verdict });
|
||||
}
|
||||
|
||||
// Missing-file re-acquisition ----------------------
|
||||
|
||||
export type ReacquisitionSettings = {
|
||||
enabled: boolean;
|
||||
grace_hours: number;
|
||||
max_per_pass: number;
|
||||
// Albums with missing files that can never be wanted automatically because
|
||||
// neither they nor their artist carries an MBID. Read-only; the server
|
||||
// computes it, and the card states it so the gap isn't a mystery.
|
||||
unnameable_albums: number;
|
||||
};
|
||||
|
||||
export async function getReacquisitionSettings(): Promise<ReacquisitionSettings> {
|
||||
return api.get<ReacquisitionSettings>('/api/admin/library/reacquisition');
|
||||
}
|
||||
|
||||
export async function updateReacquisitionSettings(
|
||||
s: ReacquisitionSettings
|
||||
): Promise<ReacquisitionSettings> {
|
||||
return api.put<ReacquisitionSettings>('/api/admin/library/reacquisition', s);
|
||||
}
|
||||
|
||||
// Notification emails: when the grouped emails go out.
|
||||
export type NotificationEmailSettings = {
|
||||
summary_hour: number;
|
||||
@@ -1008,85 +926,6 @@ export async function updateNotificationEmailSettings(
|
||||
return api.put<NotificationEmailSettings>('/api/admin/notification-email', s);
|
||||
}
|
||||
|
||||
// Indexers and download clients -------------------------------
|
||||
|
||||
export type AcquisitionProtocol = 'prowlarr' | 'torznab' | 'qbittorrent' | 'exchange';
|
||||
|
||||
/** One indexer or download client. Secrets never come back, only whether set. */
|
||||
export type AcquisitionService = {
|
||||
code: string;
|
||||
kind: 'search' | 'download';
|
||||
protocol: AcquisitionProtocol;
|
||||
label: string;
|
||||
enabled: boolean;
|
||||
base_url: string;
|
||||
has_api_key: boolean;
|
||||
has_password: boolean;
|
||||
username: string;
|
||||
category: string;
|
||||
timeout_ms: number;
|
||||
/** The three switches mean something on an exchange row only. */
|
||||
serves_search: boolean;
|
||||
serves_downloads: boolean;
|
||||
serves_enrichment: boolean;
|
||||
local_path: string;
|
||||
remote_path: string;
|
||||
searches_per_hour: number;
|
||||
/** Switched on and addressed. */
|
||||
usable: boolean;
|
||||
};
|
||||
|
||||
export type AcquisitionUpdate = Omit<
|
||||
AcquisitionService,
|
||||
'code' | 'kind' | 'protocol' | 'has_api_key' | 'has_password' | 'usable'
|
||||
>;
|
||||
|
||||
export type AcquisitionTestResult = { ok: boolean; detail: string };
|
||||
|
||||
const acquisitionBase = '/api/admin/acquisition/services';
|
||||
|
||||
export async function listAcquisitionServices(): Promise<AcquisitionService[]> {
|
||||
const res = await api.get<{ services: AcquisitionService[] }>(acquisitionBase);
|
||||
return res.services;
|
||||
}
|
||||
|
||||
export async function addAcquisitionService(
|
||||
protocol: AcquisitionProtocol
|
||||
): Promise<AcquisitionService> {
|
||||
return api.post<AcquisitionService>(acquisitionBase, { protocol });
|
||||
}
|
||||
|
||||
export async function updateAcquisitionService(
|
||||
code: string,
|
||||
u: AcquisitionUpdate
|
||||
): Promise<AcquisitionService> {
|
||||
return api.put<AcquisitionService>(`${acquisitionBase}/${encodeURIComponent(code)}`, u);
|
||||
}
|
||||
|
||||
export async function removeAcquisitionService(code: string): Promise<void> {
|
||||
await api.del(`${acquisitionBase}/${encodeURIComponent(code)}`);
|
||||
}
|
||||
|
||||
export async function testAcquisitionService(code: string): Promise<AcquisitionTestResult> {
|
||||
return api.post<AcquisitionTestResult>(`${acquisitionBase}/${encodeURIComponent(code)}/test`, {});
|
||||
}
|
||||
|
||||
/** Stores a key or password. Write-only: nothing comes back. */
|
||||
export async function setAcquisitionSecret(
|
||||
code: string,
|
||||
which: 'api-key' | 'password',
|
||||
value: string
|
||||
): Promise<void> {
|
||||
await api.put(`${acquisitionBase}/${encodeURIComponent(code)}/${which}`, { value });
|
||||
}
|
||||
|
||||
export async function clearAcquisitionSecret(
|
||||
code: string,
|
||||
which: 'api-key' | 'password'
|
||||
): Promise<void> {
|
||||
await api.del(`${acquisitionBase}/${encodeURIComponent(code)}/${which}`);
|
||||
}
|
||||
|
||||
// The server's own backup ---------------------------------------------------
|
||||
|
||||
export type BackupDestination = 'folder' | 's3';
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
import { describe, expect, test, vi, beforeEach } from 'vitest';
|
||||
|
||||
vi.mock('./client', () => ({
|
||||
api: {
|
||||
get: vi.fn(),
|
||||
post: vi.fn(),
|
||||
put: vi.fn(),
|
||||
del: vi.fn()
|
||||
}
|
||||
}));
|
||||
|
||||
import { searchCatalogue } from './catalogue';
|
||||
import { api } from './client';
|
||||
import { qk } from './queries';
|
||||
import type { CatalogueSearchResult } from './types';
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('searchCatalogue', () => {
|
||||
test('builds URL with q and kind query params', async () => {
|
||||
(api.get as ReturnType<typeof vi.fn>).mockResolvedValueOnce([]);
|
||||
await searchCatalogue('aphex twin', 'artist');
|
||||
expect(api.get).toHaveBeenCalledWith('/api/catalogue/search?q=aphex+twin&kind=artist');
|
||||
});
|
||||
|
||||
test('encodes special characters in q (quotes, ampersands, plus)', async () => {
|
||||
(api.get as ReturnType<typeof vi.fn>).mockResolvedValueOnce([]);
|
||||
await searchCatalogue('boards of canada & friends', 'album');
|
||||
const calledWith = (api.get as ReturnType<typeof vi.fn>).mock.calls[0][0] as string;
|
||||
// URLSearchParams encodes space as '+' and '&' as '%26'.
|
||||
expect(calledWith).toBe(
|
||||
'/api/catalogue/search?q=boards+of+canada+%26+friends&kind=album'
|
||||
);
|
||||
});
|
||||
|
||||
test('passes through results unchanged', async () => {
|
||||
const fixture: CatalogueSearchResult[] = [
|
||||
{
|
||||
mbid: 'mbid-1',
|
||||
name: 'Aphex Twin',
|
||||
secondary_text: 'Electronic',
|
||||
image_url: '/api/catalogue/art/artist/mbid-1?name=Aphex+Twin',
|
||||
artist_mbid: '',
|
||||
album_mbid: '',
|
||||
in_library: false,
|
||||
requested: false
|
||||
}
|
||||
];
|
||||
(api.get as ReturnType<typeof vi.fn>).mockResolvedValueOnce(fixture);
|
||||
const out = await searchCatalogue('aphex', 'artist');
|
||||
expect(out).toBe(fixture);
|
||||
});
|
||||
|
||||
test('propagates errors from api.get', async () => {
|
||||
const err = { code: 'musicbrainz_unreachable', message: 'down', status: 503 };
|
||||
(api.get as ReturnType<typeof vi.fn>).mockRejectedValueOnce(err);
|
||||
await expect(searchCatalogue('x', 'track')).rejects.toMatchObject({
|
||||
code: 'musicbrainz_unreachable',
|
||||
status: 503
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('qk.catalogueSearch', () => {
|
||||
test('keys include q + kind', () => {
|
||||
expect(qk.catalogueSearch('foo', 'artist')).toEqual([
|
||||
'catalogueSearch',
|
||||
{ q: 'foo', kind: 'artist' }
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -1,26 +0,0 @@
|
||||
import { createQuery } from '@tanstack/svelte-query';
|
||||
import { api } from './client';
|
||||
import { qk } from './queries';
|
||||
import type { CatalogueSearchResult, RequestKind } from './types';
|
||||
|
||||
// searchCatalogue asks MusicBrainz through Minstrel's release catalogue.
|
||||
// URLSearchParams handles encoding (spaces, quotes,
|
||||
// ampersands) so callers can pass q raw.
|
||||
export async function searchCatalogue(
|
||||
q: string,
|
||||
kind: RequestKind
|
||||
): Promise<CatalogueSearchResult[]> {
|
||||
const params = new URLSearchParams({ q, kind });
|
||||
return api.get<CatalogueSearchResult[]>(`/api/catalogue/search?${params.toString()}`);
|
||||
}
|
||||
|
||||
// MusicBrainz allows a request a second, so a repeated search within a minute
|
||||
// is served from the client's cache rather than asked again.
|
||||
export function createCatalogueSearchQuery(q: string, kind: RequestKind) {
|
||||
return createQuery({
|
||||
queryKey: qk.catalogueSearch(q, kind),
|
||||
queryFn: () => searchCatalogue(q, kind),
|
||||
enabled: q.length > 0,
|
||||
staleTime: 60_000
|
||||
});
|
||||
}
|
||||
@@ -29,29 +29,6 @@ export const qk = {
|
||||
likedAlbums: () => ['likedAlbums'] as const,
|
||||
likedArtists: () => ['likedArtists'] as const,
|
||||
history: () => ['history'] as const,
|
||||
// Requests / admin.
|
||||
catalogueSearch: (q: string, kind: string) =>
|
||||
['catalogueSearch', { q, kind }] as const,
|
||||
myRequests: () => ['myRequests'] as const,
|
||||
adminRequests: (status?: string) =>
|
||||
['adminRequests', { status: status ?? 'all' }] as const,
|
||||
// Wanted list. Wants sit under ['adminWants'] so one prefix
|
||||
// invalidation refreshes every tab and its counts.
|
||||
adminWants: (state: string, q: string = '', artist: string = '') =>
|
||||
['adminWants', { state, q, artist }] as const,
|
||||
wantArtists: (q: string = '') => ['adminWants', 'artists', { q }] as const,
|
||||
wantTracks: (id: string) => ['wantTracks', id] as const,
|
||||
// The Collection's Unmatched section.
|
||||
unmatched: () => ['adminWants', 'unmatched'] as const,
|
||||
adminFollows: () => ['adminFollows'] as const,
|
||||
adminFollow: (artistMbid: string) => ['adminFollow', artistMbid] as const,
|
||||
releaseProfiles: () => ['releaseProfiles'] as const,
|
||||
// Search and grab.
|
||||
wantCandidates: (wantId: string) => ['wantCandidates', wantId] as const,
|
||||
searchSettings: () => ['searchSettings'] as const,
|
||||
// The Wanted view's Activity and Blocked tabs.
|
||||
downloads: () => ['adminWants', 'downloads'] as const,
|
||||
releaseBlocks: () => ['adminWants', 'releaseBlocks'] as const,
|
||||
myQuarantine: () => ['myQuarantine'] as const,
|
||||
adminQuarantine: () => ['adminQuarantine'] as const,
|
||||
adminQuarantineActions: (limit?: number) =>
|
||||
@@ -83,9 +60,6 @@ export const qk = {
|
||||
notifications: () => ['notifications', 'list'] as const,
|
||||
notificationsUnread: () => ['notifications', 'unread'] as const,
|
||||
notificationSettings: () => ['notificationSettings'] as const,
|
||||
suggestions: (limit?: number) =>
|
||||
['suggestions', { limit: limit ?? 12 }] as const,
|
||||
suggestionSnoozes: () => ['suggestionSnoozes'] as const,
|
||||
home: () => ['home'] as const,
|
||||
albumsAlpha: () => ['albumsAlpha'] as const,
|
||||
artistTracks: (artistId: string) => ['artistTracks', artistId] as const,
|
||||
|
||||
@@ -1,183 +0,0 @@
|
||||
import { describe, expect, test, vi, beforeEach, afterEach } from 'vitest';
|
||||
|
||||
vi.mock('./client', () => ({
|
||||
api: {
|
||||
get: vi.fn(),
|
||||
post: vi.fn(),
|
||||
put: vi.fn(),
|
||||
del: vi.fn()
|
||||
},
|
||||
apiFetch: vi.fn()
|
||||
}));
|
||||
|
||||
import {
|
||||
createRequest,
|
||||
listMyRequests,
|
||||
getRequest,
|
||||
cancelRequest,
|
||||
hasInFlightRequest
|
||||
} from './requests';
|
||||
import { api, apiFetch } from './client';
|
||||
import { qk } from './queries';
|
||||
import type { MusicRequest } from './types';
|
||||
|
||||
const mockRow: MusicRequest = {
|
||||
id: 'r1',
|
||||
user_id: 'u1',
|
||||
status: 'pending',
|
||||
kind: 'album',
|
||||
artist_mbid: 'art-mbid',
|
||||
album_mbid: 'alb-mbid',
|
||||
track_mbid: null,
|
||||
artist_name: 'Aphex Twin',
|
||||
album_title: 'Selected Ambient Works',
|
||||
track_title: null,
|
||||
decided_at: null,
|
||||
decided_by: null,
|
||||
notes: null,
|
||||
completed_at: null,
|
||||
matched_track_id: null,
|
||||
matched_album_id: null,
|
||||
matched_artist_id: null,
|
||||
requested_at: '2026-01-01T00:00:00Z',
|
||||
updated_at: '2026-01-01T00:00:00Z',
|
||||
imported_album_count: 0,
|
||||
imported_track_count: 0
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('createRequest', () => {
|
||||
test('POSTs /api/requests with full body for an album request', async () => {
|
||||
(api.post as ReturnType<typeof vi.fn>).mockResolvedValueOnce(mockRow);
|
||||
const out = await createRequest({
|
||||
kind: 'album',
|
||||
artist_mbid: 'art-mbid',
|
||||
album_mbid: 'alb-mbid',
|
||||
artist_name: 'Aphex Twin',
|
||||
album_title: 'Selected Ambient Works'
|
||||
});
|
||||
expect(api.post).toHaveBeenCalledWith('/api/requests', {
|
||||
kind: 'album',
|
||||
artist_mbid: 'art-mbid',
|
||||
artist_name: 'Aphex Twin',
|
||||
album_mbid: 'alb-mbid',
|
||||
album_title: 'Selected Ambient Works'
|
||||
});
|
||||
expect(out).toBe(mockRow);
|
||||
});
|
||||
|
||||
test('omits empty / undefined optional MBID + title fields from wire body', async () => {
|
||||
(api.post as ReturnType<typeof vi.fn>).mockResolvedValueOnce(mockRow);
|
||||
await createRequest({
|
||||
kind: 'artist',
|
||||
artist_mbid: 'art-mbid',
|
||||
artist_name: 'Aphex Twin',
|
||||
album_mbid: '',
|
||||
track_mbid: ''
|
||||
});
|
||||
const body = (api.post as ReturnType<typeof vi.fn>).mock.calls[0][1] as Record<
|
||||
string,
|
||||
unknown
|
||||
>;
|
||||
expect(body).toEqual({
|
||||
kind: 'artist',
|
||||
artist_mbid: 'art-mbid',
|
||||
artist_name: 'Aphex Twin'
|
||||
});
|
||||
expect(body).not.toHaveProperty('album_mbid');
|
||||
expect(body).not.toHaveProperty('track_mbid');
|
||||
expect(body).not.toHaveProperty('album_title');
|
||||
expect(body).not.toHaveProperty('track_title');
|
||||
});
|
||||
|
||||
test('includes track fields for a track-kind request', async () => {
|
||||
(api.post as ReturnType<typeof vi.fn>).mockResolvedValueOnce(mockRow);
|
||||
await createRequest({
|
||||
kind: 'track',
|
||||
artist_mbid: 'art-mbid',
|
||||
album_mbid: 'alb-mbid',
|
||||
track_mbid: 'trk-mbid',
|
||||
artist_name: 'Aphex Twin',
|
||||
album_title: 'Drukqs',
|
||||
track_title: 'Avril 14th'
|
||||
});
|
||||
expect(api.post).toHaveBeenCalledWith('/api/requests', {
|
||||
kind: 'track',
|
||||
artist_mbid: 'art-mbid',
|
||||
artist_name: 'Aphex Twin',
|
||||
album_mbid: 'alb-mbid',
|
||||
track_mbid: 'trk-mbid',
|
||||
album_title: 'Drukqs',
|
||||
track_title: 'Avril 14th'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('listMyRequests', () => {
|
||||
test('GETs /api/requests', async () => {
|
||||
(api.get as ReturnType<typeof vi.fn>).mockResolvedValueOnce([mockRow]);
|
||||
const out = await listMyRequests();
|
||||
expect(api.get).toHaveBeenCalledWith('/api/requests');
|
||||
expect(out).toEqual([mockRow]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getRequest', () => {
|
||||
test('GETs /api/requests/:id', async () => {
|
||||
(api.get as ReturnType<typeof vi.fn>).mockResolvedValueOnce(mockRow);
|
||||
const out = await getRequest('r1');
|
||||
expect(api.get).toHaveBeenCalledWith('/api/requests/r1');
|
||||
expect(out).toBe(mockRow);
|
||||
});
|
||||
});
|
||||
|
||||
describe('cancelRequest', () => {
|
||||
test('DELETEs /api/requests/:id and returns the cancelled row', async () => {
|
||||
const cancelled = { ...mockRow, status: 'rejected' as const };
|
||||
(apiFetch as ReturnType<typeof vi.fn>).mockResolvedValueOnce(cancelled);
|
||||
const out = await cancelRequest('r1');
|
||||
expect(apiFetch).toHaveBeenCalledWith('/api/requests/r1', { method: 'DELETE' });
|
||||
expect(out).toBe(cancelled);
|
||||
expect(out.status).toBe('rejected');
|
||||
});
|
||||
});
|
||||
|
||||
describe('qk.myRequests', () => {
|
||||
test('returns the expected key tuple', () => {
|
||||
expect(qk.myRequests()).toEqual(['myRequests']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('hasInFlightRequest', () => {
|
||||
test('false for undefined / empty', () => {
|
||||
expect(hasInFlightRequest(undefined)).toBe(false);
|
||||
expect(hasInFlightRequest([])).toBe(false);
|
||||
});
|
||||
|
||||
test('false when no row is approved', () => {
|
||||
expect(
|
||||
hasInFlightRequest([
|
||||
{ ...mockRow, status: 'pending' },
|
||||
{ ...mockRow, status: 'completed' },
|
||||
{ ...mockRow, status: 'rejected' }
|
||||
])
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
test('true when at least one row is approved (mid-ingest)', () => {
|
||||
expect(
|
||||
hasInFlightRequest([
|
||||
{ ...mockRow, status: 'pending' },
|
||||
{ ...mockRow, status: 'approved' },
|
||||
{ ...mockRow, status: 'completed' }
|
||||
])
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -1,87 +0,0 @@
|
||||
import { createQuery } from '@tanstack/svelte-query';
|
||||
import { api, apiFetch } from './client';
|
||||
import { qk } from './queries';
|
||||
import type { MusicRequest, RequestKind } from './types';
|
||||
|
||||
/** Cadence for in-flight request polling: fast enough to feel live, slow
|
||||
enough not to hammer the server. */
|
||||
const POLL_INTERVAL_MS = 12_000;
|
||||
|
||||
/** True if any row is mid-ingest (status === 'approved'). The status flips
|
||||
to 'completed' / 'rejected' when the music arrives, so this predicate
|
||||
lets the page poll exactly while there's something interesting to watch. */
|
||||
export function hasInFlightRequest(rows: readonly MusicRequest[] | undefined): boolean {
|
||||
return rows?.some((r) => r.status === 'approved') ?? false;
|
||||
}
|
||||
|
||||
// CreateRequestParams is the shape callers pass; unused MBID fields are
|
||||
// optional, and we omit them from the wire body rather than sending empty
|
||||
// strings (the backend tolerates either, but this keeps test expectations
|
||||
// crisp and matches the server's wire shape).
|
||||
export type CreateRequestParams = {
|
||||
kind: RequestKind;
|
||||
artist_mbid: string;
|
||||
album_mbid?: string;
|
||||
track_mbid?: string;
|
||||
artist_name: string;
|
||||
album_title?: string;
|
||||
track_title?: string;
|
||||
};
|
||||
|
||||
type CreateRequestBody = {
|
||||
kind: RequestKind;
|
||||
artist_mbid: string;
|
||||
artist_name: string;
|
||||
album_mbid?: string;
|
||||
track_mbid?: string;
|
||||
album_title?: string;
|
||||
track_title?: string;
|
||||
};
|
||||
|
||||
function buildCreateBody(params: CreateRequestParams): CreateRequestBody {
|
||||
const body: CreateRequestBody = {
|
||||
kind: params.kind,
|
||||
artist_mbid: params.artist_mbid,
|
||||
artist_name: params.artist_name
|
||||
};
|
||||
if (params.album_mbid) body.album_mbid = params.album_mbid;
|
||||
if (params.track_mbid) body.track_mbid = params.track_mbid;
|
||||
if (params.album_title) body.album_title = params.album_title;
|
||||
if (params.track_title) body.track_title = params.track_title;
|
||||
return body;
|
||||
}
|
||||
|
||||
export async function createRequest(params: CreateRequestParams): Promise<MusicRequest> {
|
||||
return api.post<MusicRequest>('/api/requests', buildCreateBody(params));
|
||||
}
|
||||
|
||||
export async function listMyRequests(): Promise<MusicRequest[]> {
|
||||
return api.get<MusicRequest[]>('/api/requests');
|
||||
}
|
||||
|
||||
export async function getRequest(id: string): Promise<MusicRequest> {
|
||||
return api.get<MusicRequest>(`/api/requests/${id}`);
|
||||
}
|
||||
|
||||
// Server returns the cancelled row body (not 204) so callers can patch the
|
||||
// cache without a refetch. api.del's return type is fixed to null, so we
|
||||
// drop down to apiFetch here to keep typing honest.
|
||||
export async function cancelRequest(id: string): Promise<MusicRequest> {
|
||||
return apiFetch(`/api/requests/${id}`, { method: 'DELETE' }) as Promise<MusicRequest>;
|
||||
}
|
||||
|
||||
export function createMyRequestsQuery() {
|
||||
return createQuery({
|
||||
queryKey: qk.myRequests(),
|
||||
queryFn: listMyRequests,
|
||||
staleTime: 60_000,
|
||||
// Auto-poll while at least one user request is mid-ingest. Stops
|
||||
// automatically when all rows are pending/completed/rejected.
|
||||
// refetchIntervalInBackground defaults to false → polling pauses
|
||||
// while the tab is hidden and resumes on focus.
|
||||
refetchInterval: (query) =>
|
||||
hasInFlightRequest(query.state.data as MusicRequest[] | undefined)
|
||||
? POLL_INTERVAL_MS
|
||||
: false
|
||||
});
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
import { afterEach, describe, expect, test, vi } from 'vitest';
|
||||
|
||||
vi.mock('./client', () => ({
|
||||
api: { get: vi.fn(), post: vi.fn(), del: vi.fn() }
|
||||
}));
|
||||
|
||||
import {
|
||||
listSuggestions,
|
||||
listSnoozes,
|
||||
snoozeSuggestion,
|
||||
unsnoozeSuggestion
|
||||
} from './suggestions';
|
||||
import { qk } from './queries';
|
||||
import { api } from './client';
|
||||
import type { ArtistSuggestion, SuggestionSnooze } from './types';
|
||||
|
||||
afterEach(() => vi.clearAllMocks());
|
||||
|
||||
describe('suggestions client', () => {
|
||||
test('listSuggestions hits the right URL with default limit', async () => {
|
||||
const fixture: ArtistSuggestion[] = [
|
||||
{
|
||||
mbid: 'm1',
|
||||
name: 'Outsider',
|
||||
score: 1.5,
|
||||
attribution: [
|
||||
{ artist_id: 'a1', name: 'Seed', contribution: 0.9, is_liked: true, play_count: 0 }
|
||||
]
|
||||
}
|
||||
];
|
||||
(api.get as ReturnType<typeof vi.fn>).mockResolvedValueOnce(fixture);
|
||||
const got = await listSuggestions();
|
||||
expect(api.get).toHaveBeenCalledWith('/api/discover/suggestions?limit=12');
|
||||
expect(got).toEqual(fixture);
|
||||
});
|
||||
|
||||
test('listSuggestions honors a custom limit', async () => {
|
||||
(api.get as ReturnType<typeof vi.fn>).mockResolvedValueOnce([]);
|
||||
await listSuggestions(20);
|
||||
expect(api.get).toHaveBeenCalledWith('/api/discover/suggestions?limit=20');
|
||||
});
|
||||
|
||||
test('qk.suggestions key shape', () => {
|
||||
expect(qk.suggestions()).toEqual(['suggestions', { limit: 12 }]);
|
||||
expect(qk.suggestions(20)).toEqual(['suggestions', { limit: 20 }]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('suggestion snoozes (#2375)', () => {
|
||||
test('snoozeSuggestion sends the name — the server 400s without it', async () => {
|
||||
(api.post as ReturnType<typeof vi.fn>).mockResolvedValueOnce(null);
|
||||
await snoozeSuggestion('mb-1', 'Parked Artist');
|
||||
expect(api.post).toHaveBeenCalledWith('/api/discover/suggestions/mb-1/snooze', {
|
||||
name: 'Parked Artist'
|
||||
});
|
||||
});
|
||||
|
||||
test('snoozeSuggestion sends no days, leaving the default to the server', async () => {
|
||||
(api.post as ReturnType<typeof vi.fn>).mockResolvedValueOnce(null);
|
||||
await snoozeSuggestion('mb-1', 'Parked Artist');
|
||||
const body = (api.post as ReturnType<typeof vi.fn>).mock.calls[0][1] as Record<string, unknown>;
|
||||
expect(body).not.toHaveProperty('days');
|
||||
});
|
||||
|
||||
// MBIDs are UUIDs today, but the column is free-text and the value comes
|
||||
// from an external similarity feed, so it goes through encodeURIComponent.
|
||||
test('the mbid is URL-encoded into the path', async () => {
|
||||
(api.post as ReturnType<typeof vi.fn>).mockResolvedValueOnce(null);
|
||||
await snoozeSuggestion('weird/id?x', 'Odd');
|
||||
expect(api.post).toHaveBeenCalledWith(
|
||||
'/api/discover/suggestions/weird%2Fid%3Fx/snooze',
|
||||
{ name: 'Odd' }
|
||||
);
|
||||
});
|
||||
|
||||
test('unsnoozeSuggestion DELETEs the same path', async () => {
|
||||
(api.del as ReturnType<typeof vi.fn>).mockResolvedValueOnce(null);
|
||||
await unsnoozeSuggestion('mb-1');
|
||||
expect(api.del).toHaveBeenCalledWith('/api/discover/suggestions/mb-1/snooze');
|
||||
});
|
||||
|
||||
test('listSnoozes hits the snoozes collection', async () => {
|
||||
const fixture: SuggestionSnooze[] = [
|
||||
{
|
||||
mbid: 'mb-1',
|
||||
name: 'Parked Artist',
|
||||
snoozed_until: '2026-11-01T00:00:00Z',
|
||||
created_at: '2026-08-03T00:00:00Z'
|
||||
}
|
||||
];
|
||||
(api.get as ReturnType<typeof vi.fn>).mockResolvedValueOnce(fixture);
|
||||
const got = await listSnoozes();
|
||||
expect(api.get).toHaveBeenCalledWith('/api/discover/snoozes');
|
||||
expect(got).toEqual(fixture);
|
||||
});
|
||||
|
||||
test('qk.suggestionSnoozes key shape', () => {
|
||||
expect(qk.suggestionSnoozes()).toEqual(['suggestionSnoozes']);
|
||||
});
|
||||
});
|
||||
@@ -1,49 +0,0 @@
|
||||
import { createQuery } from '@tanstack/svelte-query';
|
||||
import { api } from './client';
|
||||
import { qk } from './queries';
|
||||
import type { ArtistSuggestion, SuggestionSnooze } from './types';
|
||||
|
||||
export async function listSuggestions(limit = 12): Promise<ArtistSuggestion[]> {
|
||||
return api.get<ArtistSuggestion[]>(`/api/discover/suggestions?limit=${limit}`);
|
||||
}
|
||||
|
||||
export function createSuggestionsQuery(limit = 12) {
|
||||
return createQuery({
|
||||
queryKey: qk.suggestions(limit),
|
||||
queryFn: () => listSuggestions(limit),
|
||||
staleTime: 5 * 60_000 // 5 minutes
|
||||
});
|
||||
}
|
||||
|
||||
// Parks a suggestion for the server's default period (90 days). `name` is
|
||||
// REQUIRED by the server and is not optional bookkeeping: candidates are
|
||||
// out-of-library, so there is no artists row to resolve a display name from
|
||||
// and the snooze list would have nothing to render. Omitting it is a 400.
|
||||
//
|
||||
// No `days` is sent: the default is an admin setting on the server (Discover
|
||||
// tuning), and hardcoding a value here would pin it to the client instead of
|
||||
// the server that owns it.
|
||||
export async function snoozeSuggestion(mbid: string, name: string): Promise<void> {
|
||||
await api.post<null>(`/api/discover/suggestions/${encodeURIComponent(mbid)}/snooze`, { name });
|
||||
}
|
||||
|
||||
// Brings a parked suggestion back immediately. The server 404s an MBID that
|
||||
// was never snoozed; callers treat that as already-unsnoozed rather than as a
|
||||
// failure, since the end state the user asked for is the one they get.
|
||||
export async function unsnoozeSuggestion(mbid: string): Promise<void> {
|
||||
await api.del(`/api/discover/suggestions/${encodeURIComponent(mbid)}/snooze`);
|
||||
}
|
||||
|
||||
export async function listSnoozes(): Promise<SuggestionSnooze[]> {
|
||||
return api.get<SuggestionSnooze[]>('/api/discover/snoozes');
|
||||
}
|
||||
|
||||
export function createSnoozesQuery() {
|
||||
return createQuery({
|
||||
queryKey: qk.suggestionSnoozes(),
|
||||
queryFn: listSnoozes
|
||||
// No staleTime, unlike the suggestions query: this list is the only route
|
||||
// back to an un-snooze, so it must reflect a snooze made seconds ago
|
||||
// rather than a cached view of the world.
|
||||
});
|
||||
}
|
||||
@@ -26,15 +26,7 @@ export type TasteTuning = {
|
||||
mood_scale: number;
|
||||
};
|
||||
|
||||
// Discover request-surface knobs. Its own scope rather than part of
|
||||
// taste: snooze_days belongs here, and a snooze must never be read as taste
|
||||
// signal.
|
||||
export type DiscoverTuning = {
|
||||
tag_overlap_weight: number;
|
||||
snooze_days: number;
|
||||
};
|
||||
|
||||
export type TuningScope = 'radio' | 'daily_mix' | 'songs_like' | 'taste' | 'discover';
|
||||
export type TuningScope = 'radio' | 'daily_mix' | 'songs_like' | 'taste';
|
||||
|
||||
/** The weight-profile scopes, as distinct from the singleton-settings scopes. */
|
||||
export type WeightProfileScope = 'radio' | 'daily_mix' | 'songs_like';
|
||||
@@ -42,11 +34,9 @@ export type WeightProfileScope = 'radio' | 'daily_mix' | 'songs_like';
|
||||
export type TuningSnapshot = {
|
||||
profiles: Record<WeightProfileScope, WeightProfile>;
|
||||
taste: TasteTuning;
|
||||
discover: DiscoverTuning;
|
||||
shipped: {
|
||||
profiles: Record<WeightProfileScope, WeightProfile>;
|
||||
taste: TasteTuning;
|
||||
discover: DiscoverTuning;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
+1
-465
@@ -133,66 +133,6 @@ export type EventRequest =
|
||||
export type PlayStartedResponse = { play_event_id: string; session_id: string };
|
||||
export type EventOkResponse = { ok: true };
|
||||
|
||||
// Request shared enums + shapes.
|
||||
// Status + Kind are used across catalogue.ts, requests.ts, and admin.ts so
|
||||
// they live here. Per-module helpers (CreateRequestParams, etc.) stay in their
|
||||
// respective modules.
|
||||
export type RequestStatus =
|
||||
| 'pending'
|
||||
| 'approved'
|
||||
| 'rejected'
|
||||
| 'completed'
|
||||
| 'failed';
|
||||
|
||||
export type RequestKind = 'artist' | 'album' | 'track';
|
||||
|
||||
// One row of the request search (GET /api/catalogue/search).
|
||||
// An album is a MusicBrainz release group; image_url is Minstrel's own art
|
||||
// endpoint, which answers 404 when no source has an image.
|
||||
export type CatalogueSearchResult = {
|
||||
mbid: string;
|
||||
name: string;
|
||||
secondary_text: string;
|
||||
image_url: string;
|
||||
artist_mbid: string;
|
||||
album_mbid: string;
|
||||
in_library: boolean;
|
||||
requested: boolean;
|
||||
};
|
||||
|
||||
// pgtype.UUID and pgtype.Timestamptz JSON-marshal as a native string when
|
||||
// Valid, and as `null` (or omitted, with omitempty) otherwise. We unify both
|
||||
// "absent" cases as `string | null` so callers branch on a single check.
|
||||
export type MusicRequest = {
|
||||
id: string;
|
||||
user_id: string;
|
||||
// The requester's username. Only the admin list sends it.
|
||||
username?: string;
|
||||
status: RequestStatus;
|
||||
kind: RequestKind;
|
||||
artist_mbid: string;
|
||||
// The album's MusicBrainz release group.
|
||||
album_mbid?: string | null;
|
||||
track_mbid?: string | null;
|
||||
artist_name: string;
|
||||
album_title?: string | null;
|
||||
track_title?: string | null;
|
||||
decided_at?: string | null;
|
||||
decided_by?: string | null;
|
||||
notes?: string | null;
|
||||
completed_at?: string | null;
|
||||
matched_track_id?: string | null;
|
||||
matched_album_id?: string | null;
|
||||
matched_artist_id?: string | null;
|
||||
requested_at: string;
|
||||
updated_at: string;
|
||||
// Live ingest counters. Server fills these from the matched entity's
|
||||
// children. Useful for in-flight requests so an admin can see
|
||||
// "5 albums · 47 tracks" while the rest is still being fetched.
|
||||
imported_album_count: number;
|
||||
imported_track_count: number;
|
||||
};
|
||||
|
||||
// Quarantine ------------------------------------------------------------
|
||||
|
||||
export type QuarantineReason =
|
||||
@@ -295,36 +235,6 @@ export type ActionResult = {
|
||||
affected_users: number;
|
||||
};
|
||||
|
||||
export type SeedContribution = {
|
||||
artist_id: string;
|
||||
name: string;
|
||||
contribution: number;
|
||||
is_liked: boolean;
|
||||
play_count: number;
|
||||
};
|
||||
|
||||
export type ArtistSuggestion = {
|
||||
mbid: string;
|
||||
name: string;
|
||||
score: number;
|
||||
attribution: SeedContribution[]; // up to 3 entries, ordered by contribution DESC
|
||||
image_url?: string; // absent → card placeholder
|
||||
// Tags this candidate shares with your taste profile, strongest first (max
|
||||
// 3). Absent for most candidates — tag coverage for artists you don't own
|
||||
// is partial by nature — so the card falls back to seed attribution.
|
||||
matched_tags?: string[];
|
||||
};
|
||||
|
||||
// One parked suggestion — "not right now", not a dislike. The server only
|
||||
// ever returns rows whose snoozed_until is still in the future, so the client
|
||||
// never has to compare against the clock to decide what to show.
|
||||
export type SuggestionSnooze = {
|
||||
mbid: string;
|
||||
name: string;
|
||||
snoozed_until: string; // RFC3339
|
||||
created_at: string;
|
||||
};
|
||||
|
||||
// Mirrors internal/api/types.go HomePayload. All slices are non-null
|
||||
// per the server contract — empty sections render as [].
|
||||
export type HomePayload = {
|
||||
@@ -357,17 +267,6 @@ export type AdminMissingTrack = {
|
||||
last_played_at: string | null;
|
||||
};
|
||||
|
||||
// What the wanted list says about this group's album:
|
||||
// when it was wanted back, and when the library held it again. null while the
|
||||
// album is inside the grace window, or when MusicBrainz can't name it.
|
||||
export type AdminReacquisitionState = {
|
||||
wanted_at: string | null;
|
||||
held_at: string | null;
|
||||
// The want itself, as the wanted list sends it, so the Missing page
|
||||
// shows its search and download and acts on it.
|
||||
want: Want | null;
|
||||
};
|
||||
|
||||
// A directory's worth of missing tracks. The server groups because the unit an
|
||||
// operator reasons about is a folder: three reorganised albums are three
|
||||
// decisions, not forty.
|
||||
@@ -375,7 +274,6 @@ export type AdminMissingGroup = {
|
||||
directory: string;
|
||||
missing_since: string;
|
||||
tracks: AdminMissingTrack[];
|
||||
reacquisition: AdminReacquisitionState | null;
|
||||
};
|
||||
|
||||
export type AdminMissingResponse = {
|
||||
@@ -405,10 +303,6 @@ export type AdminSuspectTrack = {
|
||||
// back. null: the resolver hasn't looked yet.
|
||||
verdict: SuspectVerdict | null;
|
||||
verdict_at: string | null;
|
||||
// The album is on the wanted list for a clean copy, and when one was last
|
||||
// searched for.
|
||||
replacing: boolean;
|
||||
searched_at: string | null;
|
||||
};
|
||||
|
||||
export type SuspectVerdict = 'suspect' | 'fine';
|
||||
@@ -486,12 +380,10 @@ export type MergeDuplicateResult = {
|
||||
};
|
||||
|
||||
// What settling one recording in several slots did. kept_track_id is
|
||||
// null when every copy went; blocked names the releases set aside, empty when
|
||||
// the album came from before Minstrel downloaded anything.
|
||||
// null when every copy went.
|
||||
export type RefetchDuplicateResult = {
|
||||
kept_track_id: string | null;
|
||||
removed_paths: string[];
|
||||
blocked: string[];
|
||||
};
|
||||
|
||||
export type AdminDuplicatesResponse = {
|
||||
@@ -540,357 +432,10 @@ export type ResolvedDuplicatesResponse = {
|
||||
items: ResolvedDuplicateActivity[];
|
||||
};
|
||||
|
||||
// Wanted list ------------------------------------------------
|
||||
|
||||
// library: in the library when the list began.
|
||||
export type WantReason = 'request' | 'follow' | 'missing' | 'library';
|
||||
// all: one artist's page, every album of theirs on the list.
|
||||
// upgrade: held albums wanted for a better copy.
|
||||
export type WantState = 'wanted' | 'missing' | 'upgrade' | 'held' | 'all';
|
||||
// Why a held album is wanted again: its copy is below the quality settled
|
||||
// for, or one of its tracks is a video rip.
|
||||
export type WantUpgrade = 'quality' | 'rip';
|
||||
|
||||
// One release group on the wanted list. held_at is set once the library
|
||||
// holds it; artist_id and album_id link into the library when it has them.
|
||||
export type Want = {
|
||||
id: string;
|
||||
release_group_mbid: string;
|
||||
title: string;
|
||||
artist_mbid: string;
|
||||
artist_name: string;
|
||||
artist_id?: string;
|
||||
primary_type: string;
|
||||
secondary_types: string[];
|
||||
year: string;
|
||||
reason: WantReason;
|
||||
requested_by?: string;
|
||||
album_id?: string;
|
||||
wanted_at: string;
|
||||
held_at: string | null;
|
||||
image_url: string;
|
||||
// A held album wanted for a better copy, and what the copy it has is
|
||||
// ("MP3, about 192 kbps").
|
||||
upgrade?: WantUpgrade;
|
||||
held_quality?: string;
|
||||
// The search schedule's last look, and the download running.
|
||||
search?: WantSearch | null;
|
||||
grab?: WantGrab | null;
|
||||
};
|
||||
|
||||
export type SearchOutcome = 'grabbed' | 'waiting' | 'nothing' | 'error';
|
||||
|
||||
export type WantSearch = {
|
||||
searched_at: string;
|
||||
outcome: SearchOutcome;
|
||||
considered: number;
|
||||
best_release: string;
|
||||
best_verdict: string;
|
||||
error: string;
|
||||
};
|
||||
|
||||
// What an import made of a finished download.
|
||||
export type ImportState =
|
||||
| ''
|
||||
| 'downloading'
|
||||
| 'waiting'
|
||||
| 'importing'
|
||||
| 'imported'
|
||||
| 'refused'
|
||||
| 'review'
|
||||
| 'held'
|
||||
| 'failed';
|
||||
|
||||
// A want's latest download, running or ended.
|
||||
export type WantGrab = {
|
||||
id: string;
|
||||
name: string;
|
||||
grabbed_at: string;
|
||||
origin: 'schedule' | 'operator';
|
||||
quality: string;
|
||||
live: boolean;
|
||||
end_reason: string;
|
||||
progress: number;
|
||||
import_state: ImportState;
|
||||
import_reason: string;
|
||||
// Why an ended download ended.
|
||||
end_detail: string;
|
||||
imported_at: string | null;
|
||||
imported_files: number;
|
||||
};
|
||||
|
||||
// Search and grab ----------------------------------------------
|
||||
|
||||
export type CandidateVerdict = 'grab' | 'review' | 'refused' | 'rejected' | 'blocked';
|
||||
|
||||
// One release a want's last search found, with what was decided about it.
|
||||
export type Candidate = {
|
||||
key: string;
|
||||
name: string;
|
||||
info_hash: string;
|
||||
indexer: string;
|
||||
size_bytes: number;
|
||||
seeders: number;
|
||||
files_count: number;
|
||||
format: string;
|
||||
quality: string;
|
||||
year: number;
|
||||
verdict: CandidateVerdict;
|
||||
reason: string;
|
||||
reasons: { kind: 'hard' | 'soft'; code: string; text: string }[];
|
||||
folded_from: string[];
|
||||
searched_at: string;
|
||||
downloading: boolean;
|
||||
};
|
||||
|
||||
export type Narrowing = { source: string; label: string; reason: string };
|
||||
|
||||
export type SearchResult = {
|
||||
outcome: SearchOutcome;
|
||||
considered: number;
|
||||
best_release: string;
|
||||
best_verdict: string;
|
||||
grabbed?: string;
|
||||
narrowed: Narrowing[];
|
||||
error?: string;
|
||||
};
|
||||
|
||||
export type GrabResult = {
|
||||
added: boolean;
|
||||
refused: boolean;
|
||||
gone: boolean;
|
||||
unconfigured: boolean;
|
||||
missing?: string;
|
||||
kept: boolean;
|
||||
replaced: boolean;
|
||||
verdict?: CandidateVerdict;
|
||||
reason?: string;
|
||||
error?: string;
|
||||
};
|
||||
|
||||
export type QualityTier = { tier: string; label: string; what: string };
|
||||
|
||||
// The last scheduled pass; empty before the first.
|
||||
export type SearchPass = {
|
||||
looked?: number;
|
||||
grabbed?: number;
|
||||
waiting?: number;
|
||||
nothing?: number;
|
||||
failed?: number;
|
||||
paced?: boolean;
|
||||
off?: boolean;
|
||||
unconfigured?: boolean;
|
||||
auto_grab?: boolean;
|
||||
error?: string;
|
||||
};
|
||||
|
||||
export type SearchSettings = {
|
||||
auto_grab: boolean;
|
||||
search_interval_hours: number;
|
||||
allowed_qualities: string[];
|
||||
tiers: QualityTier[];
|
||||
last_pass_at: string | null;
|
||||
last_pass: SearchPass;
|
||||
// The library folder new music is filed into ("" = the first of
|
||||
// scan_paths), and the library's folders.
|
||||
import_root: string;
|
||||
scan_paths: string[];
|
||||
// The download lifecycle: an imported download seeds to this
|
||||
// ratio or for this many days (0: removed once imported; no time limit),
|
||||
// and one nobody shares is given up after this many hours (0: never).
|
||||
seed_ratio: number;
|
||||
seed_days: number;
|
||||
stall_hours: number;
|
||||
// The tier a held album is upgraded to; "" is no quality upgrades.
|
||||
upgrade_until: string;
|
||||
};
|
||||
|
||||
export type WantCounts = {
|
||||
// Artists in the Collection's catalogue.
|
||||
artists: number;
|
||||
wanted: number;
|
||||
missing: number;
|
||||
held: number;
|
||||
// Held albums wanted for a better copy.
|
||||
upgrades: number;
|
||||
following: number;
|
||||
// Downloads running, those of them waiting on a person, releases set aside.
|
||||
activity: number;
|
||||
attention: number;
|
||||
blocked: number;
|
||||
// Library albums no MusicBrainz album matched, waiting to be matched by
|
||||
// hand or left off.
|
||||
unmatched: number;
|
||||
};
|
||||
|
||||
// What an import's check counted.
|
||||
export type ImportEvidence = {
|
||||
files: number;
|
||||
tracks: number;
|
||||
identified: number;
|
||||
recordings: number;
|
||||
lengths: number;
|
||||
titles: number;
|
||||
group_tag?: string;
|
||||
album_tag?: string;
|
||||
fingerprinted: boolean;
|
||||
};
|
||||
|
||||
// One download on the Activity tab.
|
||||
export type Download = {
|
||||
id: string;
|
||||
want_id: string | null;
|
||||
want_title: string;
|
||||
want_artist: string;
|
||||
name: string;
|
||||
indexer: string;
|
||||
client: string;
|
||||
quality: string;
|
||||
origin: 'schedule' | 'operator';
|
||||
grabbed_at: string;
|
||||
ended_at: string | null;
|
||||
end_reason: string;
|
||||
progress: number;
|
||||
import_state: ImportState;
|
||||
import_reason: string;
|
||||
imported_at: string | null;
|
||||
imported_files: number;
|
||||
destination: string;
|
||||
edition?: string;
|
||||
evidence?: ImportEvidence;
|
||||
files: string[];
|
||||
skipped: number;
|
||||
rehomed_from?: string;
|
||||
// Why an ended download ended; for an imported one, its seeding.
|
||||
end_detail: string;
|
||||
seeding: boolean;
|
||||
ratio: number;
|
||||
seed_released_at: string | null;
|
||||
// What is wrong with it now, if anything.
|
||||
condition: DownloadCondition | null;
|
||||
};
|
||||
|
||||
// An open condition on a download, from the lifecycle's ledger.
|
||||
export type DownloadCondition = {
|
||||
trigger: 'no_peers' | 'no_metadata' | 'client_error' | 'client_unreachable' | 'gone' | 'not_removed';
|
||||
detail: string;
|
||||
retries: number;
|
||||
since: string;
|
||||
};
|
||||
|
||||
// A download client not answering now.
|
||||
export type ClientDown = { client: string; detail: string; since: string };
|
||||
|
||||
export type DownloadsPage = {
|
||||
items: Download[];
|
||||
limit: number;
|
||||
offset: number;
|
||||
clients_down: ClientDown[];
|
||||
};
|
||||
|
||||
// A release set aside: by a person, by its files, or by an import's check.
|
||||
export type ReleaseBlock = {
|
||||
info_hash: string;
|
||||
name: string;
|
||||
reason: 'operator' | 'files' | 'import' | 'stalled' | 'gone';
|
||||
detail: string;
|
||||
blocked_at: string;
|
||||
// When a release given up on may be taken again; null is for good.
|
||||
expires_at: string | null;
|
||||
want_title: string;
|
||||
want_artist: string;
|
||||
};
|
||||
|
||||
export type ReleaseBlocksPage = { items: ReleaseBlock[]; limit: number; offset: number };
|
||||
|
||||
// The one-time listing of the library's albums as held: when it
|
||||
// finished (null while it runs), and how many albums nothing names to
|
||||
// MusicBrainz, so they could not be listed.
|
||||
// One album in the Collection's Unmatched section: why no
|
||||
// MusicBrainz album matched it, or that a person left it off.
|
||||
export type UnmatchedAlbum = {
|
||||
album_id: string;
|
||||
title: string;
|
||||
artist: string;
|
||||
detail: string;
|
||||
tracks: number;
|
||||
left_off: boolean;
|
||||
decided_at: string;
|
||||
};
|
||||
|
||||
// What matching an album by hand did: the MusicBrainz album it is now, and
|
||||
// how many of its tracks agree with that album's closest edition.
|
||||
export type ManualMatch = { release_group_mbid: string; title: string; artist: string; agree: number; tracks: number };
|
||||
|
||||
export type LibraryListing = { listed_at: string | null; unlisted: number };
|
||||
|
||||
// artist heads the list when it is narrowed to one artist's page.
|
||||
export type WantsPage = Page<Want> & { counts: WantCounts; library: LibraryListing; artist?: WantArtist };
|
||||
|
||||
// One artist in the Collection's catalogue: how many of their albums
|
||||
// on the list are held, of how many.
|
||||
export type WantArtist = {
|
||||
artist_mbid: string;
|
||||
artist_name: string;
|
||||
sort_name: string;
|
||||
artist_id?: string;
|
||||
image_url: string;
|
||||
albums: number;
|
||||
held: number;
|
||||
wanted: number;
|
||||
missing: number;
|
||||
downloading: number;
|
||||
following: boolean;
|
||||
};
|
||||
|
||||
export type WantArtistsPage = Page<WantArtist> & { counts: WantCounts; library: LibraryListing };
|
||||
|
||||
// An album's tracks in the Wanted view: the library's own for an
|
||||
// album it holds (a lost file marked missing), else MusicBrainz's standard
|
||||
// edition, named by edition; none when MusicBrainz lists no edition.
|
||||
export type WantTrack = { disc: number; number: number; title: string; length_ms: number; missing: boolean };
|
||||
|
||||
export type WantTracks = { source: 'library' | 'musicbrainz' | 'none'; edition?: string; tracks: WantTrack[] };
|
||||
|
||||
export type Follow = {
|
||||
artist_mbid: string;
|
||||
artist_name: string;
|
||||
artist_id?: string;
|
||||
profile_id: string;
|
||||
profile_name: string;
|
||||
followed_at: string;
|
||||
checked_at: string | null;
|
||||
open_wants: number;
|
||||
image_url: string;
|
||||
};
|
||||
|
||||
export type FollowState = { following: boolean; profile_id?: string; profile_name?: string };
|
||||
|
||||
// A release-type profile: which kinds of release a follow wants. A group
|
||||
// passes when its primary type is listed and every secondary type is too;
|
||||
// no secondary types means studio releases only.
|
||||
export type ReleaseProfile = {
|
||||
id: string;
|
||||
name: string;
|
||||
primary_types: string[];
|
||||
secondary_types: string[];
|
||||
is_default: boolean;
|
||||
follow_count: number;
|
||||
};
|
||||
|
||||
export type ReleaseProfileInput = Omit<ReleaseProfile, 'id' | 'follow_count'>;
|
||||
|
||||
export type ReleaseProfilesResponse = {
|
||||
profiles: ReleaseProfile[];
|
||||
primary_types: string[];
|
||||
secondary_types: string[];
|
||||
};
|
||||
|
||||
// What GET /api/admin/summary returns: each queue that waits on an
|
||||
// admin, with how many and since when the oldest has waited (null when empty).
|
||||
export type AdminQueue = { count: number; since: string | null };
|
||||
export type AdminSummary = {
|
||||
requests: AdminQueue;
|
||||
// Broken tracks: flagged by a listener or failed to play, counted by track.
|
||||
reports: AdminQueue;
|
||||
duplicates: AdminQueue;
|
||||
@@ -921,15 +466,6 @@ export type AdminStatus = {
|
||||
listeners_day: number;
|
||||
last_play_at: string | null;
|
||||
};
|
||||
downloads: {
|
||||
running: number;
|
||||
needs_you: number;
|
||||
needs_you_since: string | null;
|
||||
imported_day: number;
|
||||
given_up_day: number;
|
||||
live: Download[];
|
||||
clients_down: { client: string; detail: string; since: string }[];
|
||||
};
|
||||
library: { tracks: number; albums: number; artists: number; bytes: number; disks: AdminDisk[] };
|
||||
server: {
|
||||
version: string;
|
||||
|
||||
@@ -1,308 +0,0 @@
|
||||
import { createInfiniteQuery, createQuery, keepPreviousData } from '@tanstack/svelte-query';
|
||||
import { api } from './client';
|
||||
import { qk } from './queries';
|
||||
import type {
|
||||
Candidate,
|
||||
DownloadsPage,
|
||||
Follow,
|
||||
ReleaseBlocksPage,
|
||||
FollowState,
|
||||
ReleaseProfile,
|
||||
ReleaseProfileInput,
|
||||
ReleaseProfilesResponse,
|
||||
GrabResult,
|
||||
ManualMatch,
|
||||
SearchResult,
|
||||
SearchSettings,
|
||||
UnmatchedAlbum,
|
||||
WantArtistsPage,
|
||||
WantState,
|
||||
WantTracks,
|
||||
WantsPage
|
||||
} from './types';
|
||||
|
||||
// The wanted list: release groups Minstrel is to get, the
|
||||
// artists it follows for new releases, and the release-type profiles that
|
||||
// say which kinds of release a follow wants.
|
||||
|
||||
// q narrows the list to an artist or album whose name holds it; artist to
|
||||
// one artist's page, which the response then heads.
|
||||
export async function listWants(
|
||||
state: WantState,
|
||||
offset: number = 0,
|
||||
q: string = '',
|
||||
artist: string = ''
|
||||
): Promise<WantsPage> {
|
||||
const params = new URLSearchParams({ state, offset: String(offset) });
|
||||
if (q) params.set('q', q);
|
||||
if (artist) params.set('artist', artist);
|
||||
return api.get<WantsPage>(`/api/admin/wanted?${params}`);
|
||||
}
|
||||
|
||||
export function wantsNextOffset(last: WantsPage): number | undefined {
|
||||
const loaded = last.offset + last.items.length;
|
||||
return last.items.length === 0 || loaded >= last.total ? undefined : loaded;
|
||||
}
|
||||
|
||||
// Loads as the page scrolls, one tab at a time.
|
||||
export function createWantsQuery(state: WantState, q: string = '', artist: string = '') {
|
||||
return createInfiniteQuery({
|
||||
queryKey: qk.adminWants(state, q, artist),
|
||||
queryFn: ({ pageParam }) => listWants(state, pageParam as number, q, artist),
|
||||
initialPageParam: 0,
|
||||
getNextPageParam: wantsNextOffset,
|
||||
// A new filter keeps the list it narrows on screen until its answer comes.
|
||||
placeholderData: keepPreviousData,
|
||||
staleTime: 30_000
|
||||
});
|
||||
}
|
||||
|
||||
// The Collection's catalogue: every artist on the list, A–Z, with
|
||||
// how many of their albums are held. Its first page carries every section's
|
||||
// count.
|
||||
export async function listWantArtists(offset: number = 0, q: string = ''): Promise<WantArtistsPage> {
|
||||
const params = new URLSearchParams({ offset: String(offset) });
|
||||
if (q) params.set('q', q);
|
||||
return api.get<WantArtistsPage>(`/api/admin/wanted/artists?${params}`);
|
||||
}
|
||||
|
||||
export function createWantArtistsQuery(q: string = '') {
|
||||
return createInfiniteQuery({
|
||||
queryKey: qk.wantArtists(q),
|
||||
queryFn: ({ pageParam }) => listWantArtists(pageParam as number, q),
|
||||
initialPageParam: 0,
|
||||
getNextPageParam: (last: WantArtistsPage) => {
|
||||
const loaded = last.offset + last.items.length;
|
||||
return last.items.length === 0 || loaded >= last.total ? undefined : loaded;
|
||||
},
|
||||
placeholderData: keepPreviousData,
|
||||
staleTime: 30_000
|
||||
});
|
||||
}
|
||||
|
||||
// An album's tracks: the library's own for an album it holds,
|
||||
// otherwise MusicBrainz's standard edition.
|
||||
export async function getWantTracks(id: string): Promise<WantTracks> {
|
||||
return api.get<WantTracks>(`/api/admin/wanted/${id}/tracks`);
|
||||
}
|
||||
|
||||
export function createWantTracksQuery(id: string) {
|
||||
return createQuery({
|
||||
queryKey: qk.wantTracks(id),
|
||||
queryFn: () => getWantTracks(id),
|
||||
staleTime: 5 * 60_000
|
||||
});
|
||||
}
|
||||
|
||||
// The Collection's Unmatched section: library albums no MusicBrainz
|
||||
// album matched, and after them the ones a person left off.
|
||||
export async function listUnmatched(): Promise<UnmatchedAlbum[]> {
|
||||
const out = await api.get<{ items: UnmatchedAlbum[] }>('/api/admin/wanted/unmatched');
|
||||
return out.items;
|
||||
}
|
||||
|
||||
export function createUnmatchedQuery() {
|
||||
return createQuery({
|
||||
queryKey: qk.unmatched(),
|
||||
queryFn: listUnmatched,
|
||||
staleTime: 30_000
|
||||
});
|
||||
}
|
||||
|
||||
// Puts an unmatched album on the list as held, as the MusicBrainz album ref
|
||||
// names: a release group's or a release's link, or a bare id.
|
||||
export async function matchUnmatched(albumId: string, ref: string): Promise<ManualMatch> {
|
||||
return api.post<ManualMatch>(`/api/admin/wanted/unmatched/${albumId}/match`, { ref });
|
||||
}
|
||||
|
||||
// Leaves an album off for good (a local band's, which MusicBrainz will
|
||||
// never have), or puts one left off back.
|
||||
export async function leaveUnmatchedOff(albumId: string): Promise<void> {
|
||||
await api.post<void>(`/api/admin/wanted/unmatched/${albumId}/leave-off`, {});
|
||||
}
|
||||
|
||||
export async function putUnmatchedBack(albumId: string): Promise<void> {
|
||||
await api.post<void>(`/api/admin/wanted/unmatched/${albumId}/put-back`, {});
|
||||
}
|
||||
|
||||
export async function removeWant(id: string): Promise<void> {
|
||||
await api.del(`/api/admin/wanted/${id}`);
|
||||
}
|
||||
|
||||
export async function listFollows(): Promise<Follow[]> {
|
||||
return api.get<Follow[]>('/api/admin/follows');
|
||||
}
|
||||
|
||||
export function createFollowsQuery() {
|
||||
return createQuery({
|
||||
queryKey: qk.adminFollows(),
|
||||
queryFn: listFollows,
|
||||
staleTime: 30_000
|
||||
});
|
||||
}
|
||||
|
||||
export async function getFollow(artistMbid: string): Promise<FollowState> {
|
||||
return api.get<FollowState>(`/api/admin/follows/${artistMbid}`);
|
||||
}
|
||||
|
||||
export function createFollowQuery(artistMbid: string) {
|
||||
return createQuery({
|
||||
queryKey: qk.adminFollow(artistMbid),
|
||||
queryFn: () => getFollow(artistMbid),
|
||||
staleTime: 30_000
|
||||
});
|
||||
}
|
||||
|
||||
// Follows an artist, or moves a follow to another profile. wantExisting also
|
||||
// wants what the artist has already released that the profile passes and the
|
||||
// library doesn't hold. An omitted profile is the default.
|
||||
export async function putFollow(
|
||||
artistMbid: string,
|
||||
body: { artist_name: string; profile_id?: string; want_existing?: boolean }
|
||||
): Promise<FollowState> {
|
||||
return api.put<FollowState>(`/api/admin/follows/${artistMbid}`, body);
|
||||
}
|
||||
|
||||
export async function deleteFollow(artistMbid: string): Promise<void> {
|
||||
await api.del(`/api/admin/follows/${artistMbid}`);
|
||||
}
|
||||
|
||||
export async function listReleaseProfiles(): Promise<ReleaseProfilesResponse> {
|
||||
return api.get<ReleaseProfilesResponse>('/api/admin/release-profiles');
|
||||
}
|
||||
|
||||
export function createReleaseProfilesQuery() {
|
||||
return createQuery({
|
||||
queryKey: qk.releaseProfiles(),
|
||||
queryFn: listReleaseProfiles,
|
||||
staleTime: 60_000
|
||||
});
|
||||
}
|
||||
|
||||
export async function createReleaseProfile(body: ReleaseProfileInput): Promise<ReleaseProfile> {
|
||||
return api.post<ReleaseProfile>('/api/admin/release-profiles', body);
|
||||
}
|
||||
|
||||
export async function updateReleaseProfile(id: string, body: ReleaseProfileInput): Promise<ReleaseProfile> {
|
||||
return api.put<ReleaseProfile>(`/api/admin/release-profiles/${id}`, body);
|
||||
}
|
||||
|
||||
export async function deleteReleaseProfile(id: string): Promise<void> {
|
||||
await api.del(`/api/admin/release-profiles/${id}`);
|
||||
}
|
||||
|
||||
// Search and grab: each want's last search, a person's Search,
|
||||
// Grab and "never this one", and the schedule's settings.
|
||||
|
||||
export async function listCandidates(wantId: string): Promise<Candidate[]> {
|
||||
const res = await api.get<{ items: Candidate[] }>(`/api/admin/wanted/${wantId}/candidates`);
|
||||
return res.items;
|
||||
}
|
||||
|
||||
export function createCandidatesQuery(wantId: string) {
|
||||
return createQuery({
|
||||
queryKey: qk.wantCandidates(wantId),
|
||||
queryFn: () => listCandidates(wantId),
|
||||
staleTime: 30_000
|
||||
});
|
||||
}
|
||||
|
||||
// Searches now, as the schedule would: takes the best release when
|
||||
// auto-grab is on. Can take most of a minute.
|
||||
export async function searchWant(wantId: string): Promise<SearchResult> {
|
||||
return api.post<SearchResult>(`/api/admin/wanted/${wantId}/search`, {});
|
||||
}
|
||||
|
||||
// Takes the release named by key; force takes what the verdict would not.
|
||||
export async function grabCandidate(wantId: string, key: string, force: boolean): Promise<GrabResult> {
|
||||
return api.post<GrabResult>(`/api/admin/wanted/${wantId}/grab`, { key, force });
|
||||
}
|
||||
|
||||
// Never takes this release again, for any want.
|
||||
export async function blockCandidate(wantId: string, key: string): Promise<void> {
|
||||
await api.post(`/api/admin/wanted/${wantId}/block`, { key });
|
||||
}
|
||||
|
||||
export async function unblockRelease(infoHash: string): Promise<void> {
|
||||
await api.del(`/api/admin/release-blocks/${infoHash}`);
|
||||
}
|
||||
|
||||
export async function getSearchSettings(): Promise<SearchSettings> {
|
||||
return api.get<SearchSettings>('/api/admin/acquisition/settings');
|
||||
}
|
||||
|
||||
export function createSearchSettingsQuery() {
|
||||
return createQuery({
|
||||
queryKey: qk.searchSettings(),
|
||||
queryFn: getSearchSettings,
|
||||
staleTime: 30_000
|
||||
});
|
||||
}
|
||||
|
||||
export async function putSearchSettings(body: {
|
||||
auto_grab: boolean;
|
||||
search_interval_hours: number;
|
||||
allowed_qualities: string[];
|
||||
import_root: string;
|
||||
seed_ratio: number;
|
||||
seed_days: number;
|
||||
stall_hours: number;
|
||||
upgrade_until: string;
|
||||
}): Promise<SearchSettings> {
|
||||
return api.put<SearchSettings>('/api/admin/acquisition/settings', body);
|
||||
}
|
||||
|
||||
// Downloads and their imports ----------------------------------
|
||||
|
||||
// A page holding fewer than it asked for is the last.
|
||||
function nextOffset(last: { items: unknown[]; limit: number; offset: number }): number | undefined {
|
||||
return last.items.length < last.limit ? undefined : last.offset + last.items.length;
|
||||
}
|
||||
|
||||
export async function listDownloads(offset: number = 0): Promise<DownloadsPage> {
|
||||
return api.get<DownloadsPage>(`/api/admin/downloads?offset=${offset}`);
|
||||
}
|
||||
|
||||
// Running downloads first; refreshed every few seconds while one runs.
|
||||
export function createDownloadsQuery() {
|
||||
return createInfiniteQuery({
|
||||
queryKey: qk.downloads(),
|
||||
queryFn: ({ pageParam }) => listDownloads(pageParam as number),
|
||||
initialPageParam: 0,
|
||||
getNextPageParam: nextOffset,
|
||||
refetchInterval: (q) =>
|
||||
q.state.data?.pages[0]?.items.some((d) => !d.ended_at) ? 5_000 : false
|
||||
});
|
||||
}
|
||||
|
||||
export async function importAnyway(id: string): Promise<void> {
|
||||
await api.post(`/api/admin/downloads/${id}/import`, {});
|
||||
}
|
||||
|
||||
export async function retryImport(id: string): Promise<void> {
|
||||
await api.post(`/api/admin/downloads/${id}/retry`, {});
|
||||
}
|
||||
|
||||
export async function refuseDownload(id: string): Promise<void> {
|
||||
await api.post(`/api/admin/downloads/${id}/refuse`, {});
|
||||
}
|
||||
|
||||
// A running download given up: the release is set aside for good, the
|
||||
// download removed and the album searched for again.
|
||||
export async function abandonDownload(id: string): Promise<void> {
|
||||
await api.post(`/api/admin/downloads/${id}/abandon`, {});
|
||||
}
|
||||
|
||||
export async function listReleaseBlocks(offset: number = 0): Promise<ReleaseBlocksPage> {
|
||||
return api.get<ReleaseBlocksPage>(`/api/admin/release-blocks?offset=${offset}`);
|
||||
}
|
||||
|
||||
export function createReleaseBlocksQuery() {
|
||||
return createInfiniteQuery({
|
||||
queryKey: qk.releaseBlocks(),
|
||||
queryFn: ({ pageParam }) => listReleaseBlocks(pageParam as number),
|
||||
initialPageParam: 0,
|
||||
getNextPageParam: nextOffset,
|
||||
staleTime: 30_000
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user