mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Add /series/random
This commit is contained in:
parent
cc221c560d
commit
f143511e14
@ -184,7 +184,7 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
|
|||||||
if (!movie)
|
if (!movie)
|
||||||
return error(404, {
|
return error(404, {
|
||||||
status: 404,
|
status: 404,
|
||||||
message: "No movies in the database",
|
message: "No movies in the database.",
|
||||||
});
|
});
|
||||||
return redirect(`/movies/${movie.id}`);
|
return redirect(`/movies/${movie.id}`);
|
||||||
},
|
},
|
||||||
@ -199,7 +199,7 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
|
|||||||
}),
|
}),
|
||||||
404: {
|
404: {
|
||||||
...KError,
|
...KError,
|
||||||
description: "No movie found with the given id or slug.",
|
description: "No movies in the database.",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { and, eq } from "drizzle-orm";
|
import { and, eq, sql } from "drizzle-orm";
|
||||||
import { Elysia, t } from "elysia";
|
import { Elysia, t } from "elysia";
|
||||||
|
import { db } from "~/db";
|
||||||
import { shows } from "~/db/schema";
|
import { shows } from "~/db/schema";
|
||||||
import { KError } from "~/models/error";
|
import { KError } from "~/models/error";
|
||||||
import { Serie, SerieTranslation } from "~/models/serie";
|
import { Serie, SerieTranslation } from "~/models/serie";
|
||||||
@ -18,6 +19,38 @@ export const series = new Elysia({ prefix: "/series", tags: ["series"] })
|
|||||||
serie: Serie,
|
serie: Serie,
|
||||||
"serie-translation": SerieTranslation,
|
"serie-translation": SerieTranslation,
|
||||||
})
|
})
|
||||||
|
.get(
|
||||||
|
"random",
|
||||||
|
async ({ error, redirect }) => {
|
||||||
|
const [serie] = await db
|
||||||
|
.select({ id: shows.id })
|
||||||
|
.from(shows)
|
||||||
|
.where(eq(shows.kind, "serie"))
|
||||||
|
.orderBy(sql`random()`)
|
||||||
|
.limit(1);
|
||||||
|
if (!serie)
|
||||||
|
return error(404, {
|
||||||
|
status: 404,
|
||||||
|
message: "No series in the database.",
|
||||||
|
});
|
||||||
|
return redirect(`/series/${serie.id}`);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
detail: {
|
||||||
|
description: "Get a random serie",
|
||||||
|
},
|
||||||
|
response: {
|
||||||
|
302: t.Void({
|
||||||
|
description:
|
||||||
|
"Redirected to the [/series/{id}](#tag/series/GET/series/{id}) route.",
|
||||||
|
}),
|
||||||
|
404: {
|
||||||
|
...KError,
|
||||||
|
description: "No series in the database.",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
.get(
|
.get(
|
||||||
"",
|
"",
|
||||||
async ({
|
async ({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user