fix navi null date (#408)

This commit is contained in:
Kendall Garner 2023-12-13 08:28:53 +00:00 committed by GitHub
parent a8814d3e8a
commit c05b474827
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 6 deletions

View file

@ -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 = ( const normalizeSong = (
item: z.infer<typeof ndType._response.song> | z.infer<typeof ndType._response.playlistSong>, item: z.infer<typeof ndType._response.song> | z.infer<typeof ndType._response.playlistSong>,
server: ServerListItem | null, server: ServerListItem | null,
@ -100,7 +108,7 @@ const normalizeSong = (
imagePlaceholderUrl, imagePlaceholderUrl,
imageUrl, imageUrl,
itemType: LibraryItem.SONG, itemType: LibraryItem.SONG,
lastPlayedAt: item.playDate.includes('0001-') ? null : item.playDate, lastPlayedAt: normalizePlayDate(item),
lyrics: item.lyrics ? item.lyrics : null, lyrics: item.lyrics ? item.lyrics : null,
name: item.title, name: item.title,
path: item.path, path: item.path,
@ -159,7 +167,7 @@ const normalizeAlbum = (
imageUrl, imageUrl,
isCompilation: item.compilation, isCompilation: item.compilation,
itemType: LibraryItem.ALBUM, itemType: LibraryItem.ALBUM,
lastPlayedAt: item.playDate.includes('0001-') ? null : item.playDate, lastPlayedAt: normalizePlayDate(item),
name: item.name, name: item.name,
playCount: item.playCount, playCount: item.playCount,
releaseDate: new Date(item.minYear, 0, 1).toISOString(), releaseDate: new Date(item.minYear, 0, 1).toISOString(),
@ -207,7 +215,7 @@ const normalizeAlbumArtist = (
id: item.id, id: item.id,
imageUrl: imageUrl || null, imageUrl: imageUrl || null,
itemType: LibraryItem.ALBUM_ARTIST, itemType: LibraryItem.ALBUM_ARTIST,
lastPlayedAt: item.playDate.includes('0001-') ? null : item.playDate, lastPlayedAt: normalizePlayDate(item),
name: item.name, name: item.name,
playCount: item.playCount, playCount: item.playCount,
serverId: server?.id || 'unknown', serverId: server?.id || 'unknown',

View file

@ -78,7 +78,7 @@ const albumArtist = z.object({
name: z.string(), name: z.string(),
orderArtistName: z.string(), orderArtistName: z.string(),
playCount: z.number(), playCount: z.number(),
playDate: z.string(), playDate: z.string().optional(),
rating: z.number(), rating: z.number(),
size: z.number(), size: z.number(),
smallImageUrl: z.string().optional(), smallImageUrl: z.string().optional(),
@ -128,7 +128,7 @@ const album = z.object({
orderAlbumArtistName: z.string(), orderAlbumArtistName: z.string(),
orderAlbumName: z.string(), orderAlbumName: z.string(),
playCount: z.number(), playCount: z.number(),
playDate: z.string(), playDate: z.string().optional(),
rating: z.number().optional(), rating: z.number().optional(),
size: z.number(), size: z.number(),
songCount: z.number(), songCount: z.number(),
@ -211,7 +211,7 @@ const song = z.object({
orderTitle: z.string(), orderTitle: z.string(),
path: z.string(), path: z.string(),
playCount: z.number(), playCount: z.number(),
playDate: z.string(), playDate: z.string().optional(),
rating: z.number().optional(), rating: z.number().optional(),
rgAlbumGain: z.number().optional(), rgAlbumGain: z.number().optional(),
rgAlbumPeak: z.number().optional(), rgAlbumPeak: z.number().optional(),