diff --git a/api/src/controllers/videos.ts b/api/src/controllers/videos.ts index 080ec1a9..f5b7551f 100644 --- a/api/src/controllers/videos.ts +++ b/api/src/controllers/videos.ts @@ -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. + `, + }, + }, + ); diff --git a/api/src/index.ts b/api/src/index.ts index fd157273..a7689af1 100644 --- a/api/src/index.ts +++ b/api/src/index.ts @@ -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. + `, + }, + ], }, }), )