import { useDB, schema } from '../../utils/db.js' import { requireAdmin } from '../../utils/auth.js' import { resolveTagsWithFallback } from '../../utils/article-helpers.js' export default defineEventHandler(async (event) => { requireAdmin(event) const body = await readBody(event) if (!body?.title || !body?.slug) { throw createError({ statusCode: 422, message: '标题和 slug 不能为空' }) } const db = useDB() const now = new Date().toISOString() const result = db.insert(schema.articles).values({ slug: body.slug, title: body.title, summary: body.summary || '', content: body.content || '', category: body.category || '', type: body.type || 'news', coverImage: body.coverImage || null, author: body.author || '呼籁旅行', tags: JSON.stringify(resolveTagsWithFallback(body)), seoTitle: body.seoTitle || null, seoDesc: body.seoDesc || null, seoKeywords: body.seoKeywords || null, published: body.published !== false ? 1 : 0, createdAt: now, updatedAt: now, }).run() return { success: true, id: result.lastInsertRowid } })