mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-30 19:54:16 -04:00
Add /movies/random route
This commit is contained in:
parent
8b7e109be3
commit
9a54266967
@ -1,5 +1,5 @@
|
|||||||
import { and, eq, sql } from "drizzle-orm";
|
import { and, eq, sql } from "drizzle-orm";
|
||||||
import { Elysia, t } from "elysia";
|
import { Elysia, redirect, t } from "elysia";
|
||||||
import { KError } from "~/models/error";
|
import { KError } from "~/models/error";
|
||||||
import { comment } from "~/utils";
|
import { comment } from "~/utils";
|
||||||
import { db } from "../db";
|
import { db } from "../db";
|
||||||
@ -154,6 +154,41 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
.get(
|
||||||
|
"random",
|
||||||
|
async ({ error, redirect }) => {
|
||||||
|
const [id] = await db
|
||||||
|
.select({ id: shows.id })
|
||||||
|
.from(shows)
|
||||||
|
.where(eq(shows.kind, "movie"))
|
||||||
|
.orderBy(sql`random()`)
|
||||||
|
.limit(1);
|
||||||
|
if (!id)
|
||||||
|
return error(404, {
|
||||||
|
status: 404,
|
||||||
|
message: "No movies in the database",
|
||||||
|
});
|
||||||
|
return redirect(`/movies/${id}`);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
detail: {
|
||||||
|
description: "Get a random movie",
|
||||||
|
},
|
||||||
|
response: {
|
||||||
|
302: t.Void({
|
||||||
|
description:
|
||||||
|
"Redirected to the [/movies/id](#tag/movies/GET/movies/{id}) route.",
|
||||||
|
}),
|
||||||
|
404: {
|
||||||
|
...KError,
|
||||||
|
description: "No movie found with the given id or slug.",
|
||||||
|
examples: [
|
||||||
|
{ status: 404, message: "Movie not found", details: undefined },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
.get(
|
.get(
|
||||||
"",
|
"",
|
||||||
async ({
|
async ({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user