mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 20:24:27 -04:00
Support nextEntry
in /series/{id}
This commit is contained in:
parent
c3abd7c61b
commit
74ee45244b
@ -1,4 +1,13 @@
|
|||||||
import { type SQL, and, desc, eq, exists, ne, sql } from "drizzle-orm";
|
import {
|
||||||
|
type SQL,
|
||||||
|
type Subquery,
|
||||||
|
and,
|
||||||
|
desc,
|
||||||
|
eq,
|
||||||
|
exists,
|
||||||
|
ne,
|
||||||
|
sql,
|
||||||
|
} from "drizzle-orm";
|
||||||
import type { PgSelect } from "drizzle-orm/pg-core";
|
import type { PgSelect } from "drizzle-orm/pg-core";
|
||||||
import { db } from "~/db";
|
import { db } from "~/db";
|
||||||
import {
|
import {
|
||||||
@ -191,7 +200,7 @@ const showRelations = {
|
|||||||
}: {
|
}: {
|
||||||
languages: string[];
|
languages: string[];
|
||||||
userId: string;
|
userId: string;
|
||||||
watchStatusQ: PgSelect<typeof watchlist>;
|
watchStatusQ: Subquery;
|
||||||
}) => {
|
}) => {
|
||||||
const transQ = db
|
const transQ = db
|
||||||
.selectDistinctOn([entryTranslations.pk])
|
.selectDistinctOn([entryTranslations.pk])
|
||||||
@ -219,7 +228,9 @@ const showRelations = {
|
|||||||
.innerJoin(transQ, eq(entries.pk, transQ.pk))
|
.innerJoin(transQ, eq(entries.pk, transQ.pk))
|
||||||
.leftJoin(progressQ, eq(entries.pk, progressQ.entryPk))
|
.leftJoin(progressQ, eq(entries.pk, progressQ.entryPk))
|
||||||
.leftJoinLateral(entryVideosQ, sql`true`)
|
.leftJoinLateral(entryVideosQ, sql`true`)
|
||||||
.where(eq(watchStatusQ.nextEntryPk, entries.pk))
|
.where(
|
||||||
|
eq((watchStatusQ as unknown as typeof watchlist).nextEntry, entries.pk),
|
||||||
|
)
|
||||||
.as("nextEntry");
|
.as("nextEntry");
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -291,7 +302,11 @@ export async function getShows({
|
|||||||
|
|
||||||
watchStatus: getColumns(watchStatusQ),
|
watchStatus: getColumns(watchStatusQ),
|
||||||
|
|
||||||
...buildRelations(relations, showRelations, { languages, userId }),
|
...buildRelations(relations, showRelations, {
|
||||||
|
languages,
|
||||||
|
userId,
|
||||||
|
watchStatusQ,
|
||||||
|
}),
|
||||||
})
|
})
|
||||||
.from(shows)
|
.from(shows)
|
||||||
.leftJoin(watchStatusQ, eq(shows.pk, watchStatusQ.showPk))
|
.leftJoin(watchStatusQ, eq(shows.pk, watchStatusQ.showPk))
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { and, eq, sql } from "drizzle-orm";
|
import { and, eq, sql } from "drizzle-orm";
|
||||||
import { Elysia, t } from "elysia";
|
import { Elysia, t } from "elysia";
|
||||||
|
import { auth } from "~/auth";
|
||||||
import { prefix } from "~/base";
|
import { prefix } from "~/base";
|
||||||
import { db } from "~/db";
|
import { db } from "~/db";
|
||||||
import { shows } from "~/db/schema";
|
import { shows } from "~/db/schema";
|
||||||
@ -22,12 +23,14 @@ export const series = new Elysia({ prefix: "/series", tags: ["series"] })
|
|||||||
serie: Serie,
|
serie: Serie,
|
||||||
"serie-translation": SerieTranslation,
|
"serie-translation": SerieTranslation,
|
||||||
})
|
})
|
||||||
|
.use(auth)
|
||||||
.get(
|
.get(
|
||||||
"/:id",
|
"/:id",
|
||||||
async ({
|
async ({
|
||||||
params: { id },
|
params: { id },
|
||||||
headers: { "accept-language": languages },
|
headers: { "accept-language": languages },
|
||||||
query: { preferOriginal, with: relations },
|
query: { preferOriginal, with: relations },
|
||||||
|
jwt: { sub },
|
||||||
error,
|
error,
|
||||||
set,
|
set,
|
||||||
}) => {
|
}) => {
|
||||||
@ -42,6 +45,7 @@ export const series = new Elysia({ prefix: "/series", tags: ["series"] })
|
|||||||
fallbackLanguage: langs.includes("*"),
|
fallbackLanguage: langs.includes("*"),
|
||||||
preferOriginal,
|
preferOriginal,
|
||||||
relations,
|
relations,
|
||||||
|
userId: sub,
|
||||||
});
|
});
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
return error(404, {
|
return error(404, {
|
||||||
@ -72,10 +76,13 @@ export const series = new Elysia({ prefix: "/series", tags: ["series"] })
|
|||||||
preferOriginal: t.Optional(
|
preferOriginal: t.Optional(
|
||||||
t.Boolean({ description: desc.preferOriginal }),
|
t.Boolean({ description: desc.preferOriginal }),
|
||||||
),
|
),
|
||||||
with: t.Array(t.UnionEnum(["translations", "studios", "firstEntry"]), {
|
with: t.Array(
|
||||||
default: [],
|
t.UnionEnum(["translations", "studios", "firstEntry", "nextEntry"]),
|
||||||
description: "Include related resources in the response.",
|
{
|
||||||
}),
|
default: [],
|
||||||
|
description: "Include related resources in the response.",
|
||||||
|
},
|
||||||
|
),
|
||||||
}),
|
}),
|
||||||
headers: t.Object(
|
headers: t.Object(
|
||||||
{
|
{
|
||||||
@ -131,6 +138,7 @@ export const series = new Elysia({ prefix: "/series", tags: ["series"] })
|
|||||||
query: { limit, after, query, sort, filter, preferOriginal },
|
query: { limit, after, query, sort, filter, preferOriginal },
|
||||||
headers: { "accept-language": languages },
|
headers: { "accept-language": languages },
|
||||||
request: { url },
|
request: { url },
|
||||||
|
jwt: { sub },
|
||||||
}) => {
|
}) => {
|
||||||
const langs = processLanguages(languages);
|
const langs = processLanguages(languages);
|
||||||
const items = await getShows({
|
const items = await getShows({
|
||||||
@ -141,6 +149,7 @@ export const series = new Elysia({ prefix: "/series", tags: ["series"] })
|
|||||||
filter: and(eq(shows.kind, "serie"), filter),
|
filter: and(eq(shows.kind, "serie"), filter),
|
||||||
languages: langs,
|
languages: langs,
|
||||||
preferOriginal,
|
preferOriginal,
|
||||||
|
userId: sub,
|
||||||
});
|
});
|
||||||
return createPage(items, { url, sort, limit });
|
return createPage(items, { url, sort, limit });
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user