From e91c313f127632f1bd44d190af71bc841bbe87b7 Mon Sep 17 00:00:00 2001 From: zyachel Date: Sat, 14 Oct 2023 15:22:59 +0530 Subject: [PATCH] fix(name): fix route crash for some ids sometimes we don't get genres, causing the crash. fix https://codeberg.org/zyachel/libremdb/issues/20 --- src/interfaces/misc/rawName.ts | 6 +++--- src/utils/cleaners/name.ts | 13 +++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/interfaces/misc/rawName.ts b/src/interfaces/misc/rawName.ts index d243aa7..2a33360 100644 --- a/src/interfaces/misc/rawName.ts +++ b/src/interfaces/misc/rawName.ts @@ -373,7 +373,7 @@ export default interface Name { }>; }; }; - titleGenres: { + titleGenres?: { genres: Array<{ genre: { text: string; @@ -525,7 +525,7 @@ export default interface Name { }>; }; }; - titleGenres: { + titleGenres?: { genres: Array<{ genre: { text: string; @@ -740,7 +740,7 @@ export default interface Name { }>; }; }; - titleGenres: { + titleGenres?: { genres: Array<{ genre: { text: string; diff --git a/src/utils/cleaners/name.ts b/src/utils/cleaners/name.ts index ebf77e0..aefb9e5 100644 --- a/src/utils/cleaners/name.ts +++ b/src/utils/cleaners/name.ts @@ -113,7 +113,7 @@ const cleanName = (rawData: RawName) => { avg: item.node.title.ratingsSummary.aggregateRating ?? null, numVotes: item.node.title.ratingsSummary.voteCount, }, - genres: item.node.title.titleGenres.genres.map(genre => genre.genre.text), + genres: item.node.title.titleGenres?.genres.map(genre => genre.genre.text) ?? [], summary: { numEpisodes: item.node.summary.episodeCount ?? null, @@ -133,10 +133,11 @@ const cleanName = (rawData: RawName) => { id: cat.titleTypeCategory.id, label: cat.titleTypeCategory.text, })), - genres: misc.creditSummary.genres.map(genre => ({ - total: genre.total, - name: genre.genre.displayableProperty.value.plainText, - })), + genres: + misc.creditSummary.genres.map(genre => ({ + total: genre.total, + name: genre.genre.displayableProperty.value.plainText, + })) ?? [], }, released: getCredits(misc.releasedPrimaryCredits), // unreleased: getCredits<'unreleased'>(misc.unreleasedPrimaryCredits), @@ -263,7 +264,7 @@ const getCredits = ( numVotes: item.node.title.ratingsSummary.voteCount, }, test: JSON.stringify(item.node.title), - genres: item.node.title.titleGenres.genres.map(genre => genre.genre.text), + genres: item.node.title.titleGenres?.genres.map(genre => genre.genre.text) ?? [], productionStatus: item.node.title.productionStatus.currentProductionStage.text, summary: {