You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
1.0 KiB
29 lines
1.0 KiB
import { z } from "zod";
|
|
import { createItem } from "#server/service/collection";
|
|
import { getContextUser } from "#server/utils/context";
|
|
|
|
const createSchema = z.object({
|
|
type: z.enum(["web", "text", "image", "file", "video"]),
|
|
title: z.string().min(1),
|
|
description: z.string().optional(),
|
|
content: z.string().optional(),
|
|
url: z.string().optional(),
|
|
coverUrl: z.string().optional(),
|
|
faviconUrl: z.string().optional(),
|
|
sourceHost: z.string().optional(),
|
|
categoryId: z.number().optional().nullable(),
|
|
tagNames: z.array(z.string()).optional(),
|
|
note: z.string().optional(),
|
|
rating: z.number().min(1).max(5).optional().nullable(),
|
|
starred: z.boolean().optional(),
|
|
});
|
|
|
|
export default defineWrappedResponseHandler({ auth: "required" }, async (event) => {
|
|
const user = getContextUser(event)!;
|
|
const body = await readBody(event);
|
|
const parsed = createSchema.safeParse(body);
|
|
if (!parsed.success) return R.error("参数校验失败", parsed.error.issues);
|
|
|
|
const item = await createItem(parsed.data, user.id);
|
|
return R.success(item);
|
|
});
|
|
|