@@ -12,6 +12,8 @@ http.plugins.use(errorRetryPlugin({ retryTimes: 5 }))
1212const isXiorError = < T > ( response : T | XiorError ) : response is XiorError =>
1313 "stack" in ( response as XiorError )
1414
15+ type MaybeArray < T > = T | T [ ]
16+
1517export 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
113122export const updateRelations = async ( ) => {
114123 log . debug ( "update" , `Using ${ process . env . NODE_ENV ! } database configuration...` )
0 commit comments