Skip to content

Commit 60ec52c

Browse files
committed
fix updating relations
1 parent 84c6dd7 commit 60ec52c

2 files changed

Lines changed: 31 additions & 22 deletions

File tree

src/update.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ it("handles bad values", async () => {
2727
server.get("/Fribb/anime-lists/master/anime-list-mini.json", {
2828
status: 200,
2929
body: [
30-
{ anidb_id: 1337, themoviedb_id: { tv: "unknown" } },
30+
{ anidb_id: 1337, themoviedb_id: { tv: ["unknown"] } },
3131
{ anidb_id: 1338, tvdb_id: "unknown" as never },
32-
{ anidb_id: 1339, imdb_id: "tt1337,tt1338,tt1339" },
32+
{ anidb_id: 1339, imdb_id: ["tt1337", "tt1338", "tt1339"] },
3333
{ anidb_id: 1341, themoviedb_id: { movie: 1341 } },
3434
] satisfies AnimeListsSchema,
3535
})
@@ -57,7 +57,7 @@ it("handles bad values", async () => {
5757
},
5858
{
5959
"anidb": 1339,
60-
"imdb": null,
60+
"imdb": "tt1337",
6161
"themoviedb": null,
6262
"thetvdb": null,
6363
},

src/update.ts

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ http.plugins.use(errorRetryPlugin({ retryTimes: 5 }))
1212
const isXiorError = <T>(response: T | XiorError): response is XiorError =>
1313
"stack" in (response as XiorError)
1414

15+
type MaybeArray<T> = T | T[]
16+
1517
export type AnimeListsSchema = Array<{
1618
type?: string
1719
anidb_id?: number
@@ -25,7 +27,7 @@ export type AnimeListsSchema = Array<{
2527
animenewsnetwork_id?: number
2628
animecountdown_id?: number
2729
simkl_id?: number
28-
themoviedb_id?: { [Key in "tv" | "movie"]?: Array<number | "unknown"> }
30+
themoviedb_id?: { [Key in "tv" | "movie"]?: MaybeArray<number | "unknown"> }
2931
tvdb_id?: number
3032
season?: {
3133
tvdb?: number
@@ -91,24 +93,31 @@ export const removeDuplicates = (entries: Relation[]): Relation[] => {
9193
return goodEntries
9294
}
9395

94-
export const formatEntry = (entry: AnimeListsSchema[number]): Relation => ({
95-
anidb: handleBadValues(entry.anidb_id),
96-
anilist: handleBadValues(entry.anilist_id),
97-
"anime-planet": handleBadValues(entry["anime-planet_id"]),
98-
animecountdown: handleBadValues(entry.animecountdown_id),
99-
animenewsnetwork: handleBadValues(entry.animenewsnetwork_id),
100-
anisearch: handleBadValues(entry.anisearch_id),
101-
imdb: handleBadValues(entry.imdb_id?.[0]),
102-
kitsu: handleBadValues(entry.kitsu_id),
103-
livechart: handleBadValues(entry.livechart_id),
104-
media: handleBadValues(entry.type),
105-
myanimelist: handleBadValues(entry.mal_id),
106-
simkl: handleBadValues(entry.simkl_id),
107-
themoviedb: handleBadValues((entry.themoviedb_id?.tv ?? entry.themoviedb_id?.movie)?.[0]),
108-
"themoviedb-season": handleBadValues(entry.season?.tmdb),
109-
thetvdb: handleBadValues(entry.tvdb_id),
110-
"thetvdb-season": handleBadValues(entry.season?.tvdb),
111-
})
96+
export const formatEntry = (entry: AnimeListsSchema[number]): Relation => {
97+
let themoviedb = entry.themoviedb_id?.tv ?? entry.themoviedb_id?.movie
98+
if (themoviedb != null && Array.isArray(themoviedb)) {
99+
themoviedb = themoviedb[0]
100+
}
101+
102+
return {
103+
anidb: handleBadValues(entry.anidb_id),
104+
anilist: handleBadValues(entry.anilist_id),
105+
"anime-planet": handleBadValues(entry["anime-planet_id"]),
106+
animecountdown: handleBadValues(entry.animecountdown_id),
107+
animenewsnetwork: handleBadValues(entry.animenewsnetwork_id),
108+
anisearch: handleBadValues(entry.anisearch_id),
109+
imdb: handleBadValues(entry.imdb_id?.[0]),
110+
kitsu: handleBadValues(entry.kitsu_id),
111+
livechart: handleBadValues(entry.livechart_id),
112+
media: handleBadValues(entry.type),
113+
myanimelist: handleBadValues(entry.mal_id),
114+
simkl: handleBadValues(entry.simkl_id),
115+
themoviedb: handleBadValues(themoviedb),
116+
"themoviedb-season": handleBadValues(entry.season?.tmdb),
117+
thetvdb: handleBadValues(entry.tvdb_id),
118+
"thetvdb-season": handleBadValues(entry.season?.tvdb),
119+
}
120+
}
112121

113122
export const updateRelations = async () => {
114123
log.debug("update", `Using ${process.env.NODE_ENV!} database configuration...`)

0 commit comments

Comments
 (0)