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