Use original with collections too

This commit is contained in:
Zoe Roux 2025-03-09 16:46:04 +01:00
parent aab38f6a89
commit d61573668b
No known key found for this signature in database
7 changed files with 21 additions and 21 deletions

View File

@ -21,7 +21,7 @@ import {
processLanguages,
} from "~/models/utils";
import { desc } from "~/models/utils/descriptions";
import { getShow, getShows, showFilters, showSort } from "./logic";
import { getShows, showFilters, showSort } from "./logic";
export const collections = new Elysia({
prefix: "/collections",
@ -41,11 +41,16 @@ export const collections = new Elysia({
set,
}) => {
const langs = processLanguages(languages);
const ret = await getShow(id, {
const [ret] = await getShows({
limit: 1,
filter: and(
isUuid(id) ? eq(shows.id, id) : eq(shows.slug, id),
eq(shows.kind, "collection"),
),
languages: langs,
fallbackLanguage: langs.includes("*"),
preferOriginal,
relations,
filters: eq(shows.kind, "collection"),
});
if (!ret) {
return error(404, {
@ -60,7 +65,7 @@ export const collections = new Elysia({
});
}
set.headers["content-language"] = ret.language;
return ret.show;
return ret;
},
{
detail: {

View File

@ -143,7 +143,7 @@ export async function getShows({
languages: string[];
fallbackLanguage?: boolean;
preferOriginal?: boolean;
relations?: ("translations" | "studios" | "videos")[];
relations?: (keyof typeof showRelations)[];
}) {
const transQ = db
.selectDistinctOn([showTranslations.pk])
@ -182,7 +182,7 @@ export async function getShows({
...buildRelations(relations, showRelations, { languages }),
})
.from(shows)
[fallbackLanguage ? "innerJoin" : "leftJoin"](
[fallbackLanguage ? "innerJoin" : ("leftJoin" as "innerJoin")](
transQ,
eq(shows.pk, transQ.pk),
)

View File

@ -14,7 +14,7 @@ import {
processLanguages,
} from "~/models/utils";
import { desc } from "~/models/utils/descriptions";
import { getShow, getShows, showFilters, showSort } from "./logic";
import { getShows, showFilters, showSort } from "./logic";
export const series = new Elysia({ prefix: "/series", tags: ["series"] })
.model({

View File

@ -106,7 +106,7 @@ export const jsonbObjectAgg = <T>(key: SQLWrapper, value: SQL<T>) => {
};
export const jsonbAgg = <T>(val: SQL<T>) => {
return sql<T>`jsonb_agg(${val})`;
return sql<T[]>`jsonb_agg(${val})`;
};
export const jsonbBuildObject = <T>(select: Record<string, SQLWrapper>) => {

View File

@ -7,6 +7,7 @@ import {
Genre,
Image,
Language,
Original,
Resource,
SeedImage,
TranslationRecord,
@ -27,14 +28,7 @@ const BaseCollection = t.Object({
descrpition: "Date of the last item of the collection",
}),
),
originalLanguage: t.Nullable(
Language({
description: "The language code this movie was made in.",
}),
),
nextRefresh: t.String({ format: "date-time" }),
externalId: ExternalId(),
});
@ -56,6 +50,9 @@ export const Collection = t.Intersect([
CollectionTranslation,
BaseCollection,
DbMetadata,
t.Object({
original: Original,
}),
]);
export type Collection = Prettify<typeof Collection.static>;
@ -71,6 +68,9 @@ export const SeedCollection = t.Intersect([
t.Omit(BaseCollection, ["kind", "startAir", "endAir", "nextRefresh"]),
t.Object({
slug: t.String({ format: "slug" }),
originalLanguage: Language({
description: "The language code this collection's items were made in.",
}),
translations: TranslationRecord(
t.Intersect([
t.Omit(CollectionTranslation, [
@ -84,6 +84,7 @@ export const SeedCollection = t.Intersect([
thumbnail: t.Nullable(SeedImage),
banner: t.Nullable(SeedImage),
logo: t.Nullable(SeedImage),
latinName: t.Optional(Original.properties.latinName),
}),
]),
),

View File

@ -26,11 +26,8 @@ const BaseMovie = t.Object({
runtime: t.Nullable(
t.Number({ minimum: 0, description: "Runtime of the movie in minutes." }),
),
airDate: t.Nullable(t.String({ format: "date" })),
nextRefresh: t.String({ format: "date-time" }),
externalId: ExternalId(),
});

View File

@ -35,12 +35,9 @@ const BaseSerie = t.Object({
description: "Average runtime of all episodes (in minutes.)",
}),
),
startAir: t.Nullable(t.String({ format: "date" })),
endAir: t.Nullable(t.String({ format: "date" })),
nextRefresh: t.String({ format: "date-time" }),
externalId: ExternalId(),
});