mirror of
https://github.com/zoriya/Kyoo.git
synced 2026-05-25 00:22:28 -04:00
Create post /videos route
This commit is contained in:
@@ -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.
|
||||
`,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user