mirror of
https://github.com/zoriya/Kyoo.git
synced 2026-05-21 14:46:29 -04:00
Fix & test GET /videos
This commit is contained in:
@@ -14,6 +14,7 @@ import { KError } from "~/models/error";
|
||||
import { bubbleVideo } from "~/models/examples";
|
||||
import {
|
||||
Page,
|
||||
type Resource,
|
||||
Sort,
|
||||
createPage,
|
||||
isUuid,
|
||||
@@ -54,8 +55,9 @@ export const videosH = new Elysia({ prefix: "/videos", tags: ["videos"] })
|
||||
slug: shows.slug,
|
||||
})
|
||||
.from(videos)
|
||||
.crossJoin(
|
||||
.leftJoin(
|
||||
sql`jsonb_array_elements_text(${videos.guess}->'year') as year`,
|
||||
sql`true`,
|
||||
)
|
||||
.innerJoin(entryVideoJoin, eq(entryVideoJoin.videoPk, videos.pk))
|
||||
.innerJoin(entries, eq(entries.pk, entryVideoJoin.entryPk))
|
||||
@@ -78,7 +80,10 @@ export const videosH = new Elysia({ prefix: "/videos", tags: ["videos"] })
|
||||
const [{ guesses }] = await db
|
||||
.with(years, guess)
|
||||
.select({
|
||||
guesses: jsonbObjectAgg<Guesses["guesses"]>(guess.guess, guess.years),
|
||||
guesses: jsonbObjectAgg<Record<string, Resource>>(
|
||||
guess.guess,
|
||||
guess.years,
|
||||
),
|
||||
})
|
||||
.from(guess);
|
||||
|
||||
@@ -98,7 +103,7 @@ export const videosH = new Elysia({ prefix: "/videos", tags: ["videos"] })
|
||||
|
||||
return {
|
||||
paths: paths.map((x) => x.path),
|
||||
guesses,
|
||||
guesses: guesses ?? {},
|
||||
unmatched: unmatched.map((x) => x.path),
|
||||
};
|
||||
},
|
||||
@@ -177,8 +182,7 @@ export const videosH = new Elysia({ prefix: "/videos", tags: ["videos"] })
|
||||
path: videos.path,
|
||||
});
|
||||
} catch (e) {
|
||||
if (!isUniqueConstraint(e))
|
||||
throw e;
|
||||
if (!isUniqueConstraint(e)) throw e;
|
||||
return error(409, {
|
||||
status: 409,
|
||||
message: comment`
|
||||
|
||||
+3
-1
@@ -144,5 +144,7 @@ export const jsonbBuildObject = <T>(select: JsonFields) => {
|
||||
};
|
||||
|
||||
export const isUniqueConstraint = (e: unknown): boolean => {
|
||||
return typeof e === "object" && e != null && "code" in e && e.code === "23505";
|
||||
return (
|
||||
typeof e === "object" && e != null && "code" in e && e.code === "23505"
|
||||
);
|
||||
};
|
||||
|
||||
@@ -13,6 +13,7 @@ export const Resource = () =>
|
||||
id: t.String({ format: "uuid" }),
|
||||
slug: t.String({ format: "slug" }),
|
||||
});
|
||||
export type Resource = ReturnType<typeof Resource>["static"];
|
||||
|
||||
const checker = TypeCompiler.Compile(t.String({ format: "uuid" }));
|
||||
export const isUuid = (id: string) => checker.Check(id);
|
||||
|
||||
@@ -167,10 +167,7 @@ export const Guesses = t.Object({
|
||||
paths: t.Array(t.String()),
|
||||
guesses: t.Record(
|
||||
t.String(),
|
||||
t.Record(
|
||||
t.Union([t.Literal("unknown"), t.String({ pattern: "[1-9][0-9]*" })]),
|
||||
Resource(),
|
||||
),
|
||||
t.Record(t.String({ pattern: "^([1-9][0-9]{3})|unknown$" }), Resource()),
|
||||
),
|
||||
unmatched: t.Array(t.String()),
|
||||
});
|
||||
@@ -188,7 +185,7 @@ registerExamples(Guesses, {
|
||||
id: "43b742f5-9ce6-467d-ad29-74460624020a",
|
||||
slug: "evangelion",
|
||||
},
|
||||
1995: {
|
||||
"1995": {
|
||||
id: "43b742f5-9ce6-467d-ad29-74460624020a",
|
||||
slug: "evangelion",
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user