release / govulncheck (push) Successful in 25s
release / web (push) Successful in 1m21s
release / go (push) Successful in 1m47s
release / integration (push) Successful in 4m35s
release / android (push) Successful in 7m5s
release / Build signed APK (releases and dev) (push) Successful in 7m16s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 1m1s
release / Verify release artifacts (tag releases only) (push) Skipped
The marker list behind the earlier server and web passes did not catch "for v1", "Task 5", "Phase 2" or "today: Flutter". Those comments now say what the code does. Corrected: coverart said "both v1 providers" ship on. There are four providers (MBCAA, TheAudioDB, Deezer, Last.fm), and Last.fm, which needs a key, ships off. Non-comment tokens unchanged against HEAD: 10 Go files, 7 TS/Svelte files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
83 lines
2.8 KiB
TypeScript
83 lines
2.8 KiB
TypeScript
import { createQuery } from '@tanstack/svelte-query';
|
|
import { api } from './client';
|
|
import { qk } from './queries';
|
|
import type { AlbumRef, Page } from './types';
|
|
|
|
export const BROWSE_PAGE_SIZE = 50;
|
|
|
|
// Genres are the raw ID3 strings, split on [;,] server-side but otherwise
|
|
// untouched — no case folding, no synonym mapping. So "Rock" and "rock" can
|
|
// both appear, as can "Rock/Pop" beside "Rock" and "Pop". Deliberate: the
|
|
// raw spread has to be visible before anyone can judge whether it needs
|
|
// normalising.
|
|
export type GenreCount = { genre: string; track_count: number };
|
|
|
|
export type YearCount = { year: number; album_count: number };
|
|
|
|
export async function listGenres(): Promise<GenreCount[]> {
|
|
return api.get<GenreCount[]>('/api/library/genres');
|
|
}
|
|
|
|
export async function listAlbumYears(): Promise<YearCount[]> {
|
|
return api.get<YearCount[]>('/api/library/years');
|
|
}
|
|
|
|
// The indexes use svelte-query: they're fetched once per page mount, so static
|
|
// options are enough, and the cache means bouncing between browse and a
|
|
// drill-down doesn't refetch. The drill-down lists below deliberately do NOT —
|
|
// see the note on listAlbumsByGenre.
|
|
export function createGenresQuery() {
|
|
return createQuery({
|
|
queryKey: qk.genres(),
|
|
queryFn: listGenres,
|
|
// Genres only change when the library is rescanned.
|
|
staleTime: 5 * 60_000
|
|
});
|
|
}
|
|
|
|
export function createAlbumYearsQuery() {
|
|
return createQuery({
|
|
queryKey: qk.albumYears(),
|
|
queryFn: listAlbumYears,
|
|
staleTime: 5 * 60_000
|
|
});
|
|
}
|
|
|
|
// Genre travels as a QUERY parameter, never a path segment. Raw ID3 genres
|
|
// contain slashes ("Rock/Pop" is a real tag), which a path segment cannot
|
|
// carry — the server would see two segments, and a hard reload of such a URL
|
|
// would not survive the SPA fallback either.
|
|
//
|
|
// Called directly rather than through createInfiniteQuery because the selected
|
|
// genre comes from the URL and changes without remounting the page. This
|
|
// codebase has no reactive-query-options pattern, and introducing one here
|
|
// would be a larger change than the feature warrants.
|
|
export async function listAlbumsByGenre(
|
|
genre: string,
|
|
limit: number,
|
|
offset: number
|
|
): Promise<Page<AlbumRef>> {
|
|
const params = new URLSearchParams({
|
|
genre,
|
|
limit: String(limit),
|
|
offset: String(offset)
|
|
});
|
|
return api.get<Page<AlbumRef>>(`/api/library/albums?${params}`);
|
|
}
|
|
|
|
// Single-year drill-down. The server takes an inclusive range, so one year is
|
|
// expressed as its own degenerate range rather than needing a separate shape.
|
|
export async function listAlbumsByYear(
|
|
year: number,
|
|
limit: number,
|
|
offset: number
|
|
): Promise<Page<AlbumRef>> {
|
|
const params = new URLSearchParams({
|
|
year_from: String(year),
|
|
year_to: String(year),
|
|
limit: String(limit),
|
|
offset: String(offset)
|
|
});
|
|
return api.get<Page<AlbumRef>>(`/api/library/albums?${params}`);
|
|
}
|