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.
33 lines
1.2 KiB
33 lines
1.2 KiB
import { z } from "zod";
|
|
import { delCache } from "#server/utils/context";
|
|
import { validate } from "#server/utils/validation";
|
|
import { createCard, CardTypes } from "../../service/card";
|
|
|
|
const createSchema = z.object({
|
|
type: z.enum(CardTypes),
|
|
title: z.string().min(1, "标题不能为空").max(60, "标题不能超过 60 字"),
|
|
description: z.string().max(200, "描述不能超过 200 字").nullable().optional(),
|
|
content: z.string().max(50000, "正文不能超过 50000 字").nullable().optional(),
|
|
aspectRatio: z.number().min(0).max(99).nullable().optional(),
|
|
categoryId: z.string().nullable().optional(),
|
|
images: z
|
|
.array(
|
|
z.object({
|
|
url: z.string().min(1, "图片地址不能为空").max(500),
|
|
sortOrder: z.number().int().optional(),
|
|
}),
|
|
)
|
|
.nullable()
|
|
.optional(),
|
|
tagIds: z.array(z.number().int().positive()).nullable().optional(),
|
|
articleIds: z.array(z.number().int().positive()).nullable().optional(),
|
|
});
|
|
|
|
export default defineWrappedResponseHandler(async (event) => {
|
|
const body = await readBody(event);
|
|
const data = validate(createSchema, body);
|
|
|
|
const card = await createCard(data);
|
|
await delCache("categories:tree");
|
|
return R.success(card);
|
|
});
|
|
|