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
169 changes: 164 additions & 5 deletions docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ $defs:
minLength: 1
maxLength: 50
example: dororon-enma-kun
animecountdown:
oneOf:
- type: "null"
- type: integer
minimum: 0
maximum: 50000000
example: 1337
animenewsnetwork:
oneOf:
- type: "null"
- type: integer
minimum: 0
maximum: 50000000
example: 1337
anisearch:
oneOf:
- type: "null"
Expand Down Expand Up @@ -115,27 +129,55 @@ $defs:
minimum: 0
maximum: 50000000
example: 1337
media:
oneOf:
- type: "null"
- type: string
minLength: 0
maxLength: 10
example: TV
myanimelist:
oneOf:
- type: "null"
- type: integer
minimum: 0
maximum: 50000000
example: 1337
simkl:
oneOf:
- type: "null"
- 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
myanimelist:
thetvdb-season:
oneOf:
- type: "null"
- type: integer
minimum: 0
maximum: 50000000
example: 1337
example: 1

nullable_relation:
oneOf:
Expand All @@ -146,14 +188,19 @@ $defs:
example:
anidb: 1337
anilist: 1337
anime-planet: spriggan
anime-planet: dororon-enma-kun
animecountdown: null
animenewsnetwork: null
anisearch: null
imdb: tt0164917
kitsu: null
livechart: null
media: TV
myanimelist: null
themoviedb-season: 1
themoviedb: null
thetvdb-season: 1
thetvdb: null
myanimelist: null
oneOf:
- $ref: "#/$defs/nullable_relation"
- type: array
Expand Down Expand Up @@ -294,9 +341,11 @@ paths:
schema:
type: string
enum:
- anilist
- anidb
- anilist
- anime-planet
- animecountdown
- animenewsnetwork
- anisearch
- kitsu
- livechart
Expand Down Expand Up @@ -370,12 +419,31 @@ paths:
- type: string
minLength: 1
maxLength: 50
animecountdown:
oneOf:
- type: "null"
- type: integer
minimum: 0
maximum: 50000000
animenewsnetwork:
oneOf:
- type: "null"
- type: integer
minimum: 0
maximum: 50000000
anisearch:
oneOf:
- type: "null"
- type: integer
minimum: 0
maximum: 50000000
imdb:
oneOf:
- type: "null"
- type: string
pattern: tt\d+
minLength: 1
maxLength: 50
kitsu:
oneOf:
- type: "null"
Expand All @@ -388,12 +456,48 @@ paths:
- type: integer
minimum: 0
maximum: 50000000
media:
oneOf:
- type: "null"
- type: string
minLength: 0
maxLength: 10
myanimelist:
oneOf:
- type: "null"
- type: integer
minimum: 0
maximum: 50000000
simkl:
oneOf:
- type: "null"
- type: integer
minimum: 0
maximum: 50000000
themoviedb:
oneOf:
- type: "null"
- type: integer
minimum: 0
maximum: 50000000
themoviedb-season:
oneOf:
- type: "null"
- type: integer
minimum: 0
maximum: 50000000
thetvdb:
oneOf:
- type: "null"
- type: integer
minimum: 0
maximum: 50000000
thetvdb-season:
oneOf:
- type: "null"
- type: integer
minimum: 0
maximum: 50000000
- type: array
minItems: 1
maxItems: 100
Expand All @@ -420,12 +524,31 @@ paths:
- type: string
minLength: 1
maxLength: 50
animecountdown:
oneOf:
- type: "null"
- type: integer
minimum: 0
maximum: 50000000
animenewsnetwork:
oneOf:
- type: "null"
- type: integer
minimum: 0
maximum: 50000000
anisearch:
oneOf:
- type: "null"
- type: integer
minimum: 0
maximum: 50000000
imdb:
oneOf:
- type: "null"
- type: string
pattern: tt\d+
minLength: 1
maxLength: 50
kitsu:
oneOf:
- type: "null"
Expand All @@ -438,12 +561,48 @@ paths:
- type: integer
minimum: 0
maximum: 50000000
media:
oneOf:
- type: "null"
- type: string
minLength: 0
maxLength: 10
myanimelist:
oneOf:
- type: "null"
- type: integer
minimum: 0
maximum: 50000000
simkl:
oneOf:
- type: "null"
- type: integer
minimum: 0
maximum: 50000000
themoviedb:
oneOf:
- type: "null"
- type: integer
minimum: 0
maximum: 50000000
themoviedb-season:
oneOf:
- type: "null"
- type: integer
minimum: 0
maximum: 50000000
thetvdb:
oneOf:
- type: "null"
- type: integer
minimum: 0
maximum: 50000000
thetvdb-season:
oneOf:
- type: "null"
- type: integer
minimum: 0
maximum: 50000000

responses:
"200":
Expand Down
29 changes: 23 additions & 6 deletions src/db/db.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mkdirSync } from "node:fs"
import { existsSync } from "node:fs"

import { createDatabase } from "db0"
import sqlite from "db0/connectors/node-sqlite"
Expand All @@ -10,16 +10,30 @@ import { ActuallyWorkingMigrationProvider } from "./file-provider.ts"
export const Source = {
AniDB: "anidb",
AniList: "anilist",
AnimeCountdown: "animecountdown",
AnimeNewsNetwork: "animenewsnetwork",
AnimePlanet: "anime-planet",
AniSearch: "anisearch",
IMDB: "imdb",
Kitsu: "kitsu",
LiveChart: "livechart",
MAL: "myanimelist",
MediaType: "media",
Simkl: "simkl",
TheMovieDB: "themoviedb",
TheMovieDBSeason: "themoviedb-season",
TheTVDB: "thetvdb",
MAL: "myanimelist",
TheTVDBSeason: "thetvdb-season",
} as const
export type SourceValue = (typeof Source)[keyof typeof Source]
export const NonUniqueFields = [
Source.IMDB,
Source.MediaType,
Source.TheMovieDB,
Source.TheMovieDBSeason,
Source.TheTVDB,
Source.TheTVDBSeason,
] as (keyof Relation)[]

export type Relation = {
[Source.AniDB]?: number
Expand All @@ -29,9 +43,15 @@ export type Relation = {
[Source.IMDB]?: `tt${string}`
[Source.Kitsu]?: number
[Source.LiveChart]?: number
[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 All @@ -41,9 +61,6 @@ export interface Database {
relations: Relation
}

// Ensure SQLite directory exists
mkdirSync("./dir", { recursive: true })

const sqliteDb = sqlite(
process.env.VITEST_POOL_ID == null
? { path: `./db/${process.env.NODE_ENV ?? "development"}.sqlite3` }
Expand All @@ -58,6 +75,6 @@ export const db = new Kysely<Database>({
export const migrator = new Migrator({
db,
provider: new ActuallyWorkingMigrationProvider(
process.env.NODE_ENV !== "test" ? "dist/migrations" : "src/migrations",
existsSync("src/migrations") ? "src/migrations" : "dist/migrations",
),
})
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) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im not sure about this, it might be better to just remove the Environment constant altogether in another pr/commit

void runUpdateScript()

// eslint-disable-next-line ts/no-misused-promises
Expand Down
2 changes: 1 addition & 1 deletion src/migrations/20190611171759_initial.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type Kysely, sql } from "kysely"

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

await db.schema
Expand Down
12 changes: 12 additions & 0 deletions src/migrations/20260124120530_schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { Kysely } from "kysely"

export async function up(db: Kysely<unknown>): Promise<void> {
await db.schema.alterTable("relations").addColumn("themoviedb-season", "integer").execute()
await db.schema.alterTable("relations").addColumn("thetvdb-season", "integer").execute()
// unique, but sqlite can't add unique columns to tables
await db.schema.alterTable("relations").addColumn("animenewsnetwork", "integer").execute()
// unique, but sqlite can't add unique columns to tables
await db.schema.alterTable("relations").addColumn("animecountdown", "integer").execute()
await db.schema.alterTable("relations").addColumn("simkl", "integer").execute()
await db.schema.alterTable("relations").addColumn("media", "text").execute()
}
Loading