mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 20:24:27 -04:00
Add with=videos
support for movies
This commit is contained in:
parent
e0ad458d73
commit
b093df96ec
@ -2,11 +2,14 @@ import type { StaticDecode } from "@sinclair/typebox";
|
|||||||
import { type SQL, and, eq, exists, sql } from "drizzle-orm";
|
import { type SQL, and, eq, exists, sql } from "drizzle-orm";
|
||||||
import { db } from "~/db";
|
import { db } from "~/db";
|
||||||
import {
|
import {
|
||||||
|
entries,
|
||||||
|
entryVideoJoin,
|
||||||
showStudioJoin,
|
showStudioJoin,
|
||||||
showTranslations,
|
showTranslations,
|
||||||
shows,
|
shows,
|
||||||
studioTranslations,
|
studioTranslations,
|
||||||
studios,
|
studios,
|
||||||
|
videos,
|
||||||
} from "~/db/schema";
|
} from "~/db/schema";
|
||||||
import {
|
import {
|
||||||
coalesce,
|
coalesce,
|
||||||
@ -28,6 +31,7 @@ import {
|
|||||||
keysetPaginate,
|
keysetPaginate,
|
||||||
sortToSql,
|
sortToSql,
|
||||||
} from "~/models/utils";
|
} from "~/models/utils";
|
||||||
|
import type { EmbeddedVideo } from "~/models/video";
|
||||||
|
|
||||||
export const showFilters: FilterDef = {
|
export const showFilters: FilterDef = {
|
||||||
genres: {
|
genres: {
|
||||||
@ -120,7 +124,24 @@ const showRelations = {
|
|||||||
},
|
},
|
||||||
// only available for movies
|
// only available for movies
|
||||||
videos: () => {
|
videos: () => {
|
||||||
throw new Error();
|
const { guess, createdAt, updatedAt, ...videosCol } = getColumns(videos);
|
||||||
|
return db
|
||||||
|
.select({
|
||||||
|
videos: coalesce(
|
||||||
|
jsonbAgg(
|
||||||
|
jsonbBuildObject<EmbeddedVideo>({
|
||||||
|
slug: entryVideoJoin.slug,
|
||||||
|
...videosCol,
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
sql`'[]'::jsonb`,
|
||||||
|
).as("videos"),
|
||||||
|
})
|
||||||
|
.from(entryVideoJoin)
|
||||||
|
.where(eq(entryVideoJoin.entryPk, entries.pk))
|
||||||
|
.leftJoin(entries, eq(entries.showPk, shows.pk))
|
||||||
|
.leftJoin(videos, eq(videos.pk, entryVideoJoin.videoPk))
|
||||||
|
.as("videos");
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ import {
|
|||||||
TranslationRecord,
|
TranslationRecord,
|
||||||
} from "./utils";
|
} from "./utils";
|
||||||
import { Original } from "./utils/original";
|
import { Original } from "./utils/original";
|
||||||
import { Video } from "./video";
|
import { EmbeddedVideo } from "./video";
|
||||||
|
|
||||||
export const MovieStatus = t.UnionEnum(["unknown", "finished", "planned"]);
|
export const MovieStatus = t.UnionEnum(["unknown", "finished", "planned"]);
|
||||||
export type MovieStatus = typeof MovieStatus.static;
|
export type MovieStatus = typeof MovieStatus.static;
|
||||||
@ -62,7 +62,7 @@ export const FullMovie = t.Intersect([
|
|||||||
Movie,
|
Movie,
|
||||||
t.Object({
|
t.Object({
|
||||||
translations: t.Optional(TranslationRecord(MovieTranslation)),
|
translations: t.Optional(TranslationRecord(MovieTranslation)),
|
||||||
videos: t.Optional(t.Array(Video)),
|
videos: t.Optional(t.Array(EmbeddedVideo)),
|
||||||
studios: t.Optional(t.Array(Studio)),
|
studios: t.Optional(t.Array(Studio)),
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
@ -134,4 +134,35 @@ describe("Get movie", () => {
|
|||||||
expectStatus(resp, body).toBe(200);
|
expectStatus(resp, body).toBe(200);
|
||||||
expect(body.isAvailable).toBe(false);
|
expect(body.isAvailable).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("with=translations", async () => {
|
||||||
|
const [resp, body] = await getMovie(bubble.slug, {
|
||||||
|
with: ["translations"],
|
||||||
|
});
|
||||||
|
|
||||||
|
expectStatus(resp, body).toBe(200);
|
||||||
|
expect(body.translations).toMatchObject({
|
||||||
|
en: { name: bubble.translations.en.name },
|
||||||
|
ja: { name: bubble.translations.ja.name },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it("with=translations,videos", async () => {
|
||||||
|
const [resp, body] = await getMovie(bubble.slug, {
|
||||||
|
with: ["translations", "videos"],
|
||||||
|
});
|
||||||
|
|
||||||
|
expectStatus(resp, body).toBe(200);
|
||||||
|
expect(body.translations).toMatchObject({
|
||||||
|
en: { name: bubble.translations.en.name },
|
||||||
|
ja: { name: bubble.translations.ja.name },
|
||||||
|
});
|
||||||
|
expect(body.videos).toBeArrayOfSize(bubble.videos!.length);
|
||||||
|
expect(body.videos[0]).toMatchObject({
|
||||||
|
path: bubbleVideo.path,
|
||||||
|
slug: bubbleVideo.slug,
|
||||||
|
version: bubbleVideo.version,
|
||||||
|
rendering: bubbleVideo.rendering,
|
||||||
|
part: bubbleVideo.part,
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user