feat: align with upstream 1.5.9.9

This commit is contained in:
2026-09-12 18:21:11 +08:00
commit 34f0679117
805 changed files with 376275 additions and 0 deletions
+57
View File
@@ -0,0 +1,57 @@
import { createError, defineEventHandler, getRouterParam } from 'h3'
import { db } from '~/drizzle/db'
import { songBlacklists } from '~/drizzle/schema'
import { eq } from 'drizzle-orm'
export default defineEventHandler(async (event) => {
// 检查认证和权限
const user = event.context.user
if (!user || !['ADMIN', 'SUPER_ADMIN'].includes(user.role)) {
throw createError({
statusCode: 403,
message: '需要管理员权限'
})
}
const id = parseInt(getRouterParam(event, 'id'))
if (!id) {
throw createError({
statusCode: 400,
message: '无效的ID'
})
}
try {
// 检查黑名单项是否存在
const blacklistItemResult = await db
.select()
.from(songBlacklists)
.where(eq(songBlacklists.id, id))
.limit(1)
const blacklistItem = blacklistItemResult[0]
if (!blacklistItem) {
throw createError({
statusCode: 404,
message: '黑名单项不存在'
})
}
// 删除黑名单项
await db.delete(songBlacklists).where(eq(songBlacklists.id, id))
return {
success: true,
message: '黑名单项删除成功'
}
} catch (error) {
if (error.statusCode) {
throw error
}
console.error('删除黑名单项失败:', error)
throw createError({
statusCode: 500,
message: '删除黑名单项失败'
})
}
})
+72
View File
@@ -0,0 +1,72 @@
import { createError, defineEventHandler, getRouterParam, readBody } from 'h3'
import { db } from '~/drizzle/db'
import { songBlacklists } from '~/drizzle/schema'
import { eq } from 'drizzle-orm'
export default defineEventHandler(async (event) => {
// 检查认证和权限
const user = event.context.user
if (!user || !['ADMIN', 'SUPER_ADMIN'].includes(user.role)) {
throw createError({
statusCode: 403,
message: '需要管理员权限'
})
}
const id = parseInt(getRouterParam(event, 'id'))
if (!id) {
throw createError({
statusCode: 400,
message: '无效的ID'
})
}
const body = await readBody(event)
const { isActive, reason } = body
try {
// 检查黑名单项是否存在
const existingItemResult = await db
.select()
.from(songBlacklists)
.where(eq(songBlacklists.id, id))
.limit(1)
if (existingItemResult.length === 0) {
throw createError({
statusCode: 404,
message: '黑名单项不存在'
})
}
// 更新黑名单项
const updateData = {}
if (typeof isActive === 'boolean') {
updateData.isActive = isActive
}
if (reason !== undefined) {
updateData.reason = reason?.trim() || null
}
const updatedItem = await db
.update(songBlacklists)
.set(updateData)
.where(eq(songBlacklists.id, id))
.returning()
return {
success: true,
message: '黑名单项更新成功',
item: updatedItem[0]
}
} catch (error) {
if (error.statusCode) {
throw error
}
console.error('更新黑名单项失败:', error)
throw createError({
statusCode: 500,
message: '更新黑名单项失败'
})
}
})
+63
View File
@@ -0,0 +1,63 @@
import { createError, defineEventHandler, getQuery } from 'h3'
import { db } from '~/drizzle/db'
import { songBlacklists } from '~/drizzle/schema'
import { and, count, desc, eq, ilike } from 'drizzle-orm'
export default defineEventHandler(async (event) => {
// 检查认证和权限
const user = event.context.user
if (!user || !['ADMIN', 'SUPER_ADMIN'].includes(user.role)) {
throw createError({
statusCode: 403,
message: '需要管理员权限'
})
}
const query = getQuery(event)
const page = parseInt(query.page as string) || 1
const limit = parseInt(query.limit as string) || 20
const type = query.type as string
const search = query.search as string
try {
// 构建查询条件
const whereConditions = []
if (type) {
whereConditions.push(eq(songBlacklists.type, type))
}
if (search) {
whereConditions.push(ilike(songBlacklists.value, `%${search}%`))
}
const whereClause = whereConditions.length > 0 ? and(...whereConditions) : undefined
// 获取总数
const totalResult = await db.select({ count: count() }).from(songBlacklists).where(whereClause)
const total = totalResult[0].count
// 获取黑名单列表
const blacklist = await db
.select()
.from(songBlacklists)
.where(whereClause)
.orderBy(desc(songBlacklists.createdAt))
.limit(limit)
.offset((page - 1) * limit)
return {
blacklist,
pagination: {
page,
limit,
total,
pages: Math.ceil(total / limit)
}
}
} catch (error) {
console.error('获取黑名单失败:', error)
throw createError({
statusCode: 500,
message: '获取黑名单失败'
})
}
})
+95
View File
@@ -0,0 +1,95 @@
import { createError, defineEventHandler, readBody } from 'h3'
import { db } from '~/drizzle/db'
import { songBlacklists } from '~/drizzle/schema'
import { and, eq } from 'drizzle-orm'
import {
BLACKLIST_TYPES,
BLACKLIST_LANGUAGE_VALUES,
BLACKLIST_GENRE_VALUES
} from '~~/server/config/constants'
export default defineEventHandler(async (event) => {
// 检查认证和权限
const user = event.context.user
if (!user || !['ADMIN', 'SUPER_ADMIN'].includes(user.role)) {
throw createError({
statusCode: 403,
message: '需要管理员权限'
})
}
const body = await readBody(event)
const { type, value, reason } = body
// 验证输入
if (!type || !value) {
throw createError({
statusCode: 400,
message: '类型和值不能为空'
})
}
if (!Object.values(BLACKLIST_TYPES).includes(type)) {
throw createError({
statusCode: 400,
message: '无效的黑名单类型'
})
}
// 语种/曲风为固定候选值,防止录入无法匹配的自由文本
if (type === BLACKLIST_TYPES.LANGUAGE && !BLACKLIST_LANGUAGE_VALUES.includes(value.trim())) {
throw createError({
statusCode: 400,
message: '无效的语种候选值'
})
}
if (type === BLACKLIST_TYPES.GENRE && !BLACKLIST_GENRE_VALUES.includes(value.trim())) {
throw createError({
statusCode: 400,
message: '无效的曲风候选值'
})
}
try {
// 检查是否已存在
const existing = await db
.select()
.from(songBlacklists)
.where(and(eq(songBlacklists.type, type), eq(songBlacklists.value, value.trim())))
.limit(1)
if (existing.length > 0) {
throw createError({
statusCode: 409,
message: '该项目已在黑名单中'
})
}
// 创建黑名单项
const blacklistItem = await db
.insert(songBlacklists)
.values({
type,
value: value.trim(),
reason: reason?.trim() || null,
createdBy: user.id,
isActive: true
})
.returning()
return {
success: true,
message: '黑名单项添加成功',
item: blacklistItem[0]
}
} catch (error) {
if (error.statusCode) {
throw error
}
console.error('添加黑名单项失败:', error)
throw createError({
statusCode: 500,
message: '添加黑名单项失败'
})
}
})