feat: 迁移自定义功能至 1.5.9.9 版本
包含音乐源限制、CI 防 OOM 优化、数据库连接池优化、管理端权限及 UI 细节定制等功能
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { asc, db, desc, playTimes } from '~/drizzle/db'
|
||||
import { CacheService } from '../../../services/cacheService'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
// 检查用户认证和权限
|
||||
@@ -11,7 +12,7 @@ export default defineEventHandler(async (event) => {
|
||||
})
|
||||
}
|
||||
|
||||
if (!['SONG_ADMIN', 'ADMIN', 'SUPER_ADMIN'].includes(user.role)) {
|
||||
if (!['ADMIN', 'SUPER_ADMIN'].includes(user.role)) {
|
||||
throw createError({
|
||||
statusCode: 403,
|
||||
message: '只有管理员才能管理播出时段'
|
||||
@@ -19,11 +20,27 @@ export default defineEventHandler(async (event) => {
|
||||
}
|
||||
|
||||
try {
|
||||
// 尝试从缓存获取播放时间数据
|
||||
const cacheService = CacheService.getInstance()
|
||||
const cachedPlayTimes = await cacheService.getPlayTimes()
|
||||
|
||||
if (cachedPlayTimes) {
|
||||
return cachedPlayTimes
|
||||
}
|
||||
|
||||
// 缓存中没有,从数据库获取所有播出时段
|
||||
const playTimesResult = await db
|
||||
.select()
|
||||
.from(playTimes)
|
||||
.orderBy(desc(playTimes.enabled), asc(playTimes.startTime))
|
||||
|
||||
// 将数据存入缓存
|
||||
try {
|
||||
await cacheService.setPlayTimes(playTimesResult)
|
||||
} catch (cacheError) {
|
||||
console.warn('缓存播放时间数据失败:', cacheError)
|
||||
}
|
||||
|
||||
return playTimesResult
|
||||
} catch (error) {
|
||||
console.error('获取播出时段失败:', error)
|
||||
|
||||
Reference in New Issue
Block a user