Skip to content

Commit 877069e

Browse files
committed
Update fields from Fribb's anime-lists
1 parent 3100e85 commit 877069e

File tree

13 files changed

+265
-53
lines changed

13 files changed

+265
-53
lines changed

docs/openapi.yaml

Lines changed: 102 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -115,34 +115,83 @@ $defs:
115115
minimum: 0
116116
maximum: 50000000
117117
example: 1337
118-
notify-moe:
118+
animenewsnetwork:
119119
oneOf:
120-
- type: "null"
121-
- type: string
122-
minLength: 1
123-
maxLength: 50
124-
example: "-cQb5Fmmg"
120+
- type: 'null'
121+
- type: integer
122+
minimum: 0
123+
maximum: 50000000
124+
example: 1337
125125
themoviedb:
126126
oneOf:
127127
- type: "null"
128128
- type: integer
129129
minimum: 0
130130
maximum: 50000000
131131
example: 1337
132+
themoviedb-season:
133+
oneOf:
134+
- type: 'null'
135+
- type: integer
136+
minimum: 0
137+
maximum: 50000000
138+
example: 1
132139
thetvdb:
133140
oneOf:
134-
- type: "null"
141+
- type: 'null'
135142
- type: integer
136143
minimum: 0
137144
maximum: 50000000
138145
example: 1337
146+
thetvdb-season:
147+
oneOf:
148+
- type: 'null'
149+
- type: integer
150+
minimum: 0
151+
maximum: 50000000
152+
example: 1
139153
myanimelist:
140154
oneOf:
141155
- type: "null"
142156
- type: integer
143157
minimum: 0
144158
maximum: 50000000
145159
example: 1337
160+
simkl:
161+
oneOf:
162+
- type: 'null'
163+
- type: integer
164+
minimum: 0
165+
maximum: 50000000
166+
example: 1337
167+
animecountdown:
168+
oneOf:
169+
- type: 'null'
170+
- type: integer
171+
minimum: 0
172+
maximum: 50000000
173+
example: 1337
174+
simkl:
175+
oneOf:
176+
- type: 'null'
177+
- type: integer
178+
minimum: 0
179+
maximum: 50000000
180+
example: 1337
181+
animecountdown:
182+
oneOf:
183+
- type: 'null'
184+
- type: integer
185+
minimum: 0
186+
maximum: 50000000
187+
example: 1337
188+
media:
189+
oneOf:
190+
- type: 'null'
191+
- type: string
192+
minLength: 0
193+
maxLength: 10
194+
example: TV
146195

147196
nullable_relation:
148197
oneOf:
@@ -153,15 +202,19 @@ $defs:
153202
example:
154203
anidb: 1337
155204
anilist: 1337
156-
anime-planet: spriggan
205+
anime-planet: dororon-enma-kun
157206
anisearch: null
158207
imdb: tt0164917
159208
kitsu: null
160209
livechart: null
161-
notify-moe: "-cQb5Fmmg"
162210
themoviedb: null
211+
themoviedb-season: 1
163212
thetvdb: null
213+
thetvdb-season: 1
164214
myanimelist: null
215+
animecountdown: null
216+
animenewsnetwork: null
217+
media: TV
165218
oneOf:
166219
- $ref: "#/$defs/nullable_relation"
167220
- type: array
@@ -305,10 +358,11 @@ paths:
305358
- anilist
306359
- anidb
307360
- anime-planet
361+
- animecountdown
362+
- animenewsnetwork
308363
- anisearch
309364
- kitsu
310365
- livechart
311-
- notify-moe
312366
- myanimelist
313367
- name: id
314368
in: query
@@ -356,7 +410,6 @@ paths:
356410
example:
357411
- anilist: 1337
358412
- anidb: 1337
359-
- notify-moe: -cQb5Fmmg
360413
oneOf:
361414
- type: object
362415
minProperties: 1
@@ -398,13 +451,26 @@ paths:
398451
- type: integer
399452
minimum: 0
400453
maximum: 50000000
401-
notify-moe:
402-
oneOf:
403-
- type: "null"
404-
- type: string
405-
minLength: 1
406-
maxLength: 50
407454
myanimelist:
455+
oneOf:
456+
- type: 'null'
457+
- type: integer
458+
minimum: 0
459+
maximum: 50000000
460+
animenewsnetwork:
461+
oneOf:
462+
- type: 'null'
463+
- type: integer
464+
minimum: 0
465+
maximum: 50000000
466+
animecountdown:
467+
oneOf:
468+
- type: 'null'
469+
- type: integer
470+
minimum: 0
471+
maximum: 50000000
472+
animecountdown:
473+
>>>>>>> 67e3824 (Update fields from Fribb's anime-lists)
408474
oneOf:
409475
- type: "null"
410476
- type: integer
@@ -454,13 +520,26 @@ paths:
454520
- type: integer
455521
minimum: 0
456522
maximum: 50000000
457-
notify-moe:
458-
oneOf:
459-
- type: "null"
460-
- type: string
461-
minLength: 1
462-
maxLength: 50
463523
myanimelist:
524+
oneOf:
525+
- type: 'null'
526+
- type: integer
527+
minimum: 0
528+
maximum: 50000000
529+
animenewsnetwork:
530+
oneOf:
531+
- type: 'null'
532+
- type: integer
533+
minimum: 0
534+
maximum: 50000000
535+
animecountdown:
536+
oneOf:
537+
- type: 'null'
538+
- type: integer
539+
minimum: 0
540+
maximum: 50000000
541+
animecountdown:
542+
>>>>>>> 67e3824 (Update fields from Fribb's anime-lists)
464543
oneOf:
465544
- type: "null"
466545
- type: integer

src/db/db.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,26 @@ export const Source = {
1515
IMDB: "imdb",
1616
Kitsu: "kitsu",
1717
LiveChart: "livechart",
18-
NotifyMoe: "notify-moe",
18+
AnimeNewsNetwork: "animenewsnetwork",
1919
TheMovieDB: "themoviedb",
20+
TheMovieDBSeason: "themoviedb-season",
2021
TheTVDB: "thetvdb",
22+
TheTVDBSeason: "thetvdb-season",
2123
MAL: "myanimelist",
24+
Simkl: "simkl",
25+
AnimeCountdown: "animecountdown",
26+
MediaType: "media",
2227
} as const
2328
export type SourceValue = (typeof Source)[keyof typeof Source]
29+
export const NonUniqueFields = [
30+
Source.IMDB,
31+
Source.TheMovieDB,
32+
Source.TheMovieDBSeason,
33+
Source.TheTVDB,
34+
Source.TheTVDBSeason,
35+
Source.Simkl,
36+
Source.MediaType,
37+
]
2438

2539
export type Relation = {
2640
[Source.AniDB]?: number
@@ -30,10 +44,15 @@ export type Relation = {
3044
[Source.IMDB]?: `tt${string}`
3145
[Source.Kitsu]?: number
3246
[Source.LiveChart]?: number
33-
[Source.NotifyMoe]?: string
47+
[Source.AnimeNewsNetwork]?: number
3448
[Source.TheMovieDB]?: number
3549
[Source.TheTVDB]?: number
3650
[Source.MAL]?: number
51+
[Source.TheTVDBSeason]?: number
52+
[Source.TheMovieDBSeason]?: number
53+
[Source.Simkl]?: number
54+
[Source.AnimeCountdown]?: number
55+
[Source.MediaType]?: string
3756
}
3857

3958
export type OldRelation = Pick<Relation, "anidb" | "anilist" | "myanimelist" | "kitsu">

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { serve } from "h3"
22

33
import { createApp } from "./app.ts"
4-
import { config } from "./config.ts"
4+
import { config, Environment } from "./config.ts"
55
import { migrator } from "./db/db.ts"
66
import { updateRelations } from "./update.ts"
77

@@ -11,7 +11,7 @@ const { NODE_ENV, PORT } = config
1111

1212
const runUpdateScript = async () => updateRelations()
1313

14-
if (NODE_ENV === "production") {
14+
if (NODE_ENV === Environment.Prod) {
1515
void runUpdateScript()
1616

1717
// eslint-disable-next-line ts/no-misused-promises
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { type Kysely, sql } from "kysely"
2+
3+
export async function up(db: Kysely<any>): Promise<void> {
4+
await sql`PRAGMA journal_mode=WAL`.execute(db)
5+
6+
await db.schema.dropTable("relations").ifExists().execute()
7+
8+
await db.schema
9+
.createTable("relations")
10+
.ifNotExists()
11+
12+
// Original columns
13+
.addColumn("anidb", "integer", (col) => col.unique())
14+
.addColumn("anilist", "integer", (col) => col.unique())
15+
.addColumn("myanimelist", "integer", (col) => col.unique())
16+
.addColumn("kitsu", "integer", (col) => col.unique())
17+
18+
// v2 columns
19+
.addColumn("anime-planet", "text", (col) => col.unique())
20+
.addColumn("anisearch", "integer", (col) => col.unique())
21+
.addColumn("imdb", "text")
22+
.addColumn("livechart", "integer", (col) => col.unique())
23+
.addColumn("themoviedb", "integer")
24+
.addColumn("thetvdb", "integer")
25+
26+
// New Columns
27+
.addColumn("themoviedb-season", "integer")
28+
.addColumn("thetvdb-season", "integer")
29+
.addColumn("animenewsnetwork", "integer", (col) => col.unique())
30+
.addColumn("animecountdown", "integer", (col) => col.unique())
31+
.addColumn("simkl", "integer")
32+
.addColumn("media", "text")
33+
.execute()
34+
}

src/routes/v2/ids/handler.test.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@ const createRelations = async <N extends number>(
1616
imdb: `tt${id++}`,
1717
kitsu: id++,
1818
livechart: id++,
19-
"notify-moe": `${id++}`,
19+
animenewsnetwork: id++,
2020
themoviedb: id++,
21+
"themoviedb-season": id++,
2122
thetvdb: id++,
23+
"thetvdb-season": id++,
2224
myanimelist: id++,
25+
simkl: id++,
26+
animecountdown: id++,
27+
media: `${id++}`,
2328
}))
2429

2530
// Insert each relation
@@ -80,10 +85,15 @@ describe("query params", () => {
8085
imdb: null!,
8186
kitsu: null!,
8287
livechart: null!,
83-
"notify-moe": null!,
88+
animenewsnetwork: null!,
8489
themoviedb: null!,
90+
"themoviedb-season": null!,
8591
thetvdb: null!,
92+
"thetvdb-season": null!,
8693
myanimelist: null!,
94+
simkl: null!,
95+
animecountdown: null!,
96+
media: null!,
8797
}
8898
await db.insertInto("relations").values(relation).execute()
8999

@@ -165,10 +175,15 @@ describe("json body", () => {
165175
imdb: null!,
166176
kitsu: null!,
167177
livechart: null!,
168-
"notify-moe": null!,
178+
animenewsnetwork: null!,
169179
themoviedb: null!,
180+
"themoviedb-season": null!,
170181
thetvdb: null!,
182+
"thetvdb-season": null!,
171183
myanimelist: null!,
184+
simkl: null!,
185+
animecountdown: null!,
186+
media: null!,
172187
}
173188
await db.insertInto("relations").values(relation).execute()
174189

src/routes/v2/ids/schemas/common.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import * as v from "valibot"
44
export const numberIdSourceSchema = v.picklist([
55
"anilist",
66
"anidb",
7+
"animecountdown",
8+
"animenewsnetwork",
79
"anisearch",
810
"kitsu",
911
"livechart",
1012
"myanimelist",
1113
])
1214

13-
export const stringIdSourceSchema = v.picklist(["anime-planet", "notify-moe"])
15+
export const stringIdSourceSchema = v.picklist(["anime-planet"])

src/routes/v2/ids/schemas/json-body.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ const okCases = [
2222
anisearch: 1337,
2323
kitsu: 1337,
2424
livechart: 1337,
25-
"notify-moe": "1337",
25+
animenewsnetwork: 1337,
2626
myanimelist: 1337,
27+
animecountdown: 1337,
2728
},
2829
true,
2930
],
@@ -47,6 +48,7 @@ const badCases = [
4748
[{ imdb: 1337 }, false],
4849
[{ themoviedb: 1337 }, false],
4950
[{ thetvdb: 1337 }, false],
51+
[{ simkl: 1337 }, false],
5052
] satisfies Cases
5153

5254
const mapToSingularArrayInput = (cases: Cases): Cases =>

src/routes/v2/ids/schemas/json-body.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ export const singularItemInputSchema = v.pipe(
1111
anidb: numberIdSchema,
1212
anilist: numberIdSchema,
1313
"anime-planet": stringIdSchema,
14+
animecountdown: numberIdSchema,
15+
animenewsnetwork: numberIdSchema,
1416
anisearch: numberIdSchema,
1517
kitsu: numberIdSchema,
1618
livechart: numberIdSchema,
17-
"notify-moe": stringIdSchema,
1819
myanimelist: numberIdSchema,
1920
}),
2021
),

0 commit comments

Comments
 (0)