/** * Data model for the Subsonic API surface hackermusic consumes, plus * OpenSubsonic extensions (see docs/research/navidrome-api-and-audio-engine.md). * * Everything server-returned is optional-heavy: Subsonic responses are * allowed to omit fields, and servers differ in which OpenSubsonic * extensions they implement. Consumers must treat missing fields as * "unknown", never as "false/zero" — and degrade features per-field. */ /** Connection identity persisted in localStorage. */ export interface ConnectionSettings { /** Normalized server origin, e.g. `https://nav.example.com` (no trailing slash). */ host: string; username: string; password: string; } export const CLIENT_NAME = "hackermusic"; /** Latest API version Navidrome claims compatibility with. */ export const API_VERSION = "1.16.1"; /* ------------------------------------------------------------------ */ /* Response envelope */ /* ------------------------------------------------------------------ */ export interface SubsonicErrorBody { code: number; message?: string; subcode?: number; } export interface SubsonicEnvelope { status: "ok" | "failed"; version: string; /** * Which server answered, and the only field on this envelope that says so * reliably. The OpenSubsonic spec's two values are `subsonic` and `native`, * and Navidrome sends its own app name instead — `consts.AppName`, i.e. * "navidrome" (`server/subsonic/helpers.go:31`, `consts/consts.go:12`). Kept * wide because a picklist of the spec's pair would refuse the one value worth * matching, and the harvest's fast path depends on it. */ type?: string; serverVersion?: string; openSubsonic?: boolean; /** * The spec and Navidrome spell this `error`; `err` shows up in some clients and * fixtures. Read both: with only one of them the server's own explanation — * "missing parameter: 'id'", "sharing is not enabled here" — is discarded on the * floor and the user is handed " failed", which they can neither read * nor act on. */ error?: SubsonicErrorBody; err?: SubsonicErrorBody; } /* ------------------------------------------------------------------ */ /* Core entities */ /* ------------------------------------------------------------------ */ /** OpenSubsonic replayGain extension (Navidrome impl: all fields nullable). */ export interface ReplayGain { trackGain?: number | null; albumGain?: number | null; trackPeak?: number | null; albumPeak?: number | null; baseGain?: number | null; fallbackGain?: number | null; } /** * A song — the Subsonic `Child` element plus the OpenSubsonic extras we * care about. Also the shape we persist in the local index (IndexedDB). */ export interface Song { id: string; title?: string; name?: string; album?: string; albumId?: string; artist?: string; artistId?: string; genre?: string; track?: number; disc?: string; year?: number; created?: string; duration?: number; bitRate?: number; sampleRate?: number; /** OpenSubsonic */ bitDepth?: number; /** e.g. "mp3", "flac" */ suffix?: string; /** e.g. "audio/mpeg", "audio/flac" */ contentType?: string; /** OpenSubsonic */ mediaType?: "audio" | "video"; /** OpenSubsonic — original filename with path. */ path?: string; size?: number; coverArt?: string; playCount?: number; userRating?: number; starred?: string; isVideo?: boolean; /** OpenSubsonic extras */ artists?: { id: string; name: string }[]; displayArtist?: string; displayAlbumArtist?: string; contributors?: unknown[]; mood?: string; isCompilation?: boolean; musicBrainzId?: string; explicitStatus?: boolean | null; discSubtitle?: string; replayGain?: ReplayGain; } export interface ArtistIndex { name: string; artists: Artist[]; } export interface ArtistsIndex { ignoredArticles?: string; /** Older servers use index[].artist[] instead of artists[]. */ index?: { name: string; artist: Artist[] }[]; artists?: Artist[]; } export interface Artist { id: string; name: string; albumCount?: number; starred?: string; coverArt?: string; artistImageUrl?: string; roles?: string[]; musicBrainzId?: string; } export interface Album { id: string; name: string; title?: string; artist?: string; artistId?: string; coverArt?: string; songCount?: number; duration?: number; created?: string; updated?: string; year?: number; genre?: string; playCount?: number; starred?: string; /** OpenSubsonic */ displayArtist?: string; displayAlbumArtist?: string; artists?: { id: string; name: string }[]; allArtists?: { id: string; name: string; roles: string[] }[]; isCompilation?: boolean; discTitles?: string[]; musicBrainzId?: string; /** Only present in getAlbum responses — the album's tracks. */ song?: Song[]; /** OpenSubsonic JSON names this array `songs` (legacy name: `song`). */ songs?: Song[]; } export type AlbumListType = | "random" | "newest" | "highest" | "frequent" | "recent" | "alphabeticalByName" | "alphabeticalByArtist" | "starred" | "byYear" | "byGenre"; export interface Genre { value: string; songCount?: number; albumCount?: number; } export interface MusicFolder { id: number; name?: string; } export interface Playlist { id: string; name: string; comment?: string; owner?: string; created?: string; changed?: string; coverArt?: string; accessed?: string; songCount?: number; duration?: number; public?: boolean; /** Only present in getPlaylist responses. */ entries?: Song[]; } export interface ScanStatus { scanning: boolean; count: number; /** Navidrome extra. */ lastScan?: string; /** Navidrome extra. */ folderCount?: number; /** * Navidrome extra: what the last scan broke on (`scanStatus.error`, from * `scanner/controller.go`'s `LastError`). * * Read because `count` is only as good as the scan that produced it: a scan that died halfway * leaves a tally behind that the scanner is quite happy to keep reporting, and a client that * measures its own crawl against a stale figure draws the wrong conclusion about its own crawl. * Saying it is the difference between "the app cannot count" and "the server's scanner failed". */ error?: string; } export interface UserSettings { username: string; email?: string; scrobblingEnabled?: boolean; adminRole?: boolean; settingsRole?: boolean; downloadRole?: boolean; uploadRole?: boolean; playlistRole?: boolean; coverArtRole?: boolean; commentRole?: boolean; podcastRole?: boolean; streamRole?: boolean; jukeboxRole?: boolean; sharingRole?: boolean; /** Server-side bitrate cap for this user — limits "original quality". */ maxBitRate?: number; transcodingPreferences?: { staticTranscoding?: boolean; mp3Encoding?: string; }; } /* ------------------------------------------------------------------ */ /* Endpoint payload wrappers (the bit nested under subsonic-response) */ /* ------------------------------------------------------------------ */ export interface PingResponse { id?: string; } export interface GetScanStatusResponse { scanStatus: ScanStatus; } export interface GetMusicFoldersResponse { musicFolders: { folder: MusicFolder[] }; } export interface GetArtistsResponse { artists: ArtistsIndex; } export interface GetArtistResponse { artist: Artist; } export interface GetAlbumResponse { album: Album; } export interface GetSongResponse { song: Song; } export interface GetAlbumList2Response { albumList2: { album: Album[] }; } export interface GetGenresResponse { genres: { genre: Genre[] }; } export interface SearchResult { artist?: Artist[]; album?: Album[]; song?: Song[]; offset?: number; left?: number; } export interface GetSearch3Response { searchResult3: SearchResult; } export interface GetRandomSongsResponse { randomSongs: { song: Song[] }; } export interface GetSongsByGenreResponse { songsByGenre: { song: Song[] }; } export interface GetPlaylistsResponse { playlists: { playlist: Playlist[] }; } export interface GetPlaylistResponse { playlist: Playlist; } export interface GetUserResponse { user: UserSettings; } /** * One user's favorites, as `getStarred`/`getStarred2` answer them. * * Only `id` is declared, because only `id` is read: the three arrays carry three * different entity shapes (`Artist`, `AlbumID3`, `Child`) and the client's job here * is to produce the set of starred ids, not to re-describe three models it will * immediately throw away. Navidrome builds all three from unbounded queries * (`server/subsonic/album_lists.go:120-175` runs one `GetAll` per kind, no page, * no count param), so the response is as large as the user's favorites are — which * is why this is read once per session rather than per view. * * Everything is optional because the payload is: a server with nothing starred * omits the sibling entirely (`json:"...,omitempty"` on * `responses.Starred`/`Starred2`), and an empty favorites list therefore arrives as * `{"subsonic-response":{"status":"ok"}}` rather than as three empty arrays. */ export interface StarredItems { artist?: { id?: string }[]; album?: { id?: string }[]; song?: { id?: string }[]; } export interface GetStarredResponse { starred?: StarredItems; } export interface GetStarred2Response { starred2?: StarredItems; } /** * One share, as `buildShare` returns it. `url` is assembled server-side * (public.ShareURL) and is absolute only when the server knows its own external * address — otherwise it is a root-relative path, which is why the client * resolves it against the connection rather than handing it over raw. * `downloadable` is deliberately absent: this client never asks for it, and * pretending otherwise would promise a link that offers the original file. */ export interface Share { id: string; url: string; description?: string; username?: string; created?: string; expires?: string; visitCount?: number; } export interface CreateShareResponse { shares?: { share?: Share[] }; }