feat: 迁移自定义功能至 1.5.9.9 版本
包含音乐源限制、CI 防 OOM 优化、数据库连接池优化、管理端权限及 UI 细节定制等功能
This commit is contained in:
@@ -4,7 +4,7 @@ import { and, count, db, eq, exists, schedules, semesters, songs, votes } from '
|
||||
export default defineEventHandler(async (event) => {
|
||||
// 检查认证和权限
|
||||
const user = event.context.user
|
||||
if (!user || !['SONG_ADMIN', 'ADMIN', 'SUPER_ADMIN'].includes(user.role)) {
|
||||
if (!user || !['ADMIN', 'SUPER_ADMIN'].includes(user.role)) {
|
||||
throw createError({
|
||||
statusCode: 403,
|
||||
message: '需要管理员权限'
|
||||
@@ -19,28 +19,30 @@ export default defineEventHandler(async (event) => {
|
||||
const semesterStats = await Promise.all(
|
||||
semesterList.map(async (semester) => {
|
||||
// 统计该学期的歌曲数量
|
||||
const totalSongsResult = await db
|
||||
.select({ count: count() })
|
||||
.from(songs)
|
||||
.where(eq(songs.semester, semester.name))
|
||||
const [totalSongsResult, totalSchedulesResult, totalRequestsResult] = await Promise.all([
|
||||
db
|
||||
.select({ count: count() })
|
||||
.from(songs)
|
||||
.where(eq(songs.semester, semester.name)),
|
||||
|
||||
// 统计该学期的排期数量(通过关联歌曲)
|
||||
const totalSchedulesResult = await db
|
||||
.select({ count: count() })
|
||||
.from(schedules)
|
||||
.innerJoin(songs, eq(schedules.songId, songs.id))
|
||||
.where(eq(songs.semester, semester.name))
|
||||
// 统计该学期的排期数量(通过关联歌曲)
|
||||
db
|
||||
.select({ count: count() })
|
||||
.from(schedules)
|
||||
.innerJoin(songs, eq(schedules.songId, songs.id))
|
||||
.where(eq(songs.semester, semester.name)),
|
||||
|
||||
// 统计该学期有投票的歌曲数量
|
||||
const totalRequestsResult = await db
|
||||
.select({ count: count() })
|
||||
.from(songs)
|
||||
.where(
|
||||
and(
|
||||
eq(songs.semester, semester.name),
|
||||
exists(db.select().from(votes).where(eq(votes.songId, songs.id)))
|
||||
// 统计该学期有投票的歌曲数量
|
||||
db
|
||||
.select({ count: count() })
|
||||
.from(songs)
|
||||
.where(
|
||||
and(
|
||||
eq(songs.semester, semester.name),
|
||||
exists(db.select().from(votes).where(eq(votes.songId, songs.id)))
|
||||
)
|
||||
)
|
||||
)
|
||||
])
|
||||
|
||||
const [totalSongs, totalSchedules, totalRequests] = [
|
||||
totalSongsResult[0]?.count || 0,
|
||||
|
||||
Reference in New Issue
Block a user