import { useDB, schema } from '../../utils/db.js' import { requireAdmin } from '../../utils/auth.js' export default defineEventHandler(async (event) => { requireAdmin(event) const body = await readBody(event) if (!body?.title || !body?.image) { throw createError({ statusCode: 422, message: '标题和图片路径不能为空' }) } const db = useDB() const result = db.insert(schema.galleryItems).values({ title: body.title, category: body.category || '', location: body.location || '', description: body.description || '', image: body.image, orientation: body.orientation || 'landscape', }).run() return { success: true, id: result.lastInsertRowid } })