mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Add /series/:id/extras route
This commit is contained in:
parent
a5483b4ca1
commit
29696c378a
@ -6,7 +6,7 @@ import { entries, entryTranslations, shows } from "~/db/schema";
|
|||||||
import { getColumns, sqlarr } from "~/db/utils";
|
import { getColumns, sqlarr } from "~/db/utils";
|
||||||
import {
|
import {
|
||||||
Entry,
|
Entry,
|
||||||
EntryKind,
|
type EntryKind,
|
||||||
Episode,
|
Episode,
|
||||||
Extra,
|
Extra,
|
||||||
ExtraType,
|
ExtraType,
|
||||||
@ -66,6 +66,10 @@ const entrySort = Sort(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const extraSort = Sort(["slug", "name", "runtime", "createdAt"], {
|
||||||
|
default: ["slug"],
|
||||||
|
});
|
||||||
|
|
||||||
async function getEntries(
|
async function getEntries(
|
||||||
serie: string,
|
serie: string,
|
||||||
{
|
{
|
||||||
@ -107,7 +111,15 @@ async function getEntries(
|
|||||||
.as("t");
|
.as("t");
|
||||||
const { pk, name, ...transCol } = getColumns(transQ);
|
const { pk, name, ...transCol } = getColumns(transQ);
|
||||||
|
|
||||||
const { kind, externalId, order, seasonNumber, episodeNumber, extraKind, ...entryCol } = getColumns(entries);
|
const {
|
||||||
|
kind,
|
||||||
|
externalId,
|
||||||
|
order,
|
||||||
|
seasonNumber,
|
||||||
|
episodeNumber,
|
||||||
|
extraKind,
|
||||||
|
...entryCol
|
||||||
|
} = getColumns(entries);
|
||||||
return await db
|
return await db
|
||||||
.with(show)
|
.with(show)
|
||||||
.select({
|
.select({
|
||||||
@ -117,7 +129,9 @@ async function getEntries(
|
|||||||
number: sql<number>`${episodeNumber}`.as("order"),
|
number: sql<number>`${episodeNumber}`.as("order"),
|
||||||
|
|
||||||
// merge `extraKind` into `kind`
|
// merge `extraKind` into `kind`
|
||||||
kind: sql<EntryKind>`case when ${kind} = 'extra' then ${extraKind} else ${kind} end`.as("kind"),
|
kind: sql<EntryKind>`case when ${kind} = 'extra' then ${extraKind} else ${kind} end`.as(
|
||||||
|
"kind",
|
||||||
|
),
|
||||||
isExtra: sql<boolean>`${kind} = "extra"`.as("isExtra"),
|
isExtra: sql<boolean>`${kind} = "extra"`.as("isExtra"),
|
||||||
|
|
||||||
// assign more restrained types to make typescript happy.
|
// assign more restrained types to make typescript happy.
|
||||||
@ -168,7 +182,7 @@ export const entriesH = new Elysia()
|
|||||||
request: { url },
|
request: { url },
|
||||||
}) => {
|
}) => {
|
||||||
const langs = processLanguages(languages);
|
const langs = processLanguages(languages);
|
||||||
const items = await getEntries(id, {
|
const items = (await getEntries(id, {
|
||||||
limit,
|
limit,
|
||||||
after,
|
after,
|
||||||
query,
|
query,
|
||||||
@ -179,7 +193,7 @@ export const entriesH = new Elysia()
|
|||||||
filter,
|
filter,
|
||||||
),
|
),
|
||||||
languages: langs,
|
languages: langs,
|
||||||
}) as Entry[];
|
})) as Entry[];
|
||||||
|
|
||||||
return createPage(items, { url, sort, limit });
|
return createPage(items, { url, sort, limit });
|
||||||
},
|
},
|
||||||
@ -212,9 +226,50 @@ export const entriesH = new Elysia()
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.get("/extras/:id", () => "hello" as unknown as Extra, {
|
.get(
|
||||||
response: { 200: "extra" },
|
"/series/:id/extras",
|
||||||
})
|
async ({
|
||||||
|
params: { id },
|
||||||
|
query: { limit, after, query, sort, filter },
|
||||||
|
request: { url },
|
||||||
|
}) => {
|
||||||
|
const items = (await getEntries(id, {
|
||||||
|
limit,
|
||||||
|
after,
|
||||||
|
query,
|
||||||
|
sort: sort as any,
|
||||||
|
filter: and(eq(entries.kind, "extra"), filter),
|
||||||
|
languages: ["extra"],
|
||||||
|
})) as Extra[];
|
||||||
|
|
||||||
|
return createPage(items, { url, sort, limit });
|
||||||
|
},
|
||||||
|
{
|
||||||
|
detail: { description: "Get extras of a serie" },
|
||||||
|
path: t.Object({
|
||||||
|
id: t.String({
|
||||||
|
description: "The id or slug of the serie.",
|
||||||
|
examples: [madeInAbyss.slug],
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
query: t.Object({
|
||||||
|
sort: extraSort,
|
||||||
|
filter: t.Optional(Filter({ def: extraFilters })),
|
||||||
|
query: t.Optional(t.String({ description: desc.query })),
|
||||||
|
limit: t.Integer({
|
||||||
|
minimum: 1,
|
||||||
|
maximum: 250,
|
||||||
|
default: 50,
|
||||||
|
description: "Max page size.",
|
||||||
|
}),
|
||||||
|
after: t.Optional(t.String({ description: desc.after })),
|
||||||
|
}),
|
||||||
|
response: {
|
||||||
|
200: Page(Extra),
|
||||||
|
422: KError,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
.get("/unknowns/:id", () => "hello" as unknown as UnknownEntry, {
|
.get("/unknowns/:id", () => "hello" as unknown as UnknownEntry, {
|
||||||
response: { 200: "unknown_entry" },
|
response: { 200: "unknown_entry" },
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user