Create post /videos route

This commit is contained in:
Zoe Roux 2024-11-25 21:39:17 +01:00
parent c20aa862a9
commit 3d20f063e9
No known key found for this signature in database
2 changed files with 43 additions and 4 deletions

View File

@ -1,11 +1,41 @@
import { Elysia, t } from "elysia";
import { Video } from "../models/video";
import { SeedVideo, Video } from "~/models/video";
import { db } from "~/db";
import { videos as videosT } from "~/db/schema";
import { comment } from "~/utils";
import { bubbleVideo } from "~/models/examples";
export const videos = new Elysia({ prefix: "/videos" })
const CreatedVideo = t.Object({
id: t.String({ format: "uuid" }),
path: t.String({ example: bubbleVideo.path }),
});
export const videos = new Elysia({ prefix: "/videos", tags: ["videos"] })
.model({
video: Video,
"created-videos": t.Array(CreatedVideo),
error: t.Object({}),
})
.get("/:id", () => "hello" as unknown as Video, {
response: { 200: "video" },
});
})
.post(
"/",
async ({ body }) => {
return await db
.insert(videosT)
.values(body)
.onConflictDoNothing()
.returning({ id: videosT.id, path: videosT.path });
},
{
body: t.Array(SeedVideo),
response: { 201: "created-videos" },
detail: {
description: comment`
Create videos in bulk.
Duplicated videos will simply be ignored.
`,
},
},
);

View File

@ -58,7 +58,16 @@ const app = new Elysia()
description: "Kyoo's demo server",
},
],
tags: [{ name: "movies", description: "Routes about movies" }],
tags: [
{ name: "movies", description: "Routes about movies" },
{
name: "videos",
description: comment`
Used by the scanner internally to list & create videos.
Can be used for administration or third party apps.
`,
},
],
},
}),
)