diff --git a/api/src/controllers/entries.ts b/api/src/controllers/entries.ts index 9bfb1124..f43b0751 100644 --- a/api/src/controllers/entries.ts +++ b/api/src/controllers/entries.ts @@ -342,6 +342,6 @@ export const entriesH = new Elysia({ tags: ["series"] }) 200: Page(UnknownEntry), 422: KError, }, - tags: [], + tags: ["videos"], }, ); diff --git a/api/src/models/entry/base-entry.ts b/api/src/models/entry/base-entry.ts index f848f6e3..cf44680c 100644 --- a/api/src/models/entry/base-entry.ts +++ b/api/src/models/entry/base-entry.ts @@ -1,18 +1,22 @@ import { t } from "elysia"; import { Image } from "../utils/image"; -export const BaseEntry = t.Object({ - airDate: t.Nullable(t.String({ format: "date" })), - runtime: t.Nullable( - t.Number({ minimum: 0, description: "Runtime of the episode in minutes" }), - ), - thumbnail: t.Nullable(Image), +export const BaseEntry = () => + t.Object({ + airDate: t.Nullable(t.String({ format: "date" })), + runtime: t.Nullable( + t.Number({ + minimum: 0, + description: "Runtime of the episode in minutes", + }), + ), + thumbnail: t.Nullable(Image), - createdAt: t.String({ format: "date-time" }), - nextRefresh: t.String({ format: "date-time" }), -}); + createdAt: t.String({ format: "date-time" }), + nextRefresh: t.String({ format: "date-time" }), + }); -export const EntryTranslation = t.Object({ +export const EntryTranslation = () => t.Object({ name: t.Nullable(t.String()), description: t.Nullable(t.String()), }); diff --git a/api/src/models/entry/episode.ts b/api/src/models/entry/episode.ts index 29d8f5d1..14baf7c2 100644 --- a/api/src/models/entry/episode.ts +++ b/api/src/models/entry/episode.ts @@ -12,17 +12,17 @@ export const BaseEpisode = t.Intersect([ episodeNumber: t.Integer(), externalId: EpisodeId, }), - BaseEntry, + BaseEntry(), ]); -export const Episode = t.Intersect([Resource(), EntryTranslation, BaseEpisode]); +export const Episode = t.Intersect([Resource(), EntryTranslation(), BaseEpisode]); export type Episode = Prettify; export const SeedEpisode = t.Intersect([ t.Omit(BaseEpisode, ["thumbnail", "createdAt", "nextRefresh"]), t.Object({ thumbnail: t.Nullable(SeedImage), - translations: TranslationRecord(EntryTranslation), + translations: TranslationRecord(EntryTranslation()), videos: t.Optional(t.Array(t.String({ format: "uuid" }))), }), ]); diff --git a/api/src/models/entry/extra.ts b/api/src/models/entry/extra.ts index 462955c0..eb702b18 100644 --- a/api/src/models/entry/extra.ts +++ b/api/src/models/entry/extra.ts @@ -21,7 +21,7 @@ export const BaseExtra = t.Intersect( kind: ExtraType, name: t.String(), }), - t.Omit(BaseEntry, ["nextRefresh", "airDate"]), + t.Omit(BaseEntry(), ["nextRefresh", "airDate"]), ], { description: comment` diff --git a/api/src/models/entry/movie-entry.ts b/api/src/models/entry/movie-entry.ts index 75757f42..8773fbf7 100644 --- a/api/src/models/entry/movie-entry.ts +++ b/api/src/models/entry/movie-entry.ts @@ -20,7 +20,7 @@ export const BaseMovieEntry = t.Intersect( }), externalId: ExternalId, }), - BaseEntry, + BaseEntry(), ], { description: comment` @@ -31,7 +31,7 @@ export const BaseMovieEntry = t.Intersect( ); export const MovieEntryTranslation = t.Intersect([ - EntryTranslation, + EntryTranslation(), t.Object({ tagline: t.Nullable(t.String()), poster: t.Nullable(Image), diff --git a/api/src/models/entry/special.ts b/api/src/models/entry/special.ts index 4bfc1a39..7806299b 100644 --- a/api/src/models/entry/special.ts +++ b/api/src/models/entry/special.ts @@ -15,7 +15,7 @@ export const BaseSpecial = t.Intersect( number: t.Integer({ minimum: 1 }), externalId: EpisodeId, }), - BaseEntry, + BaseEntry(), ], { description: comment` @@ -25,14 +25,14 @@ export const BaseSpecial = t.Intersect( }, ); -export const Special = t.Intersect([Resource(), EntryTranslation, BaseSpecial]); +export const Special = t.Intersect([Resource(), EntryTranslation(), BaseSpecial]); export type Special = Prettify; export const SeedSpecial = t.Intersect([ t.Omit(BaseSpecial, ["thumbnail", "createdAt", "nextRefresh"]), t.Object({ thumbnail: t.Nullable(SeedImage), - translations: TranslationRecord(EntryTranslation), + translations: TranslationRecord(EntryTranslation()), videos: t.Optional(t.Array(t.String({ format: "uuid" }))), }), ]); diff --git a/api/src/models/entry/unknown-entry.ts b/api/src/models/entry/unknown-entry.ts index b5b12673..284bf856 100644 --- a/api/src/models/entry/unknown-entry.ts +++ b/api/src/models/entry/unknown-entry.ts @@ -1,14 +1,16 @@ import { t } from "elysia"; import { type Prettify, comment } from "~/utils"; +import { bubbleImages, registerExamples } from "../examples"; +import { youtubeExample } from "../examples/others"; import { Resource } from "../utils/resource"; import { BaseEntry, EntryTranslation } from "./base-entry"; export const BaseUnknownEntry = t.Intersect( [ - t.Omit(BaseEntry, ["airDate"]), t.Object({ kind: t.Literal("unknown"), }), + t.Omit(BaseEntry(), ["airDate"]), ], { description: comment` @@ -18,13 +20,15 @@ export const BaseUnknownEntry = t.Intersect( }, ); -export const UnknownEntryTranslation = t.Omit(EntryTranslation, [ +export const UnknownEntryTranslation = t.Omit(EntryTranslation(), [ "description", ]); export const UnknownEntry = t.Intersect([ Resource(), - BaseUnknownEntry, UnknownEntryTranslation, + BaseUnknownEntry, ]); export type UnknownEntry = Prettify; + +registerExamples(UnknownEntry, { ...youtubeExample, ...bubbleImages }); diff --git a/api/src/models/examples/others.ts b/api/src/models/examples/others.ts new file mode 100644 index 00000000..41de7f6e --- /dev/null +++ b/api/src/models/examples/others.ts @@ -0,0 +1,10 @@ +import type { UnknownEntry } from "~/models/entry"; + +export const youtubeExample: Partial = { + kind: "unknown", + // idk if we'll keep non-ascii characters or if we can find a way to convert them + slug: "lisa-炎-the-first-take", + name: "LiSA - 炎 / THE FIRST TAKE", + runtime: 10, + thumbnail: null, +}; diff --git a/api/tests/series/get-entries.test.ts b/api/tests/series/get-entries.test.ts index 5384cde4..1078aea8 100644 --- a/api/tests/series/get-entries.test.ts +++ b/api/tests/series/get-entries.test.ts @@ -1,5 +1,5 @@ import { beforeAll, describe, expect, it } from "bun:test"; -import { getEntries, getExtras } from "tests/helpers"; +import { getEntries, getExtras, getUnknowns } from "tests/helpers"; import { expectStatus } from "tests/utils"; import { seedSerie } from "~/controllers/seed/series"; import { madeInAbyss } from "~/models/examples";