fix(purchases): deserialize purchased_at as i64 unix timestamp

The Qobuz API returns purchased_at as a Unix timestamp integer, not a
string. Updated Rust structs, TypeScript types, and frontend date
formatting to handle numeric timestamps correctly.

Fixes #88

cc
This commit is contained in:
vicrodh committed 2026-02-19 16:29:13 -06:00
1 parent 183a0ec50d
commit 45ca758f47
5 files changed
+13 -13

No files matched your search

+2 -2
View File
@@ -410,7 +410,7 @@ pub struct PurchaseAlbum {
pub downloadable: bool, pub downloadable: bool,
#[serde(default)] #[serde(default)]
pub downloaded: bool, pub downloaded: bool,
pub purchased_at: Option<String>, pub purchased_at: Option<i64>,
#[serde(default)] #[serde(default)]
pub tracks: Option<SearchResultsPage<PurchaseTrack>>, pub tracks: Option<SearchResultsPage<PurchaseTrack>>,
} }
@@ -433,7 +433,7 @@ pub struct PurchaseTrack {
pub streamable: bool, pub streamable: bool,
#[serde(default)] #[serde(default)]
pub downloaded: bool, pub downloaded: bool,
pub purchased_at: Option<String>, pub purchased_at: Option<i64>,
} }
/// Favorites container /// Favorites container
+2 -2
View File
@@ -8101,7 +8101,7 @@ pub async fn v2_purchases_get_album(
maximum_bit_depth: track.maximum_bit_depth, maximum_bit_depth: track.maximum_bit_depth,
streamable: track.streamable, streamable: track.streamable,
downloaded: false, downloaded: false,
purchased_at: purchase_meta.and_then(|item| item.purchased_at.clone()), purchased_at: purchase_meta.and_then(|item| item.purchased_at),
}) })
.collect() .collect()
}) })
@@ -8122,7 +8122,7 @@ pub async fn v2_purchases_get_album(
maximum_bit_depth: album.maximum_bit_depth, maximum_bit_depth: album.maximum_bit_depth,
downloadable: purchase_meta.map(|item| item.downloadable).unwrap_or(true), downloadable: purchase_meta.map(|item| item.downloadable).unwrap_or(true),
downloaded: false, downloaded: false,
purchased_at: purchase_meta.and_then(|item| item.purchased_at.clone()), purchased_at: purchase_meta.and_then(|item| item.purchased_at),
tracks: Some(ApiSearchResultsPage { tracks: Some(ApiSearchResultsPage {
offset: 0, offset: 0,
limit: tracks_items.len() as u32, limit: tracks_items.len() as u32,
@@ -29,10 +29,10 @@
let isDownloadingAll = $state(false); let isDownloadingAll = $state(false);
let allComplete = $state(false); let allComplete = $state(false);
function formatPurchaseDate(iso?: string): string { function formatPurchaseDate(ts?: number): string {
if (!iso) return ''; if (!ts) return '';
try { try {
return new Date(iso).toLocaleDateString(undefined, { return new Date(ts * 1000).toLocaleDateString(undefined, {
year: 'numeric', year: 'numeric',
month: 'long', month: 'long',
day: 'numeric', day: 'numeric',
@@ -121,10 +121,10 @@
showAlbumSortMenu = false; showAlbumSortMenu = false;
} }
function formatPurchaseDate(iso?: string): string { function formatPurchaseDate(ts?: number): string {
if (!iso) return ''; if (!ts) return '';
try { try {
return new Date(iso).toLocaleDateString(undefined, { return new Date(ts * 1000).toLocaleDateString(undefined, {
year: 'numeric', year: 'numeric',
month: 'short', month: 'short',
day: 'numeric', day: 'numeric',
@@ -170,7 +170,7 @@
switch (albumSortBy) { switch (albumSortBy) {
case 'date': case 'date':
return sorted.sort((a, b) => return sorted.sort((a, b) =>
dir * (new Date(a.purchased_at || '').getTime() - new Date(b.purchased_at || '').getTime()) dir * ((a.purchased_at || 0) - (b.purchased_at || 0))
); );
case 'artist': case 'artist':
return sorted.sort((a, b) => dir * a.artist.name.localeCompare(b.artist.name)); return sorted.sort((a, b) => dir * a.artist.name.localeCompare(b.artist.name));
+2 -2
View File
@@ -25,7 +25,7 @@ export interface PurchasedAlbum {
maximum_sampling_rate?: number; maximum_sampling_rate?: number;
downloadable: boolean; downloadable: boolean;
downloaded?: boolean; downloaded?: boolean;
purchased_at?: string; purchased_at?: number;
tracks?: PaginatedList<PurchasedTrack>; tracks?: PaginatedList<PurchasedTrack>;
} }
@@ -46,7 +46,7 @@ export interface PurchasedTrack {
maximum_sampling_rate?: number; maximum_sampling_rate?: number;
streamable: boolean; streamable: boolean;
downloaded?: boolean; downloaded?: boolean;
purchased_at?: string; purchased_at?: number;
} }
export interface PurchaseDownloadProgress { export interface PurchaseDownloadProgress {