Files
BYW-VoiceHub/server/api/admin/system-settings/index.post.ts
T
Henry_Du cccaf36990 feat(brand): 站点品牌名统一为「宝一外校园点歌系统」
站长要求全站一致(小程序端已单独提交)。本次只改**用户可见文案与默认值**:

- 服务端默认值/兜底:system-settings-defaults、admin/system-settings(GET/POST)、
  site-config.get、utils/siteUtils —— 原来是 'VoiceHub' / '校园广播站点歌系统'
- 用户可见通知文案:MeoW 绑定验证码与标题、MeoW 测试通知、微信订阅测试通知
- 2FA 应用名(authenticator.keyuri)、WebAuthn rpName(出现在系统密钥弹窗里)
- 网页版界面:首页副标题、后台侧栏品牌名、登录/注册/找回/改密标题与文案、
  年度回顾(IntroSlide / ShareCard / 页面标题)、用户教程、通知发送预览、
  API 密钥与数据库导入说明、酷狗 sidecar 说明、打印页脚与歌单卡片页脚、Logo alt

**刻意不动**:localStorage/sessionStorage 的 `voicehub_*` 键、`voicehub:` 前缀的
STORAGE_KEY 与缓存/Redis 前缀、`window.voiceHubPlayer` 之类代码标识、MeoW 的
User-Agent、以及上游项目链接 `github.com/laoshuikaixue/VoiceHub`(那是对原项目的署名)。

注意:站点名**数据**(systemSettings.siteTitle)仍是你后台里设置的「宝一外校园点歌」,
代码只保证默认值与文案一致;要让全站显示完整名称,请在后台「站点配置 → 站点标题」
改成「宝一外校园点歌系统」。
2026-09-30 20:24:55 +08:00

934 lines
31 KiB
TypeScript

import { db } from '~/drizzle/db'
import { systemSettings } from '~/drizzle/schema'
import { eq } from 'drizzle-orm'
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: '只有管理员才能更新系统设置'
})
}
try {
const body = await readBody(event)
// 验证请求体
const updateData: any = {}
if (body.hideStudentInfo !== undefined) {
if (typeof body.hideStudentInfo !== 'boolean') {
throw createError({
statusCode: 400,
message: 'hideStudentInfo 必须是布尔值'
})
}
updateData.hideStudentInfo = body.hideStudentInfo
}
if (body.enablePlayTimeSelection !== undefined) {
if (typeof body.enablePlayTimeSelection !== 'boolean') {
throw createError({
statusCode: 400,
message: 'enablePlayTimeSelection 必须是布尔值'
})
}
updateData.enablePlayTimeSelection = body.enablePlayTimeSelection
}
if (body.siteTitle !== undefined) {
updateData.siteTitle = body.siteTitle
}
if (body.siteLogoUrl !== undefined) {
updateData.siteLogoUrl = body.siteLogoUrl
}
if (body.schoolLogoHomeUrl !== undefined) {
updateData.schoolLogoHomeUrl = body.schoolLogoHomeUrl
}
if (body.schoolLogoPrintUrl !== undefined) {
updateData.schoolLogoPrintUrl = body.schoolLogoPrintUrl
}
if (body.siteDescription !== undefined) {
updateData.siteDescription = body.siteDescription
}
if (body.siteVersion !== undefined) {
if (body.siteVersion !== null && typeof body.siteVersion !== 'string') {
throw createError({
statusCode: 400,
message: 'siteVersion 必须是字符串或null'
})
}
updateData.siteVersion =
body.siteVersion === null ? null : (body.siteVersion.trim() || null)
}
if (body.submissionGuidelines !== undefined) {
updateData.submissionGuidelines = body.submissionGuidelines
}
if (body.icpNumber !== undefined) {
updateData.icpNumber = body.icpNumber
}
if (body.gonganNumber !== undefined) {
updateData.gonganNumber = body.gonganNumber
}
if (body.enableSubmissionLimit !== undefined) {
if (typeof body.enableSubmissionLimit !== 'boolean') {
throw createError({
statusCode: 400,
message: 'enableSubmissionLimit 必须是布尔值'
})
}
updateData.enableSubmissionLimit = body.enableSubmissionLimit
}
if (body.dailySubmissionLimit !== undefined) {
if (
body.dailySubmissionLimit !== null &&
(!Number.isInteger(body.dailySubmissionLimit) || body.dailySubmissionLimit < 0)
) {
throw createError({
statusCode: 400,
message: 'dailySubmissionLimit 必须是非负整数或null'
})
}
updateData.dailySubmissionLimit = body.dailySubmissionLimit
}
if (body.weeklySubmissionLimit !== undefined) {
if (
body.weeklySubmissionLimit !== null &&
(!Number.isInteger(body.weeklySubmissionLimit) || body.weeklySubmissionLimit < 0)
) {
throw createError({
statusCode: 400,
message: 'weeklySubmissionLimit 必须是非负整数或null'
})
}
updateData.weeklySubmissionLimit = body.weeklySubmissionLimit
}
if (body.monthlySubmissionLimit !== undefined) {
if (
body.monthlySubmissionLimit !== null &&
(!Number.isInteger(body.monthlySubmissionLimit) || body.monthlySubmissionLimit < 0)
) {
throw createError({
statusCode: 400,
message: 'monthlySubmissionLimit 必须是非负整数或null'
})
}
updateData.monthlySubmissionLimit = body.monthlySubmissionLimit
}
if (body.showBlacklistKeywords !== undefined) {
if (typeof body.showBlacklistKeywords !== 'boolean') {
throw createError({
statusCode: 400,
message: 'showBlacklistKeywords 必须是布尔值'
})
}
updateData.showBlacklistKeywords = body.showBlacklistKeywords
}
if (body.enableReplayRequests !== undefined) {
if (typeof body.enableReplayRequests !== 'boolean') {
throw createError({
statusCode: 400,
message: 'enableReplayRequests 必须是布尔值'
})
}
updateData.enableReplayRequests = body.enableReplayRequests
}
if (body.enableCollaborativeSubmission !== undefined) {
if (typeof body.enableCollaborativeSubmission !== 'boolean') {
throw createError({
statusCode: 400,
message: 'enableCollaborativeSubmission 必须是布尔值'
})
}
updateData.enableCollaborativeSubmission = body.enableCollaborativeSubmission
}
if (body.enableSubmissionRemarks !== undefined) {
if (typeof body.enableSubmissionRemarks !== 'boolean') {
throw createError({
statusCode: 400,
message: 'enableSubmissionRemarks 必须是布尔值'
})
}
updateData.enableSubmissionRemarks = body.enableSubmissionRemarks
}
if (body.enableRequestTimeLimitation !== undefined) {
if (typeof body.enableRequestTimeLimitation !== 'boolean') {
throw createError({
statusCode: 400,
message: 'enableRequestTimeLimitation 必须是布尔值'
})
}
updateData.enableRequestTimeLimitation = body.enableRequestTimeLimitation
}
if (body.forceBlockAllRequests !== undefined) {
if (typeof body.forceBlockAllRequests !== 'boolean') {
throw createError({
statusCode: 400,
message: 'forceBlockAllRequests 必须是布尔值'
})
}
updateData.forceBlockAllRequests = body.forceBlockAllRequests
}
if (body.submissionNoteRequiresApproval !== undefined) {
if (typeof body.submissionNoteRequiresApproval !== 'boolean') {
throw createError({
statusCode: 400,
message: 'submissionNoteRequiresApproval 必须是布尔值'
})
}
updateData.submissionNoteRequiresApproval = body.submissionNoteRequiresApproval
}
if (body.telemetryEnabled !== undefined) {
if (typeof body.telemetryEnabled !== 'boolean') {
throw createError({
statusCode: 400,
message: 'telemetryEnabled 必须是布尔值'
})
}
updateData.telemetryEnabled = body.telemetryEnabled
}
if (body.showBeianIcon !== undefined) {
if (typeof body.showBeianIcon !== 'boolean') {
throw createError({
statusCode: 400,
message: 'showBeianIcon 必须是布尔值'
})
}
updateData.showBeianIcon = body.showBeianIcon
}
if (body.scheduleDaysDisplay !== undefined) {
if (body.scheduleDaysDisplay !== null && (!Number.isInteger(body.scheduleDaysDisplay) || body.scheduleDaysDisplay < 0)) {
throw createError({
statusCode: 400,
message: 'scheduleDaysDisplay 必须是非负整数或null'
})
}
updateData.scheduleDaysDisplay = body.scheduleDaysDisplay
}
if (body.scheduleDaysEditable !== undefined) {
if (body.scheduleDaysEditable !== null && (!Number.isInteger(body.scheduleDaysEditable) || body.scheduleDaysEditable < 0)) {
throw createError({
statusCode: 400,
message: 'scheduleDaysEditable 必须是非负整数或null'
})
}
updateData.scheduleDaysEditable = body.scheduleDaysEditable
}
if (body.scheduleDaysRequestable !== undefined) {
if (body.scheduleDaysRequestable !== null && (!Number.isInteger(body.scheduleDaysRequestable) || body.scheduleDaysRequestable < 0)) {
throw createError({
statusCode: 400,
message: 'scheduleDaysRequestable 必须是非负整数或null'
})
}
updateData.scheduleDaysRequestable = body.scheduleDaysRequestable
}
if (body.scheduleDaysBeforeEnabled !== undefined) {
if (typeof body.scheduleDaysBeforeEnabled !== 'boolean') {
throw createError({
statusCode: 400,
message: 'scheduleDaysBeforeEnabled 必须是布尔值'
})
}
updateData.scheduleDaysBeforeEnabled = body.scheduleDaysBeforeEnabled
}
if (body.scheduleDaysBefore !== undefined) {
if (body.scheduleDaysBefore !== null && (!Number.isInteger(body.scheduleDaysBefore) || body.scheduleDaysBefore < 0)) {
throw createError({
statusCode: 400,
message: 'scheduleDaysBefore 必须是非负整数或null'
})
}
updateData.scheduleDaysBefore = body.scheduleDaysBefore
}
if (body.scheduleDaysAfterEnabled !== undefined) {
if (typeof body.scheduleDaysAfterEnabled !== 'boolean') {
throw createError({
statusCode: 400,
message: 'scheduleDaysAfterEnabled 必须是布尔值'
})
}
updateData.scheduleDaysAfterEnabled = body.scheduleDaysAfterEnabled
}
if (body.scheduleDaysAfter !== undefined) {
if (body.scheduleDaysAfter !== null && (!Number.isInteger(body.scheduleDaysAfter) || body.scheduleDaysAfter < 0)) {
throw createError({
statusCode: 400,
message: 'scheduleDaysAfter 必须是非负整数或null'
})
}
updateData.scheduleDaysAfter = body.scheduleDaysAfter
}
if (body.forcePasswordChangeOnFirstLogin !== undefined) {
if (typeof body.forcePasswordChangeOnFirstLogin !== 'boolean') {
throw createError({
statusCode: 400,
message: 'forcePasswordChangeOnFirstLogin 必须是布尔值'
})
}
updateData.forcePasswordChangeOnFirstLogin = body.forcePasswordChangeOnFirstLogin
}
if (body.enableSubmissionRestriction !== undefined) {
if (typeof body.enableSubmissionRestriction !== 'boolean') {
throw createError({
statusCode: 400,
message: 'enableSubmissionRestriction 必须是布尔值'
})
}
updateData.enableSubmissionRestriction = body.enableSubmissionRestriction
}
if (body.submissionRestrictionScope !== undefined) {
updateData.submissionRestrictionScope = body.submissionRestrictionScope
}
if (body.cardCodeEnabled !== undefined) {
if (typeof body.cardCodeEnabled !== 'boolean') {
throw createError({
statusCode: 400,
message: 'cardCodeEnabled 必须是布尔值'
})
}
updateData.cardCodeEnabled = body.cardCodeEnabled
}
if (body.cardCodeSubmissionRequired !== undefined) {
if (typeof body.cardCodeSubmissionRequired !== 'boolean') {
throw createError({
statusCode: 400,
message: 'cardCodeSubmissionRequired 必须是布尔值'
})
}
updateData.cardCodeSubmissionRequired = body.cardCodeSubmissionRequired
}
if (body.cardCodeVoteEnabled !== undefined) {
if (typeof body.cardCodeVoteEnabled !== 'boolean') {
throw createError({
statusCode: 400,
message: 'cardCodeVoteEnabled 必须是布尔值'
})
}
updateData.cardCodeVoteEnabled = body.cardCodeVoteEnabled
}
if (body.cardCodeReplayEnabled !== undefined) {
if (typeof body.cardCodeReplayEnabled !== 'boolean') {
throw createError({
statusCode: 400,
message: 'cardCodeReplayEnabled 必须是布尔值'
})
}
updateData.cardCodeReplayEnabled = body.cardCodeReplayEnabled
}
if (body.enableCardCodeRequests !== undefined) {
if (typeof body.enableCardCodeRequests !== 'boolean') {
throw createError({
statusCode: 400,
message: 'enableCardCodeRequests 必须是布尔值'
})
}
updateData.enableCardCodeRequests = body.enableCardCodeRequests
}
if (body.requireCardCodeForRequests !== undefined) {
if (typeof body.requireCardCodeForRequests !== 'boolean') {
throw createError({
statusCode: 400,
message: 'requireCardCodeForRequests 必须是布尔值'
})
}
updateData.requireCardCodeForRequests = body.requireCardCodeForRequests
}
if (body.enableCardCodeLimitBypass !== undefined) {
if (typeof body.enableCardCodeLimitBypass !== 'boolean') {
throw createError({
statusCode: 400,
message: 'enableCardCodeLimitBypass 必须是布尔值'
})
}
updateData.enableCardCodeLimitBypass = body.enableCardCodeLimitBypass
}
if (body.submissionRestrictionEnabled !== undefined) {
if (typeof body.submissionRestrictionEnabled !== 'boolean') {
throw createError({
statusCode: 400,
message: 'submissionRestrictionEnabled 必须是布尔值'
})
}
updateData.submissionRestrictionEnabled = body.submissionRestrictionEnabled
}
if (body.submissionRestrictionGradeEnabled !== undefined) {
if (typeof body.submissionRestrictionGradeEnabled !== 'boolean') {
throw createError({
statusCode: 400,
message: 'submissionRestrictionGradeEnabled 必须是布尔值'
})
}
updateData.submissionRestrictionGradeEnabled = body.submissionRestrictionGradeEnabled
}
if (body.submissionRestrictionClassEnabled !== undefined) {
if (typeof body.submissionRestrictionClassEnabled !== 'boolean') {
throw createError({
statusCode: 400,
message: 'submissionRestrictionClassEnabled 必须是布尔值'
})
}
updateData.submissionRestrictionClassEnabled = body.submissionRestrictionClassEnabled
}
if (body.submissionRestrictionGraduateEnabled !== undefined) {
if (typeof body.submissionRestrictionGraduateEnabled !== 'boolean') {
throw createError({
statusCode: 400,
message: 'submissionRestrictionGraduateEnabled 必须是布尔值'
})
}
updateData.submissionRestrictionGraduateEnabled = body.submissionRestrictionGraduateEnabled
}
if (body.submissionRestrictionWithdrawnEnabled !== undefined) {
if (typeof body.submissionRestrictionWithdrawnEnabled !== 'boolean') {
throw createError({
statusCode: 400,
message: 'submissionRestrictionWithdrawnEnabled 必须是布尔值'
})
}
updateData.submissionRestrictionWithdrawnEnabled = body.submissionRestrictionWithdrawnEnabled
}
if (body.captchaProvider !== undefined) {
updateData.captchaProvider = body.captchaProvider
}
if (body.captchaEnabled !== undefined) {
if (typeof body.captchaEnabled !== 'boolean') {
throw createError({
statusCode: 400,
message: 'captchaEnabled 必须是布尔值'
})
}
updateData.captchaEnabled = body.captchaEnabled
}
if (body.allowRegister !== undefined) {
if (typeof body.allowRegister !== 'boolean') {
throw createError({
statusCode: 400,
message: 'allowRegister 必须是布尔值'
})
}
updateData.allowRegister = body.allowRegister
}
if (body.registerRequireEmail !== undefined) {
if (typeof body.registerRequireEmail !== 'boolean') {
throw createError({
statusCode: 400,
message: 'registerRequireEmail 必须是布尔值'
})
}
updateData.registerRequireEmail = body.registerRequireEmail
}
if (body.registerRequireEmailVerify !== undefined) {
if (typeof body.registerRequireEmailVerify !== 'boolean') {
throw createError({
statusCode: 400,
message: 'registerRequireEmailVerify 必须是布尔值'
})
}
updateData.registerRequireEmailVerify = body.registerRequireEmailVerify
}
if (body.registerDefaultRole !== undefined) {
updateData.registerDefaultRole = body.registerDefaultRole
}
if (body.registerRequiresApproval !== undefined) {
if (typeof body.registerRequiresApproval !== 'boolean') {
throw createError({
statusCode: 400,
message: 'registerRequiresApproval 必须是布尔值'
})
}
updateData.registerRequiresApproval = body.registerRequiresApproval
}
if (body.oauthRegisterRequiresApproval !== undefined) {
if (typeof body.oauthRegisterRequiresApproval !== 'boolean') {
throw createError({
statusCode: 400,
message: 'oauthRegisterRequiresApproval 必须是布尔值'
})
}
updateData.oauthRegisterRequiresApproval = body.oauthRegisterRequiresApproval
}
if (body.registerEmailRequired !== undefined) {
if (typeof body.registerEmailRequired !== 'boolean') {
throw createError({
statusCode: 400,
message: 'registerEmailRequired 必须是布尔值'
})
}
updateData.registerEmailRequired = body.registerEmailRequired
}
if (body.registerRequiresGradeClass !== undefined) {
if (typeof body.registerRequiresGradeClass !== 'boolean') {
throw createError({
statusCode: 400,
message: 'registerRequiresGradeClass 必须是布尔值'
})
}
updateData.registerRequiresGradeClass = body.registerRequiresGradeClass
}
if (body.oauthEnabled !== undefined) {
if (typeof body.oauthEnabled !== 'boolean') {
throw createError({
statusCode: 400,
message: 'oauthEnabled 必须是布尔值'
})
}
updateData.oauthEnabled = body.oauthEnabled
}
if (body.oauthAllowRegister !== undefined) {
if (typeof body.oauthAllowRegister !== 'boolean') {
throw createError({
statusCode: 400,
message: 'oauthAllowRegister 必须是布尔值'
})
}
updateData.oauthAllowRegister = body.oauthAllowRegister
}
if (body.oauthAllowLogin !== undefined) {
if (typeof body.oauthAllowLogin !== 'boolean') {
throw createError({
statusCode: 400,
message: 'oauthAllowLogin 必须是布尔值'
})
}
updateData.oauthAllowLogin = body.oauthAllowLogin
}
if (body.oauthAllowBind !== undefined) {
if (typeof body.oauthAllowBind !== 'boolean') {
throw createError({
statusCode: 400,
message: 'oauthAllowBind 必须是布尔值'
})
}
updateData.oauthAllowBind = body.oauthAllowBind
}
if (body.allowOAuthRegistration !== undefined) {
if (typeof body.allowOAuthRegistration !== 'boolean') {
throw createError({
statusCode: 400,
message: 'allowOAuthRegistration 必须是布尔值'
})
}
updateData.allowOAuthRegistration = body.allowOAuthRegistration
}
if (body.oauthProviders !== undefined) {
updateData.oauthProviders = body.oauthProviders
}
if (body.githubOAuthEnabled !== undefined) {
if (typeof body.githubOAuthEnabled !== 'boolean') {
throw createError({
statusCode: 400,
message: 'githubOAuthEnabled 必须是布尔值'
})
}
updateData.githubOAuthEnabled = body.githubOAuthEnabled
}
if (body.casdoorOAuthEnabled !== undefined) {
if (typeof body.casdoorOAuthEnabled !== 'boolean') {
throw createError({
statusCode: 400,
message: 'casdoorOAuthEnabled 必须是布尔值'
})
}
updateData.casdoorOAuthEnabled = body.casdoorOAuthEnabled
}
if (body.googleOAuthEnabled !== undefined) {
if (typeof body.googleOAuthEnabled !== 'boolean') {
throw createError({
statusCode: 400,
message: 'googleOAuthEnabled 必须是布尔值'
})
}
updateData.googleOAuthEnabled = body.googleOAuthEnabled
}
if (body.aggregateOAuthEnabled !== undefined) {
if (typeof body.aggregateOAuthEnabled !== 'boolean') {
throw createError({
statusCode: 400,
message: 'aggregateOAuthEnabled 必须是布尔值'
})
}
updateData.aggregateOAuthEnabled = body.aggregateOAuthEnabled
}
if (body.aggregateOAuthLoginType !== undefined) {
updateData.aggregateOAuthLoginType = body.aggregateOAuthLoginType
}
if (body.customOAuthEnabled !== undefined) {
if (typeof body.customOAuthEnabled !== 'boolean') {
throw createError({
statusCode: 400,
message: 'customOAuthEnabled 必须是布尔值'
})
}
updateData.customOAuthEnabled = body.customOAuthEnabled
}
if (body.captchaMaxFailures !== undefined) {
if (body.captchaMaxFailures !== null && (!Number.isInteger(body.captchaMaxFailures) || body.captchaMaxFailures < 0)) {
throw createError({
statusCode: 400,
message: 'captchaMaxFailures 必须是非负整数或null'
})
}
updateData.captchaMaxFailures = body.captchaMaxFailures
}
if (body.autoBackupEnabled !== undefined) {
if (typeof body.autoBackupEnabled !== 'boolean') {
throw createError({
statusCode: 400,
message: 'autoBackupEnabled 必须是布尔值'
})
}
updateData.autoBackupEnabled = body.autoBackupEnabled
}
if (body.autoBackupIntervalHours !== undefined) {
if (body.autoBackupIntervalHours !== null && (!Number.isInteger(body.autoBackupIntervalHours) || body.autoBackupIntervalHours < 0)) {
throw createError({
statusCode: 400,
message: 'autoBackupIntervalHours 必须是非负整数或null'
})
}
updateData.autoBackupIntervalHours = body.autoBackupIntervalHours
}
if (body.autoBackupRetentionDays !== undefined) {
if (body.autoBackupRetentionDays !== null && (!Number.isInteger(body.autoBackupRetentionDays) || body.autoBackupRetentionDays < 0)) {
throw createError({
statusCode: 400,
message: 'autoBackupRetentionDays 必须是非负整数或null'
})
}
updateData.autoBackupRetentionDays = body.autoBackupRetentionDays
}
if (body.statisticsCodeEnabled !== undefined) {
if (typeof body.statisticsCodeEnabled !== 'boolean') {
throw createError({
statusCode: 400,
message: 'statisticsCodeEnabled 必须是布尔值'
})
}
updateData.statisticsCodeEnabled = body.statisticsCodeEnabled
}
if (body.statisticsCodeBody !== undefined) {
updateData.statisticsCodeBody = body.statisticsCodeBody
}
if (body.statisticsCodeHead !== undefined) {
updateData.statisticsCodeHead = body.statisticsCodeHead
}
if (body.defaultTheme !== undefined) {
updateData.defaultTheme =
typeof body.defaultTheme === 'string' && body.defaultTheme.trim()
? body.defaultTheme.trim()
: null
}
if (body.enabledThemes !== undefined) {
updateData.enabledThemes =
body.enabledThemes === null || body.enabledThemes === undefined
? null
: typeof body.enabledThemes === 'string'
? body.enabledThemes
: JSON.stringify(body.enabledThemes)
}
// SMTP配置字段
if (body.smtpEnabled !== undefined) {
if (typeof body.smtpEnabled !== 'boolean') {
throw createError({
statusCode: 400,
message: 'smtpEnabled 必须是布尔值'
})
}
updateData.smtpEnabled = body.smtpEnabled
}
if (body.smtpHost !== undefined) {
updateData.smtpHost = body.smtpHost
}
if (body.smtpPort !== undefined) {
if (
body.smtpPort !== null &&
(!Number.isInteger(body.smtpPort) || body.smtpPort < 1 || body.smtpPort > 65535)
) {
throw createError({
statusCode: 400,
message: 'smtpPort 必须是1-65535之间的整数'
})
}
updateData.smtpPort = body.smtpPort
}
if (body.smtpSecure !== undefined) {
if (typeof body.smtpSecure !== 'boolean') {
throw createError({
statusCode: 400,
message: 'smtpSecure 必须是布尔值'
})
}
updateData.smtpSecure = body.smtpSecure
}
if (body.smtpUsername !== undefined) {
updateData.smtpUsername = body.smtpUsername
}
if (body.smtpPassword !== undefined && body.smtpPassword !== '****************') {
updateData.smtpPassword = body.smtpPassword
}
if (body.smtpFromEmail !== undefined) {
updateData.smtpFromEmail = body.smtpFromEmail
}
if (body.smtpFromName !== undefined) {
updateData.smtpFromName = body.smtpFromName
}
// 验证每日、每周和每月限额三选一逻辑
const limitSettings = [
body.dailySubmissionLimit,
body.weeklySubmissionLimit,
body.monthlySubmissionLimit
].filter((limit) => limit !== undefined && limit !== null)
if (body.enableSubmissionLimit && limitSettings.length > 1) {
throw createError({
statusCode: 400,
message: '每日限额、每周限额和每月限额只能选择其中一种,其他必须设置为空'
})
}
const DEFAULTS = {
submissionNoteRequiresApproval: false,
telemetryEnabled: true,
showBeianIcon: true,
scheduleDaysDisplay: 7,
scheduleDaysEditable: 3,
scheduleDaysRequestable: 14,
scheduleDaysBeforeEnabled: false,
scheduleDaysBefore: 1,
scheduleDaysAfterEnabled: false,
scheduleDaysAfter: 1,
forcePasswordChangeOnFirstLogin: false,
enableSubmissionRestriction: false,
submissionRestrictionScope: 'all',
cardCodeEnabled: false,
cardCodeSubmissionRequired: false,
cardCodeVoteEnabled: false,
cardCodeReplayEnabled: false,
enableCardCodeRequests: false,
requireCardCodeForRequests: false,
enableCardCodeLimitBypass: false,
submissionRestrictionEnabled: false,
submissionRestrictionGradeEnabled: false,
submissionRestrictionClassEnabled: false,
submissionRestrictionGraduateEnabled: false,
submissionRestrictionWithdrawnEnabled: false,
captchaProvider: 'TURNSTILE',
captchaEnabled: false,
allowRegister: true,
registerRequireEmail: false,
registerRequireEmailVerify: false,
registerDefaultRole: 'USER',
registerRequiresApproval: false,
oauthRegisterRequiresApproval: false,
registerEmailRequired: false,
registerRequiresGradeClass: false,
oauthEnabled: false,
oauthAllowRegister: true,
oauthAllowLogin: true,
oauthAllowBind: true,
allowOAuthRegistration: false,
oauthProviders: '[]',
githubOAuthEnabled: false,
casdoorOAuthEnabled: false,
googleOAuthEnabled: false,
aggregateOAuthEnabled: false,
aggregateOAuthLoginType: 'qq',
customOAuthEnabled: false,
captchaMaxFailures: 3,
autoBackupEnabled: false,
autoBackupIntervalHours: 24,
autoBackupRetentionDays: 30,
statisticsCodeEnabled: false,
defaultTheme: 'ClassicDark',
enabledThemes: '["System","ClassicDark","ClassicLight","ModernLight"]'
} as const
// 获取当前设置,如果不存在则创建
const settingsResult = await db.select().from(systemSettings).limit(1)
let settings = settingsResult[0] || null
const fillDefaults = (obj: any) => ({ ...obj, ...Object.fromEntries(Object.entries(DEFAULTS).filter(([k]) => !Object.prototype.hasOwnProperty.call(obj || {}, k) || (obj && obj[k] === undefined || obj[k] === null))) })
if (!settings) {
// 如果不存在,创建新设置
const newSettingsResult = await db
.insert(systemSettings)
.values({
hideStudentInfo: updateData.hideStudentInfo ?? false,
enablePlayTimeSelection: updateData.enablePlayTimeSelection ?? false,
siteTitle: updateData.siteTitle ?? '宝一外校园点歌系统',
siteLogoUrl: updateData.siteLogoUrl ?? '/favicon.ico',
schoolLogoHomeUrl: updateData.schoolLogoHomeUrl ?? null,
schoolLogoPrintUrl: updateData.schoolLogoPrintUrl ?? null,
siteDescription: updateData.siteDescription ?? '宝一外校园点歌系统 - 让你的声音被听见',
siteVersion: updateData.siteVersion ?? null,
submissionGuidelines:
updateData.submissionGuidelines ??
`1. 投稿时无需加入书名号
2. 除DJ外,其他类型歌曲均接收(包括小语种)
3. 禁止投递含有违规内容的歌曲
4. 点播的歌曲将由管理员进行审核
5. 审核通过后将安排在播放时段播出
6. 提交即表明我已阅读投稿须知并已知该歌曲有概率无法播出
7. 本系统仅提供音乐搜索和播放管理功能,不存储任何音乐文件。所有音乐内容均来自第三方音乐平台,版权归原平台及版权方所有。用户点歌时请确保遵守相关音乐平台的服务条款,尊重音乐作品版权。我们鼓励用户支持正版音乐,在官方平台购买和收听喜爱的音乐作品。
8. 最终解释权归广播站所有`,
icpNumber: updateData.icpNumber ?? null,
gonganNumber: updateData.gonganNumber ?? null,
enableSubmissionLimit: updateData.enableSubmissionLimit ?? false,
dailySubmissionLimit: updateData.dailySubmissionLimit ?? null,
weeklySubmissionLimit: updateData.weeklySubmissionLimit ?? null,
monthlySubmissionLimit: updateData.monthlySubmissionLimit ?? null,
showBlacklistKeywords: updateData.showBlacklistKeywords ?? false,
enableReplayRequests: updateData.enableReplayRequests ?? false,
enableCollaborativeSubmission: updateData.enableCollaborativeSubmission ?? true,
enableSubmissionRemarks: updateData.enableSubmissionRemarks ?? false,
enableRequestTimeLimitation: updateData.enableRequestTimeLimitation ?? false,
requestTimeLimitation: updateData.requestTimeLimitation ?? null,
forceBlockAllRequests: updateData.forceBlockAllRequests ?? false,
smtpEnabled: updateData.smtpEnabled ?? false,
smtpHost: updateData.smtpHost ?? null,
smtpPort: updateData.smtpPort ?? 587,
smtpSecure: updateData.smtpSecure ?? false,
smtpUsername: updateData.smtpUsername ?? null,
smtpPassword: updateData.smtpPassword ?? null,
smtpFromEmail: updateData.smtpFromEmail ?? null,
smtpFromName: updateData.smtpFromName ?? '校园广播站'
})
.returning()
settings = newSettingsResult[0]
} else {
// 如果存在,更新设置
const updatedSettingsResult = await db
.update(systemSettings)
.set(updateData)
.where(eq(systemSettings.id, settings.id))
.returning()
settings = fillDefaults(updatedSettingsResult[0])
}
// 清除系统设置缓存
try {
const { CacheService } = await import('~~/server/services/cacheService')
await CacheService.getInstance().clearSystemSettingsCache()
console.log('[Cache] 系统设置缓存已清除(更新系统设置)')
} catch (cacheError) {
console.warn('清除系统设置缓存失败:', cacheError)
}
try {
const { SmtpService } = await import('~~/server/services/smtpService')
await SmtpService.getInstance().initializeSmtpConfig()
console.log('[SMTP] SMTP配置已重新加载(更新系统设置)')
} catch (smtpError) {
console.warn('[SMTP] SMTP配置重载失败:', smtpError)
}
return settings
} catch (error) {
console.error('更新系统设置失败:', error)
if (error.statusCode) {
throw error
}
throw createError({
statusCode: 500,
message: '更新系统设置失败'
})
}
})