Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix]: fix playDate parsing for navidrome unstable #408

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/renderer/api/navidrome/navidrome-normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ const getCoverArtUrl = (args: {
);
};

interface WithDate {
playDate?: string;
}

const normalizePlayDate = (item: WithDate): string | null => {
return !item.playDate || item.playDate.includes('0001-') ? null : item.playDate;
};

const normalizeSong = (
item: z.infer<typeof ndType._response.song> | z.infer<typeof ndType._response.playlistSong>,
server: ServerListItem | null,
Expand Down Expand Up @@ -100,7 +108,7 @@ const normalizeSong = (
imagePlaceholderUrl,
imageUrl,
itemType: LibraryItem.SONG,
lastPlayedAt: item.playDate.includes('0001-') ? null : item.playDate,
lastPlayedAt: normalizePlayDate(item),
lyrics: item.lyrics ? item.lyrics : null,
name: item.title,
path: item.path,
Expand Down Expand Up @@ -159,7 +167,7 @@ const normalizeAlbum = (
imageUrl,
isCompilation: item.compilation,
itemType: LibraryItem.ALBUM,
lastPlayedAt: item.playDate.includes('0001-') ? null : item.playDate,
lastPlayedAt: normalizePlayDate(item),
name: item.name,
playCount: item.playCount,
releaseDate: new Date(item.minYear, 0, 1).toISOString(),
Expand Down Expand Up @@ -207,7 +215,7 @@ const normalizeAlbumArtist = (
id: item.id,
imageUrl: imageUrl || null,
itemType: LibraryItem.ALBUM_ARTIST,
lastPlayedAt: item.playDate.includes('0001-') ? null : item.playDate,
lastPlayedAt: normalizePlayDate(item),
name: item.name,
playCount: item.playCount,
serverId: server?.id || 'unknown',
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/api/navidrome/navidrome-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const albumArtist = z.object({
name: z.string(),
orderArtistName: z.string(),
playCount: z.number(),
playDate: z.string(),
playDate: z.string().optional(),
rating: z.number(),
size: z.number(),
smallImageUrl: z.string().optional(),
Expand Down Expand Up @@ -128,7 +128,7 @@ const album = z.object({
orderAlbumArtistName: z.string(),
orderAlbumName: z.string(),
playCount: z.number(),
playDate: z.string(),
playDate: z.string().optional(),
rating: z.number().optional(),
size: z.number(),
songCount: z.number(),
Expand Down Expand Up @@ -211,7 +211,7 @@ const song = z.object({
orderTitle: z.string(),
path: z.string(),
playCount: z.number(),
playDate: z.string(),
playDate: z.string().optional(),
rating: z.number().optional(),
rgAlbumGain: z.number().optional(),
rgAlbumPeak: z.number().optional(),
Expand Down