chenpei 3fff87cd18 feat: 添加S3存储桶配置、全站实时弹幕功能、LOGO分离上传
新功能:
1. S3存储桶配置管理 - 可在系统设置中配置S3端点、密钥等
2. 全站实时弹幕功能 - 右下角悬浮球,支持实时发送和接收弹幕
3. LOGO分离上传 - 导航栏LOGO和登录页LOGO分开上传

数据库更新:
- SystemSettings表新增s3Endpoint, s3AccessKey, s3SecretKey等6个字段
- 新增Danmaku表用于存储弹幕数据

技术改进:
- 部门管理从系统设置移至系统管理标签页
- 优化了浏览器标题动态更新
- 添加了弹幕轮询机制(2秒)
2025-10-27 17:06:54 +08:00

102 lines
3.2 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import { getServerSession } from 'next-auth'
import { authOptions } from '@/lib/auth'
import { prisma } from '@/lib/prisma'
// GET - 获取系统设置
export async function GET() {
try {
// 获取或创建系统设置
let settings = await prisma.systemSettings.findFirst()
if (!settings) {
// 如果不存在,创建默认设置
settings = await prisma.systemSettings.create({
data: {
headerBgColor: '#1f2937',
headerLogoUrl: 'http://s3.1080p.hk/shuzhou/2025/05/18/8ebadf0a7cc34eaea00e8619b8efb827.png',
loginLogoUrl: 'http://s3.1080p.hk/shuzhou/2025/05/18/8ebadf0a7cc34eaea00e8619b8efb827.png',
siteName: '由壹点3D素材'
}
})
}
return NextResponse.json(settings)
} catch (error) {
console.error('Get system settings error:', error)
return NextResponse.json(
{ error: '获取系统设置失败' },
{ status: 500 }
)
}
}
// PUT - 更新系统设置(仅管理员)
export async function PUT(request: NextRequest) {
try {
const session = await getServerSession(authOptions)
if (!session || session.user.role !== 'ADMIN') {
return NextResponse.json(
{ error: '无权限' },
{ status: 403 }
)
}
const body = await request.json()
const {
headerBgColor,
siteName,
headerLogoUrl,
loginLogoUrl,
s3Endpoint,
s3AccessKey,
s3SecretKey,
s3Bucket,
s3Region,
s3PublicUrl
} = body
// 获取或创建系统设置
let settings = await prisma.systemSettings.findFirst()
if (!settings) {
// 创建
settings = await prisma.systemSettings.create({
data: {
headerBgColor: headerBgColor || '#1f2937',
headerLogoUrl: headerLogoUrl || 'http://s3.1080p.hk/shuzhou/2025/05/18/8ebadf0a7cc34eaea00e8619b8efb827.png',
loginLogoUrl: loginLogoUrl || 'http://s3.1080p.hk/shuzhou/2025/05/18/8ebadf0a7cc34eaea00e8619b8efb827.png',
siteName: siteName || '由壹点3D素材'
}
})
} else {
// 更新
const updateData: any = {}
if (headerBgColor !== undefined) updateData.headerBgColor = headerBgColor
if (siteName !== undefined) updateData.siteName = siteName
if (headerLogoUrl !== undefined) updateData.headerLogoUrl = headerLogoUrl
if (loginLogoUrl !== undefined) updateData.loginLogoUrl = loginLogoUrl
if (s3Endpoint !== undefined) updateData.s3Endpoint = s3Endpoint
if (s3AccessKey !== undefined) updateData.s3AccessKey = s3AccessKey
if (s3SecretKey !== undefined) updateData.s3SecretKey = s3SecretKey
if (s3Bucket !== undefined) updateData.s3Bucket = s3Bucket
if (s3Region !== undefined) updateData.s3Region = s3Region
if (s3PublicUrl !== undefined) updateData.s3PublicUrl = s3PublicUrl
settings = await prisma.systemSettings.update({
where: { id: settings.id },
data: updateData
})
}
return NextResponse.json(settings)
} catch (error) {
console.error('Update system settings error:', error)
return NextResponse.json(
{ error: '更新系统设置失败' },
{ status: 500 }
)
}
}