Skip to content

Commit dcaf183

Browse files
BrutuZbeeequeue
andauthored
New upstream fields (#906)
Co-authored-by: bq <adam@haglund.dev>
1 parent 782dc76 commit dcaf183

14 files changed

Lines changed: 319 additions & 34 deletions

docs/openapi.yaml

Lines changed: 164 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,20 @@ $defs:
8686
minLength: 1
8787
maxLength: 50
8888
example: dororon-enma-kun
89+
animecountdown:
90+
oneOf:
91+
- type: "null"
92+
- type: integer
93+
minimum: 0
94+
maximum: 50000000
95+
example: 1337
96+
animenewsnetwork:
97+
oneOf:
98+
- type: "null"
99+
- type: integer
100+
minimum: 0
101+
maximum: 50000000
102+
example: 1337
89103
anisearch:
90104
oneOf:
91105
- type: "null"
@@ -115,27 +129,55 @@ $defs:
115129
minimum: 0
116130
maximum: 50000000
117131
example: 1337
132+
media:
133+
oneOf:
134+
- type: "null"
135+
- type: string
136+
minLength: 0
137+
maxLength: 10
138+
example: TV
139+
myanimelist:
140+
oneOf:
141+
- type: "null"
142+
- type: integer
143+
minimum: 0
144+
maximum: 50000000
145+
example: 1337
146+
simkl:
147+
oneOf:
148+
- type: "null"
149+
- type: integer
150+
minimum: 0
151+
maximum: 50000000
152+
example: 1337
118153
themoviedb:
119154
oneOf:
120155
- type: "null"
121156
- type: integer
122157
minimum: 0
123158
maximum: 50000000
124159
example: 1337
160+
themoviedb-season:
161+
oneOf:
162+
- type: "null"
163+
- type: integer
164+
minimum: 0
165+
maximum: 50000000
166+
example: 1
125167
thetvdb:
126168
oneOf:
127169
- type: "null"
128170
- type: integer
129171
minimum: 0
130172
maximum: 50000000
131173
example: 1337
132-
myanimelist:
174+
thetvdb-season:
133175
oneOf:
134176
- type: "null"
135177
- type: integer
136178
minimum: 0
137179
maximum: 50000000
138-
example: 1337
180+
example: 1
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
192+
animecountdown: null
193+
animenewsnetwork: null
150194
anisearch: null
151195
imdb: tt0164917
152196
kitsu: null
153197
livechart: null
198+
media: TV
199+
myanimelist: null
200+
themoviedb-season: 1
154201
themoviedb: null
202+
thetvdb-season: 1
155203
thetvdb: null
156-
myanimelist: null
157204
oneOf:
158205
- $ref: "#/$defs/nullable_relation"
159206
- type: array
@@ -294,9 +341,11 @@ paths:
294341
schema:
295342
type: string
296343
enum:
297-
- anilist
298344
- anidb
345+
- anilist
299346
- anime-planet
347+
- animecountdown
348+
- animenewsnetwork
300349
- anisearch
301350
- kitsu
302351
- livechart
@@ -370,12 +419,31 @@ paths:
370419
- type: string
371420
minLength: 1
372421
maxLength: 50
422+
animecountdown:
423+
oneOf:
424+
- type: "null"
425+
- type: integer
426+
minimum: 0
427+
maximum: 50000000
428+
animenewsnetwork:
429+
oneOf:
430+
- type: "null"
431+
- type: integer
432+
minimum: 0
433+
maximum: 50000000
373434
anisearch:
374435
oneOf:
375436
- type: "null"
376437
- type: integer
377438
minimum: 0
378439
maximum: 50000000
440+
imdb:
441+
oneOf:
442+
- type: "null"
443+
- type: string
444+
pattern: tt\d+
445+
minLength: 1
446+
maxLength: 50
379447
kitsu:
380448
oneOf:
381449
- type: "null"
@@ -388,12 +456,48 @@ paths:
388456
- type: integer
389457
minimum: 0
390458
maximum: 50000000
459+
media:
460+
oneOf:
461+
- type: "null"
462+
- type: string
463+
minLength: 0
464+
maxLength: 10
391465
myanimelist:
392466
oneOf:
393467
- type: "null"
394468
- type: integer
395469
minimum: 0
396470
maximum: 50000000
471+
simkl:
472+
oneOf:
473+
- type: "null"
474+
- type: integer
475+
minimum: 0
476+
maximum: 50000000
477+
themoviedb:
478+
oneOf:
479+
- type: "null"
480+
- type: integer
481+
minimum: 0
482+
maximum: 50000000
483+
themoviedb-season:
484+
oneOf:
485+
- type: "null"
486+
- type: integer
487+
minimum: 0
488+
maximum: 50000000
489+
thetvdb:
490+
oneOf:
491+
- type: "null"
492+
- type: integer
493+
minimum: 0
494+
maximum: 50000000
495+
thetvdb-season:
496+
oneOf:
497+
- type: "null"
498+
- type: integer
499+
minimum: 0
500+
maximum: 50000000
397501
- type: array
398502
minItems: 1
399503
maxItems: 100
@@ -420,12 +524,31 @@ paths:
420524
- type: string
421525
minLength: 1
422526
maxLength: 50
527+
animecountdown:
528+
oneOf:
529+
- type: "null"
530+
- type: integer
531+
minimum: 0
532+
maximum: 50000000
533+
animenewsnetwork:
534+
oneOf:
535+
- type: "null"
536+
- type: integer
537+
minimum: 0
538+
maximum: 50000000
423539
anisearch:
424540
oneOf:
425541
- type: "null"
426542
- type: integer
427543
minimum: 0
428544
maximum: 50000000
545+
imdb:
546+
oneOf:
547+
- type: "null"
548+
- type: string
549+
pattern: tt\d+
550+
minLength: 1
551+
maxLength: 50
429552
kitsu:
430553
oneOf:
431554
- type: "null"
@@ -438,12 +561,48 @@ paths:
438561
- type: integer
439562
minimum: 0
440563
maximum: 50000000
564+
media:
565+
oneOf:
566+
- type: "null"
567+
- type: string
568+
minLength: 0
569+
maxLength: 10
441570
myanimelist:
442571
oneOf:
443572
- type: "null"
444573
- type: integer
445574
minimum: 0
446575
maximum: 50000000
576+
simkl:
577+
oneOf:
578+
- type: "null"
579+
- type: integer
580+
minimum: 0
581+
maximum: 50000000
582+
themoviedb:
583+
oneOf:
584+
- type: "null"
585+
- type: integer
586+
minimum: 0
587+
maximum: 50000000
588+
themoviedb-season:
589+
oneOf:
590+
- type: "null"
591+
- type: integer
592+
minimum: 0
593+
maximum: 50000000
594+
thetvdb:
595+
oneOf:
596+
- type: "null"
597+
- type: integer
598+
minimum: 0
599+
maximum: 50000000
600+
thetvdb-season:
601+
oneOf:
602+
- type: "null"
603+
- type: integer
604+
minimum: 0
605+
maximum: 50000000
447606

448607
responses:
449608
"200":

src/db/db.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { mkdirSync } from "node:fs"
1+
import { existsSync } from "node:fs"
22

33
import { createDatabase } from "db0"
44
import sqlite from "db0/connectors/node-sqlite"
@@ -10,16 +10,30 @@ import { ActuallyWorkingMigrationProvider } from "./file-provider.ts"
1010
export const Source = {
1111
AniDB: "anidb",
1212
AniList: "anilist",
13+
AnimeCountdown: "animecountdown",
14+
AnimeNewsNetwork: "animenewsnetwork",
1315
AnimePlanet: "anime-planet",
1416
AniSearch: "anisearch",
1517
IMDB: "imdb",
1618
Kitsu: "kitsu",
1719
LiveChart: "livechart",
20+
MAL: "myanimelist",
21+
MediaType: "media",
22+
Simkl: "simkl",
1823
TheMovieDB: "themoviedb",
24+
TheMovieDBSeason: "themoviedb-season",
1925
TheTVDB: "thetvdb",
20-
MAL: "myanimelist",
26+
TheTVDBSeason: "thetvdb-season",
2127
} as const
2228
export type SourceValue = (typeof Source)[keyof typeof Source]
29+
export const NonUniqueFields = [
30+
Source.IMDB,
31+
Source.MediaType,
32+
Source.TheMovieDB,
33+
Source.TheMovieDBSeason,
34+
Source.TheTVDB,
35+
Source.TheTVDBSeason,
36+
] as (keyof Relation)[]
2337

2438
export type Relation = {
2539
[Source.AniDB]?: number
@@ -29,9 +43,15 @@ export type Relation = {
2943
[Source.IMDB]?: `tt${string}`
3044
[Source.Kitsu]?: number
3145
[Source.LiveChart]?: number
46+
[Source.AnimeNewsNetwork]?: number
3247
[Source.TheMovieDB]?: number
3348
[Source.TheTVDB]?: number
3449
[Source.MAL]?: number
50+
[Source.TheTVDBSeason]?: number
51+
[Source.TheMovieDBSeason]?: number
52+
[Source.Simkl]?: number
53+
[Source.AnimeCountdown]?: number
54+
[Source.MediaType]?: string
3555
}
3656

3757
export type OldRelation = Pick<Relation, "anidb" | "anilist" | "myanimelist" | "kitsu">
@@ -41,9 +61,6 @@ export interface Database {
4161
relations: Relation
4262
}
4363

44-
// Ensure SQLite directory exists
45-
mkdirSync("./dir", { recursive: true })
46-
4764
const sqliteDb = sqlite(
4865
process.env.VITEST_POOL_ID == null
4966
? { path: `./db/${process.env.NODE_ENV ?? "development"}.sqlite3` }
@@ -58,6 +75,6 @@ export const db = new Kysely<Database>({
5875
export const migrator = new Migrator({
5976
db,
6077
provider: new ActuallyWorkingMigrationProvider(
61-
process.env.NODE_ENV !== "test" ? "dist/migrations" : "src/migrations",
78+
existsSync("src/migrations") ? "src/migrations" : "dist/migrations",
6279
),
6380
})

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

src/migrations/20190611171759_initial.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { type Kysely, sql } from "kysely"
22

3-
export async function up(db: Kysely<any>): Promise<void> {
3+
export async function up(db: Kysely<unknown>): Promise<void> {
44
await sql`PRAGMA journal_mode=WAL`.execute(db)
55

66
await db.schema
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { Kysely } from "kysely"
2+
3+
export async function up(db: Kysely<unknown>): Promise<void> {
4+
await db.schema.alterTable("relations").addColumn("themoviedb-season", "integer").execute()
5+
await db.schema.alterTable("relations").addColumn("thetvdb-season", "integer").execute()
6+
// unique, but sqlite can't add unique columns to tables
7+
await db.schema.alterTable("relations").addColumn("animenewsnetwork", "integer").execute()
8+
// unique, but sqlite can't add unique columns to tables
9+
await db.schema.alterTable("relations").addColumn("animecountdown", "integer").execute()
10+
await db.schema.alterTable("relations").addColumn("simkl", "integer").execute()
11+
await db.schema.alterTable("relations").addColumn("media", "text").execute()
12+
}

0 commit comments

Comments
 (0)