- 新增 /api/admin/songs/batch-reject.post 批量驳回接口(事务清排期/投票/扣接纳数/黑名单去重/异步通知) - requireSongAdmin 三角色校验 + createApiError 统一错误包装 - scheduleDaysBefore/After 四字段排期可见范围限制(开放 API 与公开排期接口三处缓存路径 + DB 条件过滤) - submissionNoteAutoModeration 基于黑名单 KEYWORD/LANGUAGE/GENRE 自动判定留言 publicStatus,命中自动关闭 submissionNotePublic - 更新 songs/request.post 与 songs/[id]/update.put 接入自动审查逻辑
120 lines
3.6 KiB
TypeScript
120 lines
3.6 KiB
TypeScript
import { db } from '~/drizzle/db'
|
|
import { systemSettings } from '~/drizzle/schema'
|
|
import { cacheService } from '../services/cacheService'
|
|
import { isRedisReady } from '../utils/redis'
|
|
|
|
// 过滤敏感字段,只返回公开配置
|
|
const publicFields = [
|
|
'siteTitle',
|
|
'siteLogoUrl',
|
|
'schoolLogoHomeUrl',
|
|
'schoolLogoPrintUrl',
|
|
'siteDescription',
|
|
'siteVersion',
|
|
'submissionGuidelines',
|
|
'icpNumber',
|
|
'gonganNumber',
|
|
'enablePlayTimeSelection',
|
|
'enableSubmissionLimit',
|
|
'dailySubmissionLimit',
|
|
'weeklySubmissionLimit',
|
|
'monthlySubmissionLimit',
|
|
'showBlacklistKeywords',
|
|
'hideStudentInfo',
|
|
'enableReplayRequests',
|
|
'enableCollaborativeSubmission',
|
|
'enableSubmissionRemarks',
|
|
'enableRequestTimeLimitation',
|
|
'forceBlockAllRequests',
|
|
'smtpEnabled',
|
|
'defaultTheme',
|
|
'enabledThemes',
|
|
'scheduleDaysBeforeEnabled',
|
|
'scheduleDaysBefore',
|
|
'scheduleDaysAfterEnabled',
|
|
'scheduleDaysAfter'
|
|
]
|
|
|
|
const filterPublicSettings = (data: any) => {
|
|
if (!data) {
|
|
return {}
|
|
}
|
|
const result: Record<string, any> = {}
|
|
for (const key of publicFields) {
|
|
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
|
result[key] = data[key]
|
|
}
|
|
}
|
|
return result
|
|
}
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
try {
|
|
// 优先从Redis缓存获取系统设置
|
|
if (isRedisReady()) {
|
|
const cachedSettings = await cacheService.getSystemSettings()
|
|
if (cachedSettings) {
|
|
console.log('[API] 系统设置缓存命中')
|
|
return filterPublicSettings(cachedSettings)
|
|
}
|
|
}
|
|
|
|
// 缓存未命中或Redis不可用,从数据库获取
|
|
const settingsResult = await db.select().from(systemSettings).limit(1)
|
|
let settings = settingsResult[0] || null
|
|
|
|
if (!settings) {
|
|
// 如果不存在,创建默认设置
|
|
const newSettings = await db
|
|
.insert(systemSettings)
|
|
.values({
|
|
enablePlayTimeSelection: false,
|
|
siteTitle: 'VoiceHub',
|
|
siteLogoUrl: '/images/site-logo.png',
|
|
schoolLogoHomeUrl: '/images/school-logo-white.png',
|
|
schoolLogoPrintUrl: '/images/school-logo-transparent.png',
|
|
siteDescription: '校园广播站点歌系统 - 让你的声音被听见',
|
|
siteVersion: process.env.NUXT_PUBLIC_SITE_VERSION || null,
|
|
submissionGuidelines: '请遵守校园规定,提交健康向上的歌曲。',
|
|
icpNumber: null,
|
|
enableSubmissionLimit: false,
|
|
dailySubmissionLimit: null,
|
|
weeklySubmissionLimit: null,
|
|
showBlacklistKeywords: false,
|
|
hideStudentInfo: true,
|
|
enableCollaborativeSubmission: true,
|
|
enableSubmissionRemarks: false,
|
|
enableRequestTimeLimitation: false,
|
|
forceBlockAllRequests: false,
|
|
enableReplayRequests: false,
|
|
smtpEnabled: false,
|
|
defaultTheme: 'System',
|
|
enabledThemes: '["System","ClassicDark","ClassicLight","ModernLight"]',
|
|
scheduleDaysBeforeEnabled: false,
|
|
scheduleDaysBefore: 30,
|
|
scheduleDaysAfterEnabled: false,
|
|
scheduleDaysAfter: 14
|
|
})
|
|
.returning()
|
|
|
|
settings = newSettings[0]
|
|
}
|
|
|
|
const publicSettings = filterPublicSettings(settings)
|
|
|
|
// 将结果缓存到Redis(如果可用)- 永久缓存
|
|
if (settings && isRedisReady()) {
|
|
await cacheService.setSystemSettings(settings)
|
|
console.log('[API] 系统设置已缓存到Redis')
|
|
}
|
|
|
|
return publicSettings
|
|
} catch (error) {
|
|
console.error('获取系统设置失败:', error)
|
|
throw createError({
|
|
statusCode: 500,
|
|
statusMessage: '获取系统设置失败'
|
|
})
|
|
}
|
|
})
|