Skip to content

Commit c66ba94

Browse files
committed
Add New Fields
1 parent 782dc76 commit c66ba94

13 files changed

Lines changed: 225 additions & 10 deletions

File tree

docs/openapi.yaml

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,27 +115,69 @@ $defs:
115115
minimum: 0
116116
maximum: 50000000
117117
example: 1337
118+
animenewsnetwork:
119+
oneOf:
120+
- type: "null"
121+
- type: integer
122+
minimum: 0
123+
maximum: 50000000
124+
example: 1337
118125
themoviedb:
119126
oneOf:
120127
- type: "null"
121128
- type: integer
122129
minimum: 0
123130
maximum: 50000000
124131
example: 1337
132+
themoviedb-season:
133+
oneOf:
134+
- type: "null"
135+
- type: integer
136+
minimum: 0
137+
maximum: 50000000
138+
example: 1
125139
thetvdb:
126140
oneOf:
127141
- type: "null"
128142
- type: integer
129143
minimum: 0
130144
maximum: 50000000
131145
example: 1337
146+
thetvdb-season:
147+
oneOf:
148+
- type: "null"
149+
- type: integer
150+
minimum: 0
151+
maximum: 50000000
152+
example: 1
132153
myanimelist:
133154
oneOf:
134155
- type: "null"
135156
- type: integer
136157
minimum: 0
137158
maximum: 50000000
138159
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+
media:
175+
oneOf:
176+
- type: "null"
177+
- type: string
178+
minLength: 0
179+
maxLength: 10
180+
example: TV
139181

140182
nullable_relation:
141183
oneOf:
@@ -146,14 +188,19 @@ $defs:
146188
example:
147189
anidb: 1337
148190
anilist: 1337
149-
anime-planet: spriggan
191+
anime-planet: dororon-enma-kun
150192
anisearch: null
151193
imdb: tt0164917
152194
kitsu: null
153195
livechart: null
154196
themoviedb: null
197+
themoviedb-season: 1
155198
thetvdb: null
199+
thetvdb-season: 1
156200
myanimelist: null
201+
animecountdown: null
202+
animenewsnetwork: null
203+
media: TV
157204
oneOf:
158205
- $ref: "#/$defs/nullable_relation"
159206
- type: array
@@ -297,6 +344,8 @@ paths:
297344
- anilist
298345
- anidb
299346
- anime-planet
347+
- animecountdown
348+
- animenewsnetwork
300349
- anisearch
301350
- kitsu
302351
- livechart
@@ -394,6 +443,18 @@ paths:
394443
- type: integer
395444
minimum: 0
396445
maximum: 50000000
446+
animenewsnetwork:
447+
oneOf:
448+
- type: "null"
449+
- type: string
450+
minLength: 1
451+
maxLength: 50
452+
animecountdown:
453+
oneOf:
454+
- type: "null"
455+
- type: integer
456+
minimum: 0
457+
maximum: 50000000
397458
- type: array
398459
minItems: 1
399460
maxItems: 100
@@ -444,6 +505,18 @@ paths:
444505
- type: integer
445506
minimum: 0
446507
maximum: 50000000
508+
animenewsnetwork:
509+
oneOf:
510+
- type: "null"
511+
- type: integer
512+
minimum: 0
513+
maximum: 50000000
514+
animecountdown:
515+
oneOf:
516+
- type: "null"
517+
- type: integer
518+
minimum: 0
519+
maximum: 50000000
447520

448521
responses:
449522
"200":

src/db/db.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,26 @@ export const Source = {
1515
IMDB: "imdb",
1616
Kitsu: "kitsu",
1717
LiveChart: "livechart",
18+
AnimeNewsNetwork: "animenewsnetwork",
1819
TheMovieDB: "themoviedb",
20+
TheMovieDBSeason: "themoviedb-season",
1921
TheTVDB: "thetvdb",
22+
TheTVDBSeason: "thetvdb-season",
2023
MAL: "myanimelist",
24+
Simkl: "simkl",
25+
AnimeCountdown: "animecountdown",
26+
MediaType: "media",
2127
} as const
2228
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+
]
2338

2439
export type Relation = {
2540
[Source.AniDB]?: number
@@ -29,9 +44,15 @@ export type Relation = {
2944
[Source.IMDB]?: `tt${string}`
3045
[Source.Kitsu]?: number
3146
[Source.LiveChart]?: number
47+
[Source.AnimeNewsNetwork]?: number
3248
[Source.TheMovieDB]?: number
3349
[Source.TheTVDB]?: number
3450
[Source.MAL]?: number
51+
[Source.TheTVDBSeason]?: number
52+
[Source.TheMovieDBSeason]?: number
53+
[Source.Simkl]?: number
54+
[Source.AnimeCountdown]?: number
55+
[Source.MediaType]?: string
3556
}
3657

3758
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: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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("notify-moe", "text", (col) => col.unique())
24+
.addColumn("themoviedb", "integer")
25+
.addColumn("thetvdb", "integer")
26+
27+
// New Columns
28+
.addColumn("themoviedb-season", "integer")
29+
.addColumn("thetvdb-season", "integer")
30+
.addColumn("animenewsnetwork", "integer", (col) => col.unique())
31+
.addColumn("animecountdown", "integer", (col) => col.unique())
32+
.addColumn("simkl", "integer")
33+
.addColumn("media", "text")
34+
.execute()
35+
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@ const createRelations = async <N extends number>(
1616
imdb: `tt${id++}`,
1717
kitsu: id++,
1818
livechart: id++,
19+
animenewsnetwork: id++,
1920
themoviedb: id++,
21+
"themoviedb-season": id++,
2022
thetvdb: id++,
23+
"thetvdb-season": id++,
2124
myanimelist: id++,
25+
simkl: id++,
26+
animecountdown: id++,
27+
media: `${id++}`,
2228
}))
2329

2430
// Insert each relation
@@ -79,9 +85,15 @@ describe("query params", () => {
7985
imdb: null!,
8086
kitsu: null!,
8187
livechart: null!,
88+
animenewsnetwork: null!,
8289
themoviedb: null!,
90+
"themoviedb-season": null!,
8391
thetvdb: null!,
92+
"thetvdb-season": null!,
8493
myanimelist: null!,
94+
simkl: null!,
95+
animecountdown: null!,
96+
media: null!,
8597
}
8698
await db.insertInto("relations").values(relation).execute()
8799

@@ -163,9 +175,15 @@ describe("json body", () => {
163175
imdb: null!,
164176
kitsu: null!,
165177
livechart: null!,
178+
animenewsnetwork: null!,
166179
themoviedb: null!,
180+
"themoviedb-season": null!,
167181
thetvdb: null!,
182+
"thetvdb-season": null!,
168183
myanimelist: null!,
184+
simkl: null!,
185+
animecountdown: null!,
186+
media: null!,
169187
}
170188
await db.insertInto("relations").values(relation).execute()
171189

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ 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",

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ const okCases = [
2222
anisearch: 1337,
2323
kitsu: 1337,
2424
livechart: 1337,
25+
animenewsnetwork: 1337,
2526
myanimelist: 1337,
27+
animecountdown: 1337,
2628
},
2729
true,
2830
],
@@ -46,6 +48,7 @@ const badCases = [
4648
[{ imdb: 1337 }, false],
4749
[{ themoviedb: 1337 }, false],
4850
[{ thetvdb: 1337 }, false],
51+
[{ simkl: 1337 }, false],
4952
] satisfies Cases
5053

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

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ 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,

src/routes/v2/include.test-utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,15 @@ export const testIncludeQueryParam = (
7474
imdb: null,
7575
kitsu: null,
7676
livechart: null,
77+
animenewsnetwork: null,
7778
themoviedb: null,
79+
"themoviedb-season": null,
7880
thetvdb: null,
81+
"thetvdb-season": null,
7982
myanimelist: null,
83+
simkl: null,
84+
animecountdown: null,
85+
media: null,
8086
}
8187
expectedResult[source] = prefixify(source, 1337) as never
8288

src/routes/v2/include.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const includeSchema = v.object({
88
v.string(),
99
v.regex(/^[\-a-z,]+$/, "Invalid `include` query"),
1010
v.minLength(1),
11-
v.maxLength(100),
11+
v.maxLength(200),
1212
),
1313
),
1414
})

0 commit comments

Comments
 (0)