Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 70 additions & 19 deletions docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,34 +115,69 @@ $defs:
minimum: 0
maximum: 50000000
example: 1337
notify-moe:
animenewsnetwork:
oneOf:
- type: 'null'
- type: string
minLength: 1
maxLength: 50
example: "-cQb5Fmmg"
- type: integer
minimum: 0
maximum: 50000000
example: 1337
themoviedb:
oneOf:
- type: 'null'
- type: integer
minimum: 0
maximum: 50000000
example: 1337
themoviedb-season:
oneOf:
- type: 'null'
- type: integer
minimum: 0
maximum: 50000000
example: 1
thetvdb:
oneOf:
- type: 'null'
- type: integer
minimum: 0
maximum: 50000000
example: 1337
thetvdb-season:
oneOf:
- type: 'null'
- type: integer
minimum: 0
maximum: 50000000
example: 1
myanimelist:
oneOf:
- type: 'null'
- type: integer
minimum: 0
maximum: 50000000
example: 1337
simkl:
oneOf:
- type: 'null'
- type: integer
minimum: 0
maximum: 50000000
example: 1337
animecountdown:
oneOf:
- type: 'null'
- type: integer
minimum: 0
maximum: 50000000
example: 1337
media:
oneOf:
- type: 'null'
- type: string
minLength: 0
maxLength: 10
example: TV

nullable_relation:
oneOf:
Expand All @@ -153,15 +188,19 @@ $defs:
example:
anidb: 1337
anilist: 1337
anime-planet: spriggan
anime-planet: dororon-enma-kun
anisearch: null
imdb: tt0164917
kitsu: null
livechart: null
notify-moe: "-cQb5Fmmg"
themoviedb: null
themoviedb-season: 1
thetvdb: null
thetvdb-season: 1
myanimelist: null
animecountdown: null
animenewsnetwork: null
media: TV
oneOf:
- $ref: '#/$defs/nullable_relation'
- type: array
Expand Down Expand Up @@ -305,10 +344,11 @@ paths:
- anilist
- anidb
- anime-planet
- animecountdown
- animenewsnetwork
- anisearch
- kitsu
- livechart
- notify-moe
- myanimelist
- name: id
in: query
Expand Down Expand Up @@ -356,7 +396,6 @@ paths:
example:
- anilist: 1337
- anidb: 1337
- notify-moe: -cQb5Fmmg
oneOf:
- type: object
minProperties: 1
Expand Down Expand Up @@ -398,13 +437,19 @@ paths:
- type: integer
minimum: 0
maximum: 50000000
notify-moe:
myanimelist:
oneOf:
- type: 'null'
- type: string
minLength: 1
maxLength: 50
myanimelist:
- type: integer
minimum: 0
maximum: 50000000
animenewsnetwork:
oneOf:
- type: 'null'
- type: integer
minimum: 0
maximum: 50000000
animecountdown:
oneOf:
- type: 'null'
- type: integer
Expand Down Expand Up @@ -454,13 +499,19 @@ paths:
- type: integer
minimum: 0
maximum: 50000000
notify-moe:
myanimelist:
oneOf:
- type: 'null'
- type: string
minLength: 1
maxLength: 50
myanimelist:
- type: integer
minimum: 0
maximum: 50000000
animenewsnetwork:
oneOf:
- type: 'null'
- type: integer
minimum: 0
maximum: 50000000
animecountdown:
oneOf:
- type: 'null'
- type: integer
Expand Down
23 changes: 21 additions & 2 deletions src/db/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,26 @@ export const Source = {
IMDB: "imdb",
Kitsu: "kitsu",
LiveChart: "livechart",
NotifyMoe: "notify-moe",
AnimeNewsNetwork: "animenewsnetwork",
TheMovieDB: "themoviedb",
TheMovieDBSeason: "themoviedb-season",
TheTVDB: "thetvdb",
TheTVDBSeason: "thetvdb-season",
MAL: "myanimelist",
Simkl: "simkl",
AnimeCountdown: "animecountdown",
MediaType: "media",
} as const
export type SourceValue = (typeof Source)[keyof typeof Source]
export const NonUniqueFields = [
Source.IMDB,
Source.TheMovieDB,
Source.TheMovieDBSeason,
Source.TheTVDB,
Source.TheTVDBSeason,
Source.Simkl,
Source.MediaType,
]

export type Relation = {
[Source.AniDB]?: number
Expand All @@ -30,10 +44,15 @@ export type Relation = {
[Source.IMDB]?: `tt${string}`
[Source.Kitsu]?: number
[Source.LiveChart]?: number
[Source.NotifyMoe]?: string
[Source.AnimeNewsNetwork]?: number
[Source.TheMovieDB]?: number
[Source.TheTVDB]?: number
[Source.MAL]?: number
[Source.TheTVDBSeason]?: number
[Source.TheMovieDBSeason]?: number
[Source.Simkl]?: number
[Source.AnimeCountdown]?: number
[Source.MediaType]?: string
}

export type OldRelation = Pick<Relation, "anidb" | "anilist" | "myanimelist" | "kitsu">
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { serve } from "h3"

import { createApp } from "./app.ts"
import { config } from "./config.ts"
import { config, Environment } from "./config.ts"
import { migrator } from "./db/db.ts"
import { updateRelations } from "./update.ts"

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

const runUpdateScript = async () => updateRelations()

if (NODE_ENV === "production") {
if (NODE_ENV === Environment.Prod) {
void runUpdateScript()

// eslint-disable-next-line ts/no-misused-promises
Expand Down
34 changes: 34 additions & 0 deletions src/migrations/20260124120530_schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { type Kysely, sql } from "kysely"

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

await db.schema.dropTable("relations").ifExists().execute()

await db.schema
.createTable("relations")
.ifNotExists()

// Original columns
.addColumn("anidb", "integer", (col) => col.unique())
.addColumn("anilist", "integer", (col) => col.unique())
.addColumn("myanimelist", "integer", (col) => col.unique())
.addColumn("kitsu", "integer", (col) => col.unique())

// v2 columns
.addColumn("anime-planet", "text", (col) => col.unique())
.addColumn("anisearch", "integer", (col) => col.unique())
.addColumn("imdb", "text")
.addColumn("livechart", "integer", (col) => col.unique())
.addColumn("themoviedb", "integer")
.addColumn("thetvdb", "integer")

// New Columns
.addColumn("themoviedb-season", "integer")
.addColumn("thetvdb-season", "integer")
.addColumn("animenewsnetwork", "integer", (col) => col.unique())
.addColumn("animecountdown", "integer", (col) => col.unique())
.addColumn("simkl", "integer")
.addColumn("media", "text")
.execute()
}
21 changes: 18 additions & 3 deletions src/routes/v2/ids/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ const createRelations = async <N extends number>(
imdb: `tt${id++}`,
kitsu: id++,
livechart: id++,
"notify-moe": `${id++}`,
animenewsnetwork: id++,
themoviedb: id++,
"themoviedb-season": id++,
thetvdb: id++,
"thetvdb-season": id++,
myanimelist: id++,
simkl: id++,
animecountdown: id++,
media: `${id++}`,
}))

// Insert each relation
Expand Down Expand Up @@ -80,10 +85,15 @@ describe("query params", () => {
imdb: null!,
kitsu: null!,
livechart: null!,
"notify-moe": null!,
animenewsnetwork: null!,
themoviedb: null!,
"themoviedb-season": null!,
thetvdb: null!,
"thetvdb-season": null!,
myanimelist: null!,
simkl: null!,
animecountdown: null!,
media: null!,
}
await db.insertInto("relations").values(relation).execute()

Expand Down Expand Up @@ -165,10 +175,15 @@ describe("json body", () => {
imdb: null!,
kitsu: null!,
livechart: null!,
"notify-moe": null!,
animenewsnetwork: null!,
themoviedb: null!,
"themoviedb-season": null!,
thetvdb: null!,
"thetvdb-season": null!,
myanimelist: null!,
simkl: null!,
animecountdown: null!,
media: null!,
}
await db.insertInto("relations").values(relation).execute()

Expand Down
4 changes: 3 additions & 1 deletion src/routes/v2/ids/schemas/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import * as v from "valibot"
export const numberIdSourceSchema = v.picklist([
"anilist",
"anidb",
"animecountdown",
"animenewsnetwork",
"anisearch",
"kitsu",
"livechart",
"myanimelist",
])

export const stringIdSourceSchema = v.picklist(["anime-planet", "notify-moe"])
export const stringIdSourceSchema = v.picklist(["anime-planet"])
4 changes: 3 additions & 1 deletion src/routes/v2/ids/schemas/json-body.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ const okCases = [
anisearch: 1337,
kitsu: 1337,
livechart: 1337,
"notify-moe": "1337",
animenewsnetwork: 1337,
myanimelist: 1337,
animecountdown: 1337,
},
true,
],
Expand All @@ -47,6 +48,7 @@ const badCases = [
[{ imdb: 1337 }, false],
[{ themoviedb: 1337 }, false],
[{ thetvdb: 1337 }, false],
[{ simkl: 1337 }, false],
] satisfies Cases

const mapToSingularArrayInput = (cases: Cases): Cases =>
Expand Down
3 changes: 2 additions & 1 deletion src/routes/v2/ids/schemas/json-body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ export const singularItemInputSchema = v.pipe(
anidb: numberIdSchema,
anilist: numberIdSchema,
"anime-planet": stringIdSchema,
animecountdown: numberIdSchema,
animenewsnetwork: numberIdSchema,
anisearch: numberIdSchema,
kitsu: numberIdSchema,
livechart: numberIdSchema,
"notify-moe": stringIdSchema,
myanimelist: numberIdSchema,
}),
),
Expand Down
7 changes: 6 additions & 1 deletion src/routes/v2/include.test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,15 @@ export const testIncludeQueryParam = (
imdb: null,
kitsu: null,
livechart: null,
"notify-moe": null,
animenewsnetwork: null,
themoviedb: null,
"themoviedb-season": null,
thetvdb: null,
"thetvdb-season": null,
myanimelist: null,
simkl: null,
animecountdown: null,
media: null,
}
expectedResult[source] = prefixify(source, 1337) as never

Expand Down
2 changes: 1 addition & 1 deletion src/routes/v2/include.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const includeSchema = v.object({
v.string(),
v.regex(/^[\-a-z,]+$/, "Invalid `include` query"),
v.minLength(1),
v.maxLength(100),
v.maxLength(200),
),
),
})
Expand Down
Loading