mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Fix type issues on get /movies
This commit is contained in:
parent
eea0f688a0
commit
43ae26679a
@ -7,7 +7,7 @@ import { db } from "../db";
|
||||
import { shows, showTranslations } from "../db/schema/shows";
|
||||
import { getColumns } from "../db/schema/utils";
|
||||
import { bubble } from "../models/examples";
|
||||
import { Movie, MovieTranslation } from "../models/movie";
|
||||
import { Movie, type MovieStatus, MovieTranslation } from "../models/movie";
|
||||
|
||||
// drizzle is bugged and doesn't allow js arrays to be used in raw sql.
|
||||
export function sqlarr(array: unknown[]) {
|
||||
@ -41,40 +41,6 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
|
||||
movie: Movie,
|
||||
"movie-translation": MovieTranslation,
|
||||
})
|
||||
.guard({
|
||||
params: t.Object({
|
||||
id: t.String({
|
||||
description: "The id or slug of the movie to retrieve",
|
||||
examples: [bubble.slug],
|
||||
}),
|
||||
}),
|
||||
headers: t.Object({
|
||||
"accept-language": t.String({
|
||||
default: "*",
|
||||
examples: "en-us, ja;q=0.5",
|
||||
description: comment`
|
||||
List of languages you want the data in.
|
||||
This follows the Accept-Language offical specification
|
||||
(https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language)
|
||||
`,
|
||||
}),
|
||||
}),
|
||||
response: {
|
||||
200: "movie",
|
||||
404: {
|
||||
...KError,
|
||||
description: "No movie found with the given id or slug.",
|
||||
},
|
||||
422: {
|
||||
...KError,
|
||||
description: comment`
|
||||
The Accept-Language header can't be satisfied (all languages listed are
|
||||
unavailable). Try with another languages or add * to the list of languages
|
||||
to fallback to any language.
|
||||
`,
|
||||
},
|
||||
},
|
||||
})
|
||||
.get(
|
||||
"/:id",
|
||||
async ({
|
||||
@ -91,8 +57,9 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
|
||||
const [ret] = await db
|
||||
.select({
|
||||
...moviesCol,
|
||||
...transCol,
|
||||
status: sql<MovieStatus>`${moviesCol.status}`,
|
||||
airDate: startAir,
|
||||
translation: transCol,
|
||||
})
|
||||
.from(shows)
|
||||
.leftJoin(transQ, eq(shows.pk, transQ.pk))
|
||||
@ -106,19 +73,51 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
|
||||
details: undefined,
|
||||
});
|
||||
}
|
||||
if (!ret.language) {
|
||||
if (!ret.translation) {
|
||||
return error(422, {
|
||||
status: 422,
|
||||
message: "Accept-Language header could not be satisfied.",
|
||||
details: undefined,
|
||||
});
|
||||
}
|
||||
set.headers["content-language"] = ret.language;
|
||||
return ret;
|
||||
set.headers["content-language"] = ret.translation.language;
|
||||
return { ...ret, ...ret.translation };
|
||||
},
|
||||
{
|
||||
detail: {
|
||||
description: "Get a movie by id or slug",
|
||||
},
|
||||
params: t.Object({
|
||||
id: t.String({
|
||||
description: "The id or slug of the movie to retrieve",
|
||||
examples: [bubble.slug],
|
||||
}),
|
||||
}),
|
||||
headers: t.Object({
|
||||
"accept-language": t.String({
|
||||
default: "*",
|
||||
examples: "en-us, ja;q=0.5",
|
||||
description: comment`
|
||||
List of languages you want the data in.
|
||||
This follows the Accept-Language offical specification
|
||||
(https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language)
|
||||
`,
|
||||
}),
|
||||
}),
|
||||
response: {
|
||||
200: "movie",
|
||||
404: {
|
||||
...KError,
|
||||
description: "No movie found with the given id or slug.",
|
||||
},
|
||||
422: {
|
||||
...KError,
|
||||
description: comment`
|
||||
The Accept-Language header can't be satisfied (all languages listed are
|
||||
unavailable). Try with another languages or add * to the list of languages
|
||||
to fallback to any language.
|
||||
`,
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { t } from "elysia";
|
||||
import { ExternalId, Genre, Image, Language, SeedImage } from "./utils";
|
||||
import { SeedVideo } from "./video";
|
||||
import { bubble, registerExamples } from "./examples";
|
||||
import { bubbleImages } from "./examples/bubble";
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user