diff --git a/api/src/controllers/seed/insert/entries.ts b/api/src/controllers/seed/insert/entries.ts index a3100cbf..a17e41b6 100644 --- a/api/src/controllers/seed/insert/entries.ts +++ b/api/src/controllers/seed/insert/entries.ts @@ -121,6 +121,7 @@ export const insertEntries = async ( return { videoId: seed.video, entryPk: retEntries[i].pk, + entrySlug: retEntries[i].slug, needRendering: false, }; } @@ -128,6 +129,7 @@ export const insertEntries = async ( return seed.videos.map((x, j) => ({ videoId: x, entryPk: retEntries[i].pk, + entrySlug: retEntries[i].slug, // The first video should not have a rendering. needRendering: j && seed.videos!.length > 1, })); @@ -142,9 +144,9 @@ export const insertEntries = async ( db .select({ entryPk: sql`vids.entryPk::integer`.as("entry"), - videoPk: sql`${videos.pk}`.as("video"), + videoPk: videos.pk, slug: computeVideoSlug( - sql`${show.slug}::text`, + sql`vids.entrySlug::text`, sql`vids.needRendering::boolean`, ), }) diff --git a/api/src/controllers/seed/insert/studios.ts b/api/src/controllers/seed/insert/studios.ts index 291801d7..f53f93a2 100644 --- a/api/src/controllers/seed/insert/studios.ts +++ b/api/src/controllers/seed/insert/studios.ts @@ -7,8 +7,11 @@ import { processOptImage } from "../images"; type StudioI = typeof studios.$inferInsert; type StudioTransI = typeof studioTranslations.$inferInsert; -export const insertStudios = async (seed: SeedStudio[], showPk: number) => { - if (!seed.length) return []; +export const insertStudios = async ( + seed: SeedStudio[] | undefined, + showPk: number, +) => { + if (!seed?.length) return []; return await db.transaction(async (tx) => { const vals: StudioI[] = seed.map((x) => { diff --git a/api/src/models/entry/episode.ts b/api/src/models/entry/episode.ts index 3c87b28e..8b07b74c 100644 --- a/api/src/models/entry/episode.ts +++ b/api/src/models/entry/episode.ts @@ -8,6 +8,7 @@ import { SeedImage, TranslationRecord, } from "../utils"; +import { Video } from "../video"; import { BaseEntry, EntryTranslation } from "./base-entry"; export const BaseEpisode = t.Intersect([ @@ -25,6 +26,9 @@ export const Episode = t.Intersect([ Resource(), EntryTranslation(), BaseEpisode, + t.Object({ + videos: t.Optional(t.Array(Video)), + }), DbMetadata, ]); export type Episode = Prettify; @@ -34,7 +38,7 @@ export const SeedEpisode = t.Intersect([ t.Object({ thumbnail: t.Nullable(SeedImage), translations: TranslationRecord(EntryTranslation()), - videos: t.Optional(t.Array(t.String({ format: "uuid" }))), + videos: t.Optional(t.Array(t.String({ format: "uuid" }), { default: [] })), }), ]); export type SeedEpisode = Prettify; @@ -45,4 +49,5 @@ registerExamples(Episode, { ...ep.translations.en, ...bubbleImages, slug: `${madeInAbyss.slug}-s${ep.seasonNumber}-e${ep.episodeNumber}`, + videos: [], }); diff --git a/api/src/models/entry/extra.ts b/api/src/models/entry/extra.ts index 1d033753..5f1d1007 100644 --- a/api/src/models/entry/extra.ts +++ b/api/src/models/entry/extra.ts @@ -3,6 +3,7 @@ import { type Prettify, comment } from "~/utils"; import { madeInAbyss, registerExamples } from "../examples"; import { DbMetadata, SeedImage } from "../utils"; import { Resource } from "../utils/resource"; +import { Video } from "../video"; import { BaseEntry } from "./base-entry"; export const ExtraType = t.UnionEnum([ @@ -31,7 +32,14 @@ export const BaseExtra = t.Intersect( }, ); -export const Extra = t.Intersect([Resource(), BaseExtra, DbMetadata]); +export const Extra = t.Intersect([ + Resource(), + BaseExtra, + t.Object({ + video: t.Optional(Video), + }), + DbMetadata, +]); export type Extra = Prettify; export const SeedExtra = t.Intersect([ @@ -44,4 +52,4 @@ export const SeedExtra = t.Intersect([ ]); export type SeedExtra = Prettify; -registerExamples(Extra, madeInAbyss.extras[0]); +registerExamples(Extra, { ...madeInAbyss.extras[0], video: undefined }); diff --git a/api/src/models/entry/movie-entry.ts b/api/src/models/entry/movie-entry.ts index 95fcc501..77447d91 100644 --- a/api/src/models/entry/movie-entry.ts +++ b/api/src/models/entry/movie-entry.ts @@ -9,6 +9,7 @@ import { SeedImage, TranslationRecord, } from "../utils"; +import { Video } from "../video"; import { BaseEntry, EntryTranslation } from "./base-entry"; export const BaseMovieEntry = t.Intersect( @@ -43,6 +44,9 @@ export const MovieEntry = t.Intersect([ Resource(), MovieEntryTranslation, BaseMovieEntry, + t.Object({ + videos: t.Optional(t.Array(Video)), + }), DbMetadata, ]); export type MovieEntry = Prettify; @@ -58,7 +62,7 @@ export const SeedMovieEntry = t.Intersect([ t.Object({ poster: t.Nullable(SeedImage) }), ]), ), - videos: t.Optional(t.Array(t.String({ format: "uuid" }))), + videos: t.Optional(t.Array(t.String({ format: "uuid" }), { default: [] })), }), ]); export type SeedMovieEntry = Prettify; diff --git a/api/src/models/entry/special.ts b/api/src/models/entry/special.ts index 248ff9d7..e9fb851f 100644 --- a/api/src/models/entry/special.ts +++ b/api/src/models/entry/special.ts @@ -8,6 +8,7 @@ import { SeedImage, TranslationRecord, } from "../utils"; +import { Video } from "../video"; import { BaseEntry, EntryTranslation } from "./base-entry"; export const BaseSpecial = t.Intersect( @@ -35,6 +36,9 @@ export const Special = t.Intersect([ Resource(), EntryTranslation(), BaseSpecial, + t.Object({ + videos: t.Optional(t.Array(Video)), + }), DbMetadata, ]); export type Special = Prettify; @@ -44,7 +48,7 @@ export const SeedSpecial = t.Intersect([ t.Object({ thumbnail: t.Nullable(SeedImage), translations: TranslationRecord(EntryTranslation()), - videos: t.Optional(t.Array(t.String({ format: "uuid" }))), + videos: t.Optional(t.Array(t.String({ format: "uuid" }), { default: [] })), }), ]); export type SeedSpecial = Prettify; diff --git a/api/src/models/examples/made-in-abyss.ts b/api/src/models/examples/made-in-abyss.ts index 6fd213e1..f6dfb4ca 100644 --- a/api/src/models/examples/made-in-abyss.ts +++ b/api/src/models/examples/made-in-abyss.ts @@ -3,15 +3,15 @@ import type { Video } from "~/models/video"; export const madeInAbyssVideo: Video = { id: "3cd436ee-01ff-4f45-ba98-654282531234", - slug: "made-in-abyss-s1e1", - path: "/video/Made in abyss S01E01.mkv", + slug: "made-in-abyss-s1e13", + path: "/video/Made in abyss S01E13.mkv", rendering: "459429fa062adeebedcc2bb04b9965de0262bfa453369783132d261be79021bd", part: null, version: 1, guess: { title: "Made in abyss", season: [1], - episode: [1], + episode: [13], type: "episode", from: "guessit", }, @@ -156,6 +156,7 @@ export const madeInAbyss = { link: "https://www.themoviedb.org/tv/72636/season/1/episode/13", }, }, + videos: [madeInAbyssVideo.id], }, { kind: "special", @@ -240,7 +241,7 @@ export const madeInAbyss = { name: "The Making of MADE IN ABYSS 01", runtime: 17, thumbnail: null, - video: "3cd436ee-01ff-4f45-ba98-654282531234", + video: madeInAbyssVideo.id, }, ], studios: [ diff --git a/api/src/models/movie.ts b/api/src/models/movie.ts index 4f3f7089..5285d374 100644 --- a/api/src/models/movie.ts +++ b/api/src/models/movie.ts @@ -88,9 +88,9 @@ export const SeedMovie = t.Intersect([ }), ]), ), - videos: t.Optional(t.Array(t.String({ format: "uuid" }))), + videos: t.Optional(t.Array(t.String({ format: "uuid" }), { default: [] })), collection: t.Optional(SeedCollection), - studios: t.Array(SeedStudio), + studios: t.Optional(t.Array(SeedStudio, { default: [] })), }), ]); export type SeedMovie = Prettify; diff --git a/api/src/models/serie.ts b/api/src/models/serie.ts index a20c8795..9be6f76f 100644 --- a/api/src/models/serie.ts +++ b/api/src/models/serie.ts @@ -98,9 +98,9 @@ export const SeedSerie = t.Intersect([ ), seasons: t.Array(SeedSeason), entries: t.Array(SeedEntry), - extras: t.Optional(t.Array(SeedExtra)), + extras: t.Optional(t.Array(SeedExtra, { default: [] })), collection: t.Optional(SeedCollection), - studios: t.Array(SeedStudio), + studios: t.Optional(t.Array(SeedStudio, { default: [] })), }), ]); export type SeedSerie = typeof SeedSerie.static; diff --git a/api/tests/series/get-entries.test.ts b/api/tests/series/get-entries.test.ts index 1078aea8..f22416b9 100644 --- a/api/tests/series/get-entries.test.ts +++ b/api/tests/series/get-entries.test.ts @@ -1,14 +1,15 @@ import { beforeAll, describe, expect, it } from "bun:test"; -import { getEntries, getExtras, getUnknowns } from "tests/helpers"; +import { createSerie, createVideo, getEntries, getExtras } from "tests/helpers"; import { expectStatus } from "tests/utils"; -import { seedSerie } from "~/controllers/seed/series"; -import { madeInAbyss } from "~/models/examples"; - -let miaId = ""; +import { db } from "~/db"; +import { shows, videos } from "~/db/schema"; +import { madeInAbyss, madeInAbyssVideo } from "~/models/examples"; beforeAll(async () => { - const ret = await seedSerie(madeInAbyss); - if (!("status" in ret)) miaId = ret.id; + await db.delete(shows); + await db.delete(videos); + console.log(await createVideo(madeInAbyssVideo)); + await createSerie(madeInAbyss); }); describe("Get entries", () => { @@ -27,6 +28,12 @@ describe("Get entries", () => { expectStatus(resp, body).toBe(200); expect(body.items).toBeArrayOfSize(madeInAbyss.entries.length); }); + it("With videos", async () => { + const [resp, body] = await getEntries(madeInAbyss.slug, { langs: "en" }); + + expectStatus(resp, body).toBe(200); + expect(body.items[0].videos).toBeArrayOfSize(1); + }); }); describe("Get extra", () => { diff --git a/api/tests/series/get-seasons.test.ts b/api/tests/series/get-seasons.test.ts index d49d751f..8aa29284 100644 --- a/api/tests/series/get-seasons.test.ts +++ b/api/tests/series/get-seasons.test.ts @@ -1,14 +1,10 @@ import { beforeAll, describe, expect, it } from "bun:test"; -import { getSeasons } from "tests/helpers"; +import { createSerie, getSeasons } from "tests/helpers"; import { expectStatus } from "tests/utils"; -import { seedSerie } from "~/controllers/seed/series"; import { madeInAbyss } from "~/models/examples"; -let miaId = ""; - beforeAll(async () => { - const ret = await seedSerie(madeInAbyss); - if (!("status" in ret)) miaId = ret.id; + await createSerie(madeInAbyss); }); describe("Get seasons", () => { diff --git a/api/tests/series/seed-serie.test.ts b/api/tests/series/seed-serie.test.ts index 2d5baf56..d6a0111f 100644 --- a/api/tests/series/seed-serie.test.ts +++ b/api/tests/series/seed-serie.test.ts @@ -25,7 +25,12 @@ describe("Serie seeding", () => { where: eq(shows.id, body.id), with: { seasons: { orderBy: seasons.seasonNumber }, - entries: { with: { translations: true } }, + entries: { + with: { + translations: true, + evj: { with: { video: true } }, + }, + }, }, }); @@ -37,7 +42,9 @@ describe("Serie seeding", () => { madeInAbyss.entries.length + madeInAbyss.extras.length, ); - const ep13 = madeInAbyss.entries.find((x) => x.order === 13)!; + const { videos: _, ...ep13 } = madeInAbyss.entries.find( + (x) => x.order === 13, + )!; expect(ret!.entries.find((x) => x.order === 13)).toMatchObject({ ...ep13, slug: "made-in-abyss-s1e13", @@ -48,6 +55,12 @@ describe("Serie seeding", () => { ...ep13.translations.en, }, ], + evj: [ + expect.objectContaining({ + slug: madeInAbyssVideo.slug, + video: expect.objectContaining({ path: madeInAbyssVideo.path }), + }), + ], }); const { number, ...special } = madeInAbyss.entries.find( diff --git a/api/tests/series/studios.test.ts b/api/tests/series/studios.test.ts index a23f9494..9ddd2659 100644 --- a/api/tests/series/studios.test.ts +++ b/api/tests/series/studios.test.ts @@ -1,11 +1,10 @@ import { beforeAll, describe, expect, it } from "bun:test"; -import { getSerie, getShowsByStudio, getStudio } from "tests/helpers"; +import { createSerie, getSerie, getShowsByStudio, getStudio } from "tests/helpers"; import { expectStatus } from "tests/utils"; -import { seedSerie } from "~/controllers/seed/series"; import { madeInAbyss } from "~/models/examples"; beforeAll(async () => { - await seedSerie(madeInAbyss); + await createSerie(madeInAbyss); }); describe("Get by studio", () => {