Files
BYW-VoiceHub/server/api/admin/changelog/index.post.ts
T
Henry_Du 4ce4649aaf
Build VoiceHub FPK / build-fpk (push) Failing after 56m5s
Build and Push Docker Image / build-and-push (push) Canceled after 1h9m35s
初次提交
2026-09-06 08:19:02 +08:00

45 lines
1.2 KiB
TypeScript

import { db } from '~/drizzle/db'
import { changelogEntries } from '~/drizzle/schema'
export default defineEventHandler(async (event) => {
const user = event.context.user
if (!user) {
throw createError({ statusCode: 401, message: '未授权访问' })
}
if (!['ADMIN', 'SUPER_ADMIN'].includes(user.role)) {
throw createError({ statusCode: 403, message: '只有管理员才能创建更新日志' })
}
const body = await readBody(event)
const version = typeof body?.version === 'string' ? body.version.trim() : ''
const title = typeof body?.title === 'string' ? body.title.trim() : ''
const content = typeof body?.content === 'string' ? body.content.trim() : ''
const published = body?.published === true
if (!version) {
throw createError({ statusCode: 400, message: 'version 不能为空' })
}
if (!title) {
throw createError({ statusCode: 400, message: 'title 不能为空' })
}
if (!content) {
throw createError({ statusCode: 400, message: 'content 不能为空' })
}
const rows = await db
.insert(changelogEntries)
.values({
version,
title,
content,
published,
publishedAt: published ? new Date() : null,
createdBy: user.id
})
.returning()
return rows[0]
})