refactor: extract shared types to $lib/types/

Move type definitions to centralized location:
- Qobuz API types (QobuzTrack, QobuzAlbum, QobuzArtist)
- UI display types (Track, AlbumDetail, ArtistDetail, PlaylistTrack)
- Local library types (LocalLibraryTrack)
- External API types (SongLinkResponse)

Reduces +page.svelte from 1806 to 1675 lines.
This commit is contained in:
vicrodh committed 2026-01-10 05:07:26 -06:00
1 parent 3ea2bb937b
commit d3ea80c5d4
2 files changed
+175 -144

No files matched your search

+162
View File
@@ -0,0 +1,162 @@
/**
* Shared Type Definitions
*
* Central location for types used across the application.
*/
// ============ Qobuz API Types ============
// Raw response types from Qobuz API (via backend)
export interface QobuzImage {
small?: string;
thumbnail?: string;
large?: string;
}
export interface QobuzTrack {
id: number;
title: string;
duration: number;
album?: {
id?: string;
title: string;
image?: QobuzImage;
};
performer?: { id?: number; name: string };
hires_streamable?: boolean;
maximum_bit_depth?: number;
maximum_sampling_rate?: number;
isrc?: string;
}
export interface QobuzAlbum {
id: string;
title: string;
artist: { id?: number; name: string };
image: QobuzImage;
release_date_original?: string;
hires_streamable?: boolean;
tracks_count?: number;
duration?: number;
label?: { name: string };
genre?: { name: string };
maximum_bit_depth?: number;
maximum_sampling_rate?: number;
tracks?: { items: QobuzTrack[] };
}
export interface QobuzArtist {
id: number;
name: string;
image?: QobuzImage;
albums_count?: number;
biography?: {
summary?: string;
content?: string;
source?: string;
};
albums?: {
items: QobuzAlbum[];
total: number;
offset: number;
limit: number;
};
}
// ============ UI Display Types ============
// Converted/formatted types for UI components
export interface Track {
id: number;
number: number;
title: string;
artist?: string;
duration: string;
durationSeconds: number;
quality?: string;
hires?: boolean;
bitDepth?: number;
samplingRate?: number;
albumId?: string;
artistId?: number;
isrc?: string;
}
export interface AlbumDetail {
id: string;
artwork: string;
title: string;
artist: string;
artistId?: number;
year: string;
label: string;
genre: string;
quality: string;
trackCount: number;
duration: string;
tracks: Track[];
}
export interface ArtistDetail {
id: number;
name: string;
image?: string;
albumsCount?: number;
biography?: {
summary?: string;
content?: string;
source?: string;
};
albums: {
id: string;
title: string;
artwork: string;
year?: string;
quality: string;
}[];
totalAlbums: number;
}
export interface PlaylistTrack {
id: number;
number: number;
title: string;
artist?: string;
album?: string;
albumArt?: string;
duration: string;
durationSeconds: number;
hires?: boolean;
bitDepth?: number;
samplingRate?: number;
albumId?: string;
artistId?: number;
isrc?: string;
}
// ============ Local Library Types ============
export interface LocalLibraryTrack {
id: number;
file_path: string;
title: string;
artist: string;
album: string;
duration_secs: number;
format: string;
bit_depth?: number;
sample_rate: number;
artwork_path?: string;
}
// ============ External API Types ============
export interface SongLinkResponse {
pageUrl: string;
title?: string;
artist?: string;
thumbnailUrl?: string;
platforms: Record<string, string>;
identifier: string;
contentType: string;
}
+13 -144
View File
@@ -109,6 +109,19 @@
type RepeatMode
} from '$lib/stores/queueStore';
// Types
import type {
QobuzTrack,
QobuzAlbum,
QobuzArtist,
Track,
AlbumDetail,
ArtistDetail,
PlaylistTrack,
LocalLibraryTrack,
SongLinkResponse
} from '$lib/types';
// Components
import Sidebar from '$lib/components/Sidebar.svelte';
import NowPlayingBar from '$lib/components/NowPlayingBar.svelte';
@@ -132,118 +145,6 @@
import PlaylistModal from '$lib/components/PlaylistModal.svelte';
import CastPicker from '$lib/components/CastPicker.svelte';
// Types
interface QobuzTrack {
id: number;
title: string;
duration: number;
album?: {
id?: string;
title: string;
image?: { small?: string; thumbnail?: string; large?: string };
};
performer?: { id?: number; name: string };
hires_streamable?: boolean;
maximum_bit_depth?: number;
maximum_sampling_rate?: number;
isrc?: string;
}
interface QobuzAlbum {
id: string;
title: string;
artist: { id?: number; name: string };
image: { small?: string; thumbnail?: string; large?: string };
release_date_original?: string;
hires_streamable?: boolean;
tracks_count?: number;
duration?: number;
label?: { name: string };
genre?: { name: string };
maximum_bit_depth?: number;
maximum_sampling_rate?: number;
tracks?: { items: QobuzTrack[] };
}
interface QobuzArtist {
id: number;
name: string;
image?: { small?: string; thumbnail?: string; large?: string };
albums_count?: number;
biography?: {
summary?: string;
content?: string;
source?: string;
};
albums?: {
items: QobuzAlbum[];
total: number;
offset: number;
limit: number;
};
}
interface ArtistDetail {
id: number;
name: string;
image?: string;
albumsCount?: number;
biography?: {
summary?: string;
content?: string;
source?: string;
};
albums: {
id: string;
title: string;
artwork: string;
year?: string;
quality: string;
}[];
totalAlbums: number;
}
interface Track {
id: number;
number: number;
title: string;
artist?: string;
duration: string;
durationSeconds: number;
quality?: string;
hires?: boolean;
bitDepth?: number;
samplingRate?: number;
albumId?: string;
artistId?: number;
isrc?: string;
}
interface AlbumDetail {
id: string;
artwork: string;
title: string;
artist: string;
artistId?: number;
year: string;
label: string;
genre: string;
quality: string;
trackCount: number;
duration: string;
tracks: Track[];
}
interface SongLinkResponse {
pageUrl: string;
title?: string;
artist?: string;
thumbnailUrl?: string;
platforms: Record<string, string>;
identifier: string;
contentType: string;
}
// Auth State (from authStore subscription)
let isLoggedIn = $state(false);
let userInfo = $state<UserInfo | null>(null);
@@ -1050,24 +951,6 @@
queueTrackLater(buildQueueTrackFromLocalTrack(track), true);
}
// Handle playing a track from playlist view
interface PlaylistTrack {
id: number;
number: number;
title: string;
artist?: string;
album?: string;
albumArt?: string;
duration: string;
durationSeconds: number;
hires?: boolean;
bitDepth?: number;
samplingRate?: number;
albumId?: string;
artistId?: number;
isrc?: string;
}
async function handlePlaylistTrackPlay(track: PlaylistTrack) {
console.log('Playing playlist track:', track);
@@ -1126,20 +1009,6 @@
}
}
// Handle playing a track from local library view
interface LocalLibraryTrack {
id: number;
file_path: string;
title: string;
artist: string;
album: string;
duration_secs: number;
format: string;
bit_depth?: number;
sample_rate: number;
artwork_path?: string;
}
async function handleLocalTrackPlay(track: LocalLibraryTrack) {
console.log('Playing local track:', track);