mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Use sql builder instead of orm for /movie
This commit is contained in:
parent
16fb638231
commit
cca0da4bf6
@ -62,6 +62,7 @@ export async function getShows({
|
||||
sort,
|
||||
filter,
|
||||
languages,
|
||||
fallbackLanguage = true,
|
||||
preferOriginal = false,
|
||||
}: {
|
||||
after: string | undefined;
|
||||
@ -70,11 +71,17 @@ export async function getShows({
|
||||
sort: StaticDecode<typeof showSort>;
|
||||
filter: SQL | undefined;
|
||||
languages: string[];
|
||||
fallbackLanguage?: boolean;
|
||||
preferOriginal?: boolean;
|
||||
}) {
|
||||
const transQ = db
|
||||
.selectDistinctOn([showTranslations.pk])
|
||||
.from(showTranslations)
|
||||
.where(
|
||||
!fallbackLanguage
|
||||
? eq(showTranslations.language, sql`any(${sqlarr(languages)})`)
|
||||
: undefined,
|
||||
)
|
||||
.orderBy(
|
||||
showTranslations.pk,
|
||||
sql`array_position(${sqlarr(languages)}, ${showTranslations.language})`,
|
||||
@ -86,6 +93,8 @@ export async function getShows({
|
||||
.select({
|
||||
...getColumns(shows),
|
||||
...transCol,
|
||||
lanugage: transQ.language,
|
||||
|
||||
// movie columns (status is only a typescript hint)
|
||||
status: sql<MovieStatus>`${shows.status}`,
|
||||
airDate: shows.startAir,
|
||||
@ -93,14 +102,17 @@ export async function getShows({
|
||||
isAvailable: sql<boolean>`${shows.availableCount} != 0`,
|
||||
|
||||
...(preferOriginal && {
|
||||
poster: sql<Image>`coalesce(${shows.original}->'poster', ${showTranslations.poster})`,
|
||||
thumbnail: sql<Image>`coalesce(${shows.original}->'thumbnail', ${showTranslations.thumbnail})`,
|
||||
banner: sql<Image>`coalesce(${shows.original}->'banner', ${showTranslations.banner})`,
|
||||
logo: sql<Image>`coalesce(${shows.original}->'logo', ${showTranslations.logo})`,
|
||||
poster: sql<Image>`coalesce(${shows.original}->'poster', ${transQ.poster})`,
|
||||
thumbnail: sql<Image>`coalesce(${shows.original}->'thumbnail', ${transQ.thumbnail})`,
|
||||
banner: sql<Image>`coalesce(${shows.original}->'banner', ${transQ.banner})`,
|
||||
logo: sql<Image>`coalesce(${shows.original}->'logo', ${transQ.logo})`,
|
||||
}),
|
||||
})
|
||||
.from(shows)
|
||||
.innerJoin(transQ, eq(shows.pk, transQ.pk))
|
||||
[fallbackLanguage ? "leftJoin" : "innerJoin"](
|
||||
transQ,
|
||||
eq(shows.pk, transQ.pk),
|
||||
)
|
||||
.where(
|
||||
and(
|
||||
filter,
|
||||
|
@ -10,10 +10,11 @@ import {
|
||||
Filter,
|
||||
Page,
|
||||
createPage,
|
||||
isUuid,
|
||||
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 movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
|
||||
.model({
|
||||
@ -30,11 +31,15 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
|
||||
set,
|
||||
}) => {
|
||||
const langs = processLanguages(languages);
|
||||
const ret = await getShow(id, {
|
||||
const [ret] = await getShows({
|
||||
filter: and(
|
||||
isUuid(id) ? eq(shows.id, id) : eq(shows.slug, id),
|
||||
eq(shows.kind, "movie"),
|
||||
),
|
||||
languages: langs,
|
||||
fallbackLanguage: langs.includes("*"),
|
||||
preferOriginal,
|
||||
relations,
|
||||
filters: eq(shows.kind, "movie"),
|
||||
});
|
||||
if (!ret) {
|
||||
return error(404, {
|
||||
@ -49,7 +54,7 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
|
||||
});
|
||||
}
|
||||
set.headers["content-language"] = ret.language;
|
||||
return ret.show;
|
||||
return ret;
|
||||
},
|
||||
{
|
||||
detail: {
|
||||
|
Loading…
x
Reference in New Issue
Block a user