mirror of
https://github.com/zoriya/Kyoo.git
synced 2026-04-21 09:18:51 -04:00
Cleanup response properly (#1258)
This commit is contained in:
parent
a76c8858a0
commit
6044f88571
@ -46,6 +46,7 @@ async function verifyJwt(bearer: string) {
|
||||
|
||||
export const auth = new Elysia({ name: "auth" })
|
||||
.guard({
|
||||
schema: "standalone",
|
||||
headers: t.Object(
|
||||
{
|
||||
authorization: t.Optional(t.TemplateLiteral("Bearer ${string}")),
|
||||
|
||||
@ -16,7 +16,7 @@ import { staffH } from "./controllers/staff";
|
||||
import { studiosH } from "./controllers/studios";
|
||||
import { videosReadH, videosWriteH } from "./controllers/videos";
|
||||
import { dbRaw } from "./db";
|
||||
import type { KError } from "./models/error";
|
||||
import { KError } from "./models/error";
|
||||
import { appWs } from "./websockets";
|
||||
|
||||
const logger = getLogger();
|
||||
@ -98,11 +98,10 @@ export const handlers = new Elysia({ prefix })
|
||||
detail: {
|
||||
security: [{ bearer: ["core.read"] }, { api: ["core.read"] }],
|
||||
},
|
||||
// See https://github.com/elysiajs/elysia/issues/1158
|
||||
// response: {
|
||||
// 401: { ...KError, description: "" },
|
||||
// 403: { ...KError, description: "" },
|
||||
// },
|
||||
response: {
|
||||
401: { ...KError, description: "" },
|
||||
403: { ...KError, description: "" },
|
||||
},
|
||||
permissions: ["core.read"],
|
||||
},
|
||||
(app) =>
|
||||
@ -126,11 +125,10 @@ export const handlers = new Elysia({ prefix })
|
||||
detail: {
|
||||
security: [{ bearer: ["core.write"] }, { api: ["core.write"] }],
|
||||
},
|
||||
// See https://github.com/elysiajs/elysia/issues/1158
|
||||
// response: {
|
||||
// 401: { ...KError, description: "" },
|
||||
// 403: { ...KError, description: "" },
|
||||
// },
|
||||
response: {
|
||||
401: { ...KError, description: "" },
|
||||
403: { ...KError, description: "" },
|
||||
},
|
||||
permissions: ["core.write"],
|
||||
},
|
||||
(app) => app.use(videosWriteH).use(seed),
|
||||
|
||||
@ -396,12 +396,9 @@ export const entriesH = new Elysia({ tags: ["series"] })
|
||||
}),
|
||||
after: t.Optional(t.String({ description: description.after })),
|
||||
}),
|
||||
headers: t.Object(
|
||||
{
|
||||
"accept-language": AcceptLanguage({ autoFallback: true }),
|
||||
},
|
||||
{ additionalProperties: true },
|
||||
),
|
||||
headers: t.Object({
|
||||
"accept-language": AcceptLanguage({ autoFallback: true }),
|
||||
}),
|
||||
response: {
|
||||
200: Page(Entry),
|
||||
404: {
|
||||
@ -516,12 +513,9 @@ export const entriesH = new Elysia({ tags: ["series"] })
|
||||
},
|
||||
{
|
||||
detail: { description: "Get new movies/episodes added recently." },
|
||||
headers: t.Object(
|
||||
{
|
||||
"accept-language": AcceptLanguage({ autoFallback: true }),
|
||||
},
|
||||
{ additionalProperties: true },
|
||||
),
|
||||
headers: t.Object({
|
||||
"accept-language": AcceptLanguage({ autoFallback: true }),
|
||||
}),
|
||||
query: t.Object({
|
||||
filter: t.Optional(Filter({ def: entryFilters })),
|
||||
query: t.Optional(t.String({ description: description.query })),
|
||||
|
||||
@ -374,12 +374,9 @@ export const historyH = new Elysia({ tags: ["profiles"] })
|
||||
detail: {
|
||||
description: "List your watch history (episodes/movies seen)",
|
||||
},
|
||||
headers: t.Object(
|
||||
{
|
||||
"accept-language": AcceptLanguage({ autoFallback: true }),
|
||||
},
|
||||
{ additionalProperties: true },
|
||||
),
|
||||
headers: t.Object({
|
||||
"accept-language": AcceptLanguage({ autoFallback: true }),
|
||||
}),
|
||||
response: {
|
||||
200: Page(Entry),
|
||||
},
|
||||
|
||||
@ -130,12 +130,9 @@ export const nextup = new Elysia({ tags: ["profiles"] })
|
||||
detail: {
|
||||
description: "",
|
||||
},
|
||||
headers: t.Object(
|
||||
{
|
||||
"accept-language": AcceptLanguage({ autoFallback: true }),
|
||||
},
|
||||
{ additionalProperties: true },
|
||||
),
|
||||
headers: t.Object({
|
||||
"accept-language": AcceptLanguage({ autoFallback: true }),
|
||||
}),
|
||||
response: {
|
||||
200: Page(Entry),
|
||||
},
|
||||
|
||||
@ -165,12 +165,9 @@ export const watchlistH = new Elysia({ tags: ["profiles"] })
|
||||
},
|
||||
{
|
||||
detail: { description: "Get all movies/series in your watchlist" },
|
||||
headers: t.Object(
|
||||
{
|
||||
"accept-language": AcceptLanguage({ autoFallback: true }),
|
||||
},
|
||||
{ additionalProperties: true },
|
||||
),
|
||||
headers: t.Object({
|
||||
"accept-language": AcceptLanguage({ autoFallback: true }),
|
||||
}),
|
||||
response: {
|
||||
200: Page(
|
||||
t.Union([
|
||||
|
||||
@ -132,12 +132,9 @@ export const seasonsH = new Elysia({ tags: ["series"] })
|
||||
}),
|
||||
after: t.Optional(t.String({ description: desc.after })),
|
||||
}),
|
||||
headers: t.Object(
|
||||
{
|
||||
"accept-language": AcceptLanguage({ autoFallback: true }),
|
||||
},
|
||||
{ additionalProperties: true },
|
||||
),
|
||||
headers: t.Object({
|
||||
"accept-language": AcceptLanguage({ autoFallback: true }),
|
||||
}),
|
||||
response: {
|
||||
200: Page(Season),
|
||||
404: {
|
||||
|
||||
@ -92,12 +92,9 @@ export const collections = new Elysia({
|
||||
description: "Include related resources in the response.",
|
||||
}),
|
||||
}),
|
||||
headers: t.Object(
|
||||
{
|
||||
"accept-language": AcceptLanguage(),
|
||||
},
|
||||
{ additionalProperties: true },
|
||||
),
|
||||
headers: t.Object({
|
||||
"accept-language": AcceptLanguage(),
|
||||
}),
|
||||
response: {
|
||||
200: { ...FullCollection, description: "Found" },
|
||||
404: {
|
||||
@ -191,12 +188,9 @@ export const collections = new Elysia({
|
||||
}),
|
||||
),
|
||||
}),
|
||||
headers: t.Object(
|
||||
{
|
||||
"accept-language": AcceptLanguage({ autoFallback: true }),
|
||||
},
|
||||
{ additionalProperties: true },
|
||||
),
|
||||
headers: t.Object({
|
||||
"accept-language": AcceptLanguage({ autoFallback: true }),
|
||||
}),
|
||||
response: {
|
||||
200: Page(Collection),
|
||||
422: KError,
|
||||
@ -227,12 +221,9 @@ export const collections = new Elysia({
|
||||
}),
|
||||
),
|
||||
}),
|
||||
headers: t.Object(
|
||||
{
|
||||
"accept-language": AcceptLanguage({ autoFallback: true }),
|
||||
},
|
||||
{ additionalProperties: true },
|
||||
),
|
||||
headers: t.Object({
|
||||
"accept-language": AcceptLanguage({ autoFallback: true }),
|
||||
}),
|
||||
})
|
||||
.get(
|
||||
"/:id/movies",
|
||||
|
||||
@ -82,12 +82,9 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
|
||||
description: "Include related resources in the response.",
|
||||
}),
|
||||
}),
|
||||
headers: t.Object(
|
||||
{
|
||||
"accept-language": AcceptLanguage(),
|
||||
},
|
||||
{ additionalProperties: true },
|
||||
),
|
||||
headers: t.Object({
|
||||
"accept-language": AcceptLanguage(),
|
||||
}),
|
||||
response: {
|
||||
200: { ...FullMovie, description: "Found" },
|
||||
404: {
|
||||
@ -179,12 +176,9 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
|
||||
}),
|
||||
),
|
||||
}),
|
||||
headers: t.Object(
|
||||
{
|
||||
"accept-language": AcceptLanguage({ autoFallback: true }),
|
||||
},
|
||||
{ additionalProperties: true },
|
||||
),
|
||||
headers: t.Object({
|
||||
"accept-language": AcceptLanguage({ autoFallback: true }),
|
||||
}),
|
||||
response: {
|
||||
200: Page(Movie),
|
||||
422: KError,
|
||||
|
||||
@ -85,12 +85,9 @@ export const series = new Elysia({ prefix: "/series", tags: ["series"] })
|
||||
},
|
||||
),
|
||||
}),
|
||||
headers: t.Object(
|
||||
{
|
||||
"accept-language": AcceptLanguage(),
|
||||
},
|
||||
{ additionalProperties: true },
|
||||
),
|
||||
headers: t.Object({
|
||||
"accept-language": AcceptLanguage(),
|
||||
}),
|
||||
response: {
|
||||
200: { ...FullSerie, description: "Found" },
|
||||
404: {
|
||||
@ -185,12 +182,9 @@ export const series = new Elysia({ prefix: "/series", tags: ["series"] })
|
||||
}),
|
||||
),
|
||||
}),
|
||||
headers: t.Object(
|
||||
{
|
||||
"accept-language": AcceptLanguage({ autoFallback: true }),
|
||||
},
|
||||
{ additionalProperties: true },
|
||||
),
|
||||
headers: t.Object({
|
||||
"accept-language": AcceptLanguage({ autoFallback: true }),
|
||||
}),
|
||||
response: {
|
||||
200: Page(Serie),
|
||||
422: KError,
|
||||
|
||||
@ -147,12 +147,9 @@ export const showsH = new Elysia({ prefix: "/shows", tags: ["shows"] })
|
||||
}),
|
||||
),
|
||||
}),
|
||||
headers: t.Object(
|
||||
{
|
||||
"accept-language": AcceptLanguage({ autoFallback: true }),
|
||||
},
|
||||
{ additionalProperties: true },
|
||||
),
|
||||
headers: t.Object({
|
||||
"accept-language": AcceptLanguage({ autoFallback: true }),
|
||||
}),
|
||||
response: {
|
||||
200: Page(Show),
|
||||
422: KError,
|
||||
|
||||
@ -298,12 +298,9 @@ export const staffH = new Elysia({ tags: ["staff"] })
|
||||
}),
|
||||
),
|
||||
}),
|
||||
headers: t.Object(
|
||||
{
|
||||
"accept-language": AcceptLanguage(),
|
||||
},
|
||||
{ additionalProperties: true },
|
||||
),
|
||||
headers: t.Object({
|
||||
"accept-language": AcceptLanguage(),
|
||||
}),
|
||||
response: {
|
||||
200: Page(RoleWShow),
|
||||
404: {
|
||||
|
||||
@ -178,12 +178,9 @@ export const studiosH = new Elysia({ prefix: "/studios", tags: ["studios"] })
|
||||
description: "Include related resources in the response.",
|
||||
}),
|
||||
}),
|
||||
headers: t.Object(
|
||||
{
|
||||
"accept-language": AcceptLanguage(),
|
||||
},
|
||||
{ additionalProperties: true },
|
||||
),
|
||||
headers: t.Object({
|
||||
"accept-language": AcceptLanguage(),
|
||||
}),
|
||||
response: {
|
||||
200: "studio",
|
||||
404: {
|
||||
@ -261,12 +258,9 @@ export const studiosH = new Elysia({ prefix: "/studios", tags: ["studios"] })
|
||||
}),
|
||||
after: t.Optional(t.String({ description: desc.after })),
|
||||
}),
|
||||
headers: t.Object(
|
||||
{
|
||||
"accept-language": AcceptLanguage({ autoFallback: true }),
|
||||
},
|
||||
{ additionalProperties: true },
|
||||
),
|
||||
headers: t.Object({
|
||||
"accept-language": AcceptLanguage({ autoFallback: true }),
|
||||
}),
|
||||
response: {
|
||||
200: Page(Studio),
|
||||
422: KError,
|
||||
@ -297,12 +291,9 @@ export const studiosH = new Elysia({ prefix: "/studios", tags: ["studios"] })
|
||||
}),
|
||||
),
|
||||
}),
|
||||
headers: t.Object(
|
||||
{
|
||||
"accept-language": AcceptLanguage({ autoFallback: true }),
|
||||
},
|
||||
{ additionalProperties: true },
|
||||
),
|
||||
headers: t.Object({
|
||||
"accept-language": AcceptLanguage({ autoFallback: true }),
|
||||
}),
|
||||
})
|
||||
.get(
|
||||
"/:id/shows",
|
||||
|
||||
@ -513,12 +513,9 @@ export const videosReadH = new Elysia({ prefix: "/videos", tags: ["videos"] })
|
||||
}),
|
||||
),
|
||||
}),
|
||||
headers: t.Object(
|
||||
{
|
||||
"accept-language": AcceptLanguage(),
|
||||
},
|
||||
{ additionalProperties: true },
|
||||
),
|
||||
headers: t.Object({
|
||||
"accept-language": AcceptLanguage(),
|
||||
}),
|
||||
response: {
|
||||
200: t.Composite([
|
||||
Video,
|
||||
|
||||
@ -41,12 +41,12 @@ export const Sort = (
|
||||
.Transform(
|
||||
t.Array(
|
||||
t.Union([
|
||||
t.TemplateLiteral("random:${number}"),
|
||||
t.UnionEnum([
|
||||
"random",
|
||||
...Object.keys(values),
|
||||
...Object.keys(values).map((x) => `-${x}`),
|
||||
]),
|
||||
t.TemplateLiteral("random:${number}"),
|
||||
]),
|
||||
{
|
||||
default: def,
|
||||
|
||||
@ -140,13 +140,10 @@ export const Video = t.Composite([
|
||||
export type Video = Prettify<typeof Video.static>;
|
||||
|
||||
// type used in entry responses (the slug comes from the entryVideoJoin)
|
||||
export const EmbeddedVideo = t.Composite(
|
||||
[
|
||||
t.Object({ slug: t.String({ format: "slug" }) }),
|
||||
t.Omit(Video, ["guess", "createdAt", "updatedAt"]),
|
||||
],
|
||||
{ additionalProperties: true },
|
||||
);
|
||||
export const EmbeddedVideo = t.Composite([
|
||||
t.Object({ slug: t.String({ format: "slug" }) }),
|
||||
t.Omit(Video, ["guess", "createdAt", "updatedAt"]),
|
||||
]);
|
||||
export type EmbeddedVideo = Prettify<typeof EmbeddedVideo.static>;
|
||||
|
||||
registerExamples(Video, bubbleVideo);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user