Skip to content

Commit

Permalink
fix(name): fix route crash for some ids
Browse files Browse the repository at this point in the history
sometimes we don't get genres, causing the crash.

fix https://codeberg.org/zyachel/libremdb/issues/20
  • Loading branch information
zyachel committed Oct 14, 2023
1 parent 5fa5e9e commit e91c313
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/interfaces/misc/rawName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ export default interface Name {
}>;
};
};
titleGenres: {
titleGenres?: {
genres: Array<{
genre: {
text: string;
Expand Down Expand Up @@ -525,7 +525,7 @@ export default interface Name {
}>;
};
};
titleGenres: {
titleGenres?: {
genres: Array<{
genre: {
text: string;
Expand Down Expand Up @@ -740,7 +740,7 @@ export default interface Name {
}>;
};
};
titleGenres: {
titleGenres?: {
genres: Array<{
genre: {
text: string;
Expand Down
13 changes: 7 additions & 6 deletions src/utils/cleaners/name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
Expand Down Expand Up @@ -263,7 +264,7 @@ const getCredits = <T extends 'released' | 'unreleased' = 'released'>(
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: {
Expand Down

0 comments on commit e91c313

Please sign in to comment.