diff --git a/api/src/controllers/seed/images.ts b/api/src/controllers/seed/images.ts index bbb595f8..12f0d016 100644 --- a/api/src/controllers/seed/images.ts +++ b/api/src/controllers/seed/images.ts @@ -1,6 +1,9 @@ import type { Image } from "~/models/utils"; -export const processImage = async (url: string): Promise => { +// this will only push a task to the image downloader service and not download it instantly. +// this is both done to prevent to many requests to be sent at once and to make sure POST +// requests are not blocked by image downloading or blurhash calculation +export const processImage = (url: string): Image => { const hasher = new Bun.CryptoHasher("sha256"); hasher.update(url); @@ -13,7 +16,7 @@ export const processImage = async (url: string): Promise => { }; }; -export const processOptImage = (url: string | null): Promise => { - if (!url) return Promise.resolve(null); +export const processOptImage = (url: string | null): Image | null => { + if (!url) return null; return processImage(url); }; diff --git a/api/src/controllers/seed/insert/shows.ts b/api/src/controllers/seed/insert/shows.ts index eb895d7e..8986e33e 100644 --- a/api/src/controllers/seed/insert/shows.ts +++ b/api/src/controllers/seed/insert/shows.ts @@ -3,6 +3,7 @@ import { db } from "~/db"; import { showTranslations, shows } from "~/db/schema"; import { conflictUpdateAllExcept } from "~/db/utils"; import type { SeedMovie } from "~/models/movie"; +import type { SeedSerie } from "~/models/serie"; import { getYear } from "~/utils"; import { processOptImage } from "../images"; @@ -11,22 +12,22 @@ type ShowTrans = typeof showTranslations.$inferInsert; export const insertShow = async ( show: Show, - translations: SeedMovie["translations"], + translations: SeedMovie["translations"] | SeedSerie["translations"], ) => { return await db.transaction(async (tx) => { const ret = await insertBaseShow(tx, show); if ("status" in ret) return ret; - const trans: ShowTrans[] = await Promise.all( - Object.entries(translations).map(async ([lang, tr]) => ({ + const trans: ShowTrans[] = Object.entries(translations).map( + ([lang, tr]) => ({ pk: ret.pk, language: lang, ...tr, - poster: await processOptImage(tr.poster), - thumbnail: await processOptImage(tr.thumbnail), - logo: await processOptImage(tr.logo), - banner: await processOptImage(tr.banner), - })), + poster: processOptImage(tr.poster), + thumbnail: processOptImage(tr.thumbnail), + logo: processOptImage(tr.logo), + banner: processOptImage(tr.banner), + }), ); await tx .insert(showTranslations) diff --git a/api/src/controllers/seed/movies.ts b/api/src/controllers/seed/movies.ts index 14ef30e2..32e7f700 100644 --- a/api/src/controllers/seed/movies.ts +++ b/api/src/controllers/seed/movies.ts @@ -43,7 +43,7 @@ export const seedMovie = async ( const { translations, videos: vids, ...bMovie } = seed; const nextRefresh = guessNextRefresh(bMovie.airDate ?? new Date()); - const ret = await insertShow( + const show = await insertShow( { kind: "movie", startAir: bMovie.airDate, @@ -52,12 +52,13 @@ export const seedMovie = async ( }, translations, ); - if ("status" in ret) return ret; + if ("status" in show) return show; // even if never shown to the user, a movie still has an entry. - const [entry] = await insertEntries(ret.pk, [ + const [entry] = await insertEntries(show, [ { kind: "movie", + order: 1, nextRefresh, ...bMovie, }, @@ -70,12 +71,12 @@ export const seedMovie = async ( .select( db .select({ - entry: sql`${ret.entry}`.as("entry"), + entry: sql`${show.entry}`.as("entry"), video: videos.pk, // TODO: do not add rendering if all videos of the entry have the same rendering slug: sql` concat( - ${ret.slug}::text, + ${show.slug}::text, case when ${videos.part} <> null then concat('-p', ${videos.part}) else '' end, case when ${videos.version} <> 1 then concat('-v', ${videos.version}) else '' end ) @@ -90,9 +91,9 @@ export const seedMovie = async ( } return { - updated: ret.updated, - id: ret.id, - slug: ret.slug, + updated: show.updated, + id: show.id, + slug: show.slug, videos: retVideos, }; }; diff --git a/api/src/controllers/seed/series.ts b/api/src/controllers/seed/series.ts index 948889e6..bd421493 100644 --- a/api/src/controllers/seed/series.ts +++ b/api/src/controllers/seed/series.ts @@ -1,13 +1,19 @@ import { t } from "elysia"; import type { SeedSerie } from "~/models/serie"; import { getYear } from "~/utils"; +import { insertEntries } from "./insert/entries"; import { insertShow } from "./insert/shows"; import { guessNextRefresh } from "./refresh"; -import { insertEntries } from "./insert/entries"; export const SeedSerieResponse = t.Object({ id: t.String({ format: "uuid" }), - slug: t.String({ format: "slug", examples: ["bubble"] }), + slug: t.String({ format: "slug", examples: ["made-in-abyss"] }), + entries: t.Array( + t.Object({ + id: t.String({ format: "uuid" }), + slug: t.String({ format: "slug", examples: ["made-in-abyss-s1e1"] }), + }), + ), }); export type SeedSerieResponse = typeof SeedSerieResponse.static; @@ -31,7 +37,7 @@ export const seedSerie = async ( const { translations, seasons, entries, ...serie } = seed; const nextRefresh = guessNextRefresh(serie.startAir ?? new Date()); - const ret = await insertShow( + const show = await insertShow( { kind: "serie", nextRefresh, @@ -39,13 +45,14 @@ export const seedSerie = async ( }, translations, ); - if ("status" in ret) return ret; + if ("status" in show) return show; - const retEntries = await insertEntries(ret.pk, entries); + const retEntries = await insertEntries(show, entries); return { - updated: ret.updated, - id: ret.id, - slug: ret.slug, + updated: show.updated, + id: show.id, + slug: show.slug, + entries: retEntries, }; }; diff --git a/biome.json b/biome.json index d8b12b95..84dde2d8 100644 --- a/biome.json +++ b/biome.json @@ -2,7 +2,6 @@ "$schema": "https://biomejs.dev/schemas/1.8.1/schema.json", "formatter": { "enabled": true, - "formatWithErrors": false, "indentStyle": "tab", "indentWidth": 2, "lineEnding": "lf",