c0785cf894
Field names mirror web/src/lib/api/types.ts and the server JSON shape (internal/api/types.go's HomePayload). Hand-written DTOs per spec section 10 -- codegen revisits at ~30 models. Adopts server contract over plan-body mock: - cover_url (not cover_art_url) for artist/album refs - duration_sec (not duration_ms) for albums and tracks - stream_url, disc_number on TrackRef - sort_name/album_count on ArtistRef; sort_title/year/track_count on AlbumRef HomeData section keys match server: recently_added_albums, rediscover_albums, rediscover_artists, most_played_tracks, last_played_artists.
44 lines
1.3 KiB
Dart
44 lines
1.3 KiB
Dart
// Mirrors internal/api/types.go TrackRef and web/src/lib/api/types.ts.
|
|
//
|
|
// Server uses `duration_sec` (NOT duration_ms). `track_number` and
|
|
// `disc_number` are omitempty server-side so they're nullable here.
|
|
// `stream_url` points at /api/tracks/{id}/stream.
|
|
class TrackRef {
|
|
const TrackRef({
|
|
required this.id,
|
|
required this.title,
|
|
required this.albumId,
|
|
required this.artistId,
|
|
this.albumTitle = '',
|
|
this.artistName = '',
|
|
this.trackNumber,
|
|
this.discNumber,
|
|
this.durationSec = 0,
|
|
this.streamUrl = '',
|
|
});
|
|
|
|
final String id;
|
|
final String title;
|
|
final String albumId;
|
|
final String albumTitle;
|
|
final String artistId;
|
|
final String artistName;
|
|
final int? trackNumber;
|
|
final int? discNumber;
|
|
final int durationSec;
|
|
final String streamUrl;
|
|
|
|
factory TrackRef.fromJson(Map<String, dynamic> j) => TrackRef(
|
|
id: j['id'] as String,
|
|
title: j['title'] as String,
|
|
albumId: j['album_id'] as String,
|
|
albumTitle: j['album_title'] as String? ?? '',
|
|
artistId: j['artist_id'] as String,
|
|
artistName: j['artist_name'] as String? ?? '',
|
|
trackNumber: (j['track_number'] as num?)?.toInt(),
|
|
discNumber: (j['disc_number'] as num?)?.toInt(),
|
|
durationSec: (j['duration_sec'] as num?)?.toInt() ?? 0,
|
|
streamUrl: j['stream_url'] as String? ?? '',
|
|
);
|
|
}
|