mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 12:14:46 -04:00
Add a flag to retrieve all translations
This commit is contained in:
parent
02ddd1401b
commit
956ab51e1b
@ -11,7 +11,12 @@ import {
|
|||||||
} from "~/db/schema";
|
} from "~/db/schema";
|
||||||
import { getColumns, sqlarr } from "~/db/schema/utils";
|
import { getColumns, sqlarr } from "~/db/schema/utils";
|
||||||
import { bubble } from "~/models/examples";
|
import { bubble } from "~/models/examples";
|
||||||
import { Movie, MovieStatus, MovieTranslation } from "~/models/movie";
|
import {
|
||||||
|
FullMovie,
|
||||||
|
Movie,
|
||||||
|
MovieStatus,
|
||||||
|
MovieTranslation,
|
||||||
|
} from "~/models/movie";
|
||||||
import {
|
import {
|
||||||
Filter,
|
Filter,
|
||||||
type Image,
|
type Image,
|
||||||
@ -49,7 +54,7 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
|
|||||||
async ({
|
async ({
|
||||||
params: { id },
|
params: { id },
|
||||||
headers: { "accept-language": languages },
|
headers: { "accept-language": languages },
|
||||||
query: { preferOriginal },
|
query: { preferOriginal, with: relations },
|
||||||
error,
|
error,
|
||||||
set,
|
set,
|
||||||
}) => {
|
}) => {
|
||||||
@ -86,7 +91,7 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
|
|||||||
isUuid(id) ? eq(shows.id, id) : eq(shows.slug, id),
|
isUuid(id) ? eq(shows.id, id) : eq(shows.slug, id),
|
||||||
),
|
),
|
||||||
with: {
|
with: {
|
||||||
translations: {
|
selectedTranslation: {
|
||||||
columns: {
|
columns: {
|
||||||
pk: false,
|
pk: false,
|
||||||
},
|
},
|
||||||
@ -113,6 +118,13 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
|
|||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
...(relations.includes("translations") && {
|
||||||
|
translations: {
|
||||||
|
columns: {
|
||||||
|
pk: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -122,7 +134,7 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
|
|||||||
message: "Movie not found",
|
message: "Movie not found",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const translation = ret.translations[0];
|
const translation = ret.selectedTranslation[0];
|
||||||
if (!translation) {
|
if (!translation) {
|
||||||
return error(422, {
|
return error(422, {
|
||||||
status: 422,
|
status: 422,
|
||||||
@ -140,6 +152,14 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
|
|||||||
...(ot.banner && { banner: ot.banner }),
|
...(ot.banner && { banner: ot.banner }),
|
||||||
...(ot.logo && { logo: ot.logo }),
|
...(ot.logo && { logo: ot.logo }),
|
||||||
}),
|
}),
|
||||||
|
...(ret.translations && {
|
||||||
|
translations: Object.fromEntries(
|
||||||
|
ret.translations.map(
|
||||||
|
({ language, ...translation }) =>
|
||||||
|
[language, translation] as const,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -162,6 +182,10 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
|
|||||||
`,
|
`,
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
with: t.Array(t.UnionEnum(["translations", "videos"]), {
|
||||||
|
default: [],
|
||||||
|
description: "Include related resources in the response.",
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
headers: t.Object({
|
headers: t.Object({
|
||||||
"accept-language": t.String({
|
"accept-language": t.String({
|
||||||
@ -174,13 +198,10 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
|
|||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
response: {
|
response: {
|
||||||
200: { ...Movie, description: "Found" },
|
200: { ...FullMovie, description: "Found" },
|
||||||
404: {
|
404: {
|
||||||
...KError,
|
...KError,
|
||||||
description: "No movie found with the given id or slug.",
|
description: "No movie found with the given id or slug.",
|
||||||
examples: [
|
|
||||||
{ status: 404, message: "Movie not found", details: undefined },
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
422: {
|
422: {
|
||||||
...KError,
|
...KError,
|
||||||
@ -189,12 +210,6 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
|
|||||||
unavailable.) Try with another languages or add * to the list of languages
|
unavailable.) Try with another languages or add * to the list of languages
|
||||||
to fallback to any language.
|
to fallback to any language.
|
||||||
`,
|
`,
|
||||||
examples: [
|
|
||||||
{
|
|
||||||
status: 422,
|
|
||||||
message: "Accept-Language header could not be satisfied.",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -227,9 +242,6 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
|
|||||||
404: {
|
404: {
|
||||||
...KError,
|
...KError,
|
||||||
description: "No movie found with the given id or slug.",
|
description: "No movie found with the given id or slug.",
|
||||||
examples: [
|
|
||||||
{ status: 404, message: "Movie not found", details: undefined },
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -362,16 +374,6 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
|
|||||||
422: {
|
422: {
|
||||||
...KError,
|
...KError,
|
||||||
description: "Invalid query parameters.",
|
description: "Invalid query parameters.",
|
||||||
examples: [
|
|
||||||
{
|
|
||||||
status: 422,
|
|
||||||
message:
|
|
||||||
"Invalid property: slug. Expected one of genres, rating, status, runtime, airDate, originalLanguage.",
|
|
||||||
details: {
|
|
||||||
in: "slug eq bubble",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -110,6 +110,9 @@ export const showTranslations = schema.table(
|
|||||||
);
|
);
|
||||||
|
|
||||||
export const showsRelations = relations(shows, ({ many, one }) => ({
|
export const showsRelations = relations(shows, ({ many, one }) => ({
|
||||||
|
selectedTranslation: many(showTranslations, {
|
||||||
|
relationName: "selectedTranslation",
|
||||||
|
}),
|
||||||
translations: many(showTranslations, { relationName: "showTranslations" }),
|
translations: many(showTranslations, { relationName: "showTranslations" }),
|
||||||
originalTranslation: one(showTranslations, {
|
originalTranslation: one(showTranslations, {
|
||||||
relationName: "originalTranslation",
|
relationName: "originalTranslation",
|
||||||
@ -123,6 +126,11 @@ export const showsTrRelations = relations(showTranslations, ({ one }) => ({
|
|||||||
fields: [showTranslations.pk],
|
fields: [showTranslations.pk],
|
||||||
references: [shows.pk],
|
references: [shows.pk],
|
||||||
}),
|
}),
|
||||||
|
selectedTranslation: one(shows, {
|
||||||
|
relationName: "selectedTranslation",
|
||||||
|
fields: [showTranslations.pk],
|
||||||
|
references: [shows.pk],
|
||||||
|
}),
|
||||||
originalTranslation: one(shows, {
|
originalTranslation: one(shows, {
|
||||||
relationName: "originalTranslation",
|
relationName: "originalTranslation",
|
||||||
fields: [showTranslations.pk, showTranslations.language],
|
fields: [showTranslations.pk, showTranslations.language],
|
||||||
|
@ -1,10 +1,15 @@
|
|||||||
import { t } from "elysia";
|
import { t } from "elysia";
|
||||||
|
|
||||||
export const KError = t.Object({
|
export const KError = t.Object(
|
||||||
status: t.Integer(),
|
{
|
||||||
message: t.String(),
|
status: t.Integer(),
|
||||||
details: t.Optional(t.Any()),
|
message: t.String(),
|
||||||
});
|
details: t.Optional(t.Any()),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
examples: [{ status: 404, message: "Movie not found" }],
|
||||||
|
},
|
||||||
|
);
|
||||||
export type KError = typeof KError.static;
|
export type KError = typeof KError.static;
|
||||||
|
|
||||||
export class KErrorT extends Error {
|
export class KErrorT extends Error {
|
||||||
|
@ -9,6 +9,7 @@ import {
|
|||||||
} from "./utils";
|
} from "./utils";
|
||||||
import { bubble, registerExamples } from "./examples";
|
import { bubble, registerExamples } from "./examples";
|
||||||
import { bubbleImages } from "./examples/bubble";
|
import { bubbleImages } from "./examples/bubble";
|
||||||
|
import { Video } 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;
|
||||||
@ -58,6 +59,15 @@ export const Movie = t.Intersect([
|
|||||||
]);
|
]);
|
||||||
export type Movie = typeof Movie.static;
|
export type Movie = typeof Movie.static;
|
||||||
|
|
||||||
|
export const FullMovie = t.Intersect([
|
||||||
|
Movie,
|
||||||
|
t.Object({
|
||||||
|
translations: t.Optional(TranslationRecord(MovieTranslation)),
|
||||||
|
videos: t.Optional(t.Array(Video)),
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
export type FullMovie = typeof FullMovie.static;
|
||||||
|
|
||||||
export const SeedMovie = t.Intersect([
|
export const SeedMovie = t.Intersect([
|
||||||
t.Omit(BaseMovie, ["id", "createdAt", "nextRefresh"]),
|
t.Omit(BaseMovie, ["id", "createdAt", "nextRefresh"]),
|
||||||
t.Object({
|
t.Object({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user