mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Create post /videos route
This commit is contained in:
parent
c20aa862a9
commit
3d20f063e9
@ -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.
|
||||
`,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
@ -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.
|
||||
`,
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user