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

View File

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

View File

@ -14,7 +14,7 @@ import {
processLanguages, processLanguages,
} from "~/models/utils"; } from "~/models/utils";
import { desc } from "~/models/utils/descriptions"; 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"] }) export const series = new Elysia({ prefix: "/series", tags: ["series"] })
.model({ .model({

View File

@ -106,7 +106,7 @@ export const jsonbObjectAgg = <T>(key: SQLWrapper, value: SQL<T>) => {
}; };
export const jsonbAgg = <T>(val: 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>) => { export const jsonbBuildObject = <T>(select: Record<string, SQLWrapper>) => {

View File

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

View File

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