Cleanup response properly (#1258)

This commit is contained in:
Zoe Roux 2026-01-05 12:51:39 +01:00 committed by GitHub
parent a76c8858a0
commit 6044f88571
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 72 additions and 133 deletions

View File

@ -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}")),

View File

@ -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),

View File

@ -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 })),

View File

@ -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),
},

View File

@ -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),
},

View File

@ -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([

View File

@ -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: {

View File

@ -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",

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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: {

View File

@ -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",

View File

@ -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,

View File

@ -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,

View File

@ -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);