feat(songs): 歌曲管理支持批量驳回、投稿留言自动审查与排期范围可见性过滤
- 新增 /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 接入自动审查逻辑
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
import { createError, defineEventHandler, getQuery } from 'h3'
|
||||
import { db } from '~/drizzle/db'
|
||||
import { playTimes, schedules, songCollaborators, songs, users } from '~/drizzle/schema'
|
||||
import { playTimes, schedules, songCollaborators, songs, systemSettings, users } from '~/drizzle/schema'
|
||||
import { and, asc, desc, eq, gte, inArray, like, lt, or, sql } from 'drizzle-orm'
|
||||
import { formatDateTime } from '~/utils/timeUtils'
|
||||
import { openApiCache } from '~~/server/utils/open-api-cache'
|
||||
import { CACHE_CONSTANTS } from '~~/server/config/constants'
|
||||
import { cacheService } from '~~/server/services/cacheService'
|
||||
import { executeRedisCommand, isRedisReady } from '~~/server/utils/redis'
|
||||
import {
|
||||
resolveScheduleVisibilityRange,
|
||||
isPlayDateInRange,
|
||||
type VisibilitySettingsLike
|
||||
} from '~~/server/utils/schedule-visibility'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
try {
|
||||
@@ -36,6 +41,27 @@ export default defineEventHandler(async (event) => {
|
||||
const sortBy = (query.sortBy as string) || 'playDate'
|
||||
const sortOrder = (query.sortOrder as string) || 'asc'
|
||||
|
||||
// 读取系统设置:排期可见范围
|
||||
let visibilityRange = { startAt: null as Date | null, endAt: null as Date | null }
|
||||
try {
|
||||
const systemSettingsDataResult = await db.select().from(systemSettings).limit(1)
|
||||
const systemSettingsData = systemSettingsDataResult[0] || null
|
||||
const visibilitySettings: VisibilitySettingsLike = {
|
||||
scheduleDaysBeforeEnabled: systemSettingsData?.scheduleDaysBeforeEnabled,
|
||||
scheduleDaysBefore: systemSettingsData?.scheduleDaysBefore,
|
||||
scheduleDaysAfterEnabled: systemSettingsData?.scheduleDaysAfterEnabled,
|
||||
scheduleDaysAfter: systemSettingsData?.scheduleDaysAfter
|
||||
}
|
||||
visibilityRange = resolveScheduleVisibilityRange(visibilitySettings)
|
||||
} catch (err) {
|
||||
console.warn('[Schedules API] 读取排期可见范围设置失败,将展示全部:', err)
|
||||
}
|
||||
|
||||
const applyVisibilityFilter = (items: any[]): any[] => {
|
||||
if (!visibilityRange.startAt && !visibilityRange.endAt) return items
|
||||
return items.filter((s) => isPlayDateInRange(s.playDate, visibilityRange))
|
||||
}
|
||||
|
||||
// 优先从普通API缓存获取数据
|
||||
|
||||
// 尝试从CacheService获取排期数据
|
||||
@@ -49,6 +75,7 @@ export default defineEventHandler(async (event) => {
|
||||
if (semester) {
|
||||
filteredSchedules = cachedSchedules.filter((s) => s.song?.semester === semester)
|
||||
}
|
||||
filteredSchedules = applyVisibilityFilter(filteredSchedules)
|
||||
|
||||
// 转换为开放API格式
|
||||
const result = {
|
||||
@@ -105,11 +132,12 @@ export default defineEventHandler(async (event) => {
|
||||
})
|
||||
|
||||
if (redisData) {
|
||||
const filteredRedisData = applyVisibilityFilter(redisData)
|
||||
// 转换为开放API格式
|
||||
const result = {
|
||||
success: true,
|
||||
data: {
|
||||
schedules: redisData.map((schedule: any) => ({
|
||||
schedules: filteredRedisData.map((schedule: any) => ({
|
||||
id: schedule.id,
|
||||
playDate: schedule.playDate,
|
||||
sequence: schedule.sequence,
|
||||
@@ -133,7 +161,7 @@ export default defineEventHandler(async (event) => {
|
||||
}
|
||||
: null
|
||||
})),
|
||||
total: redisData.length,
|
||||
total: filteredRedisData.length,
|
||||
semester: semester || null
|
||||
}
|
||||
}
|
||||
@@ -175,6 +203,13 @@ export default defineEventHandler(async (event) => {
|
||||
conditions.push(or(like(songs.title, `%${search}%`)!, like(songs.artist, `%${search}%`)!)!)
|
||||
}
|
||||
|
||||
if (visibilityRange.startAt) {
|
||||
conditions.push(gte(schedules.playDate, visibilityRange.startAt)!)
|
||||
}
|
||||
if (visibilityRange.endAt) {
|
||||
conditions.push(lt(schedules.playDate, visibilityRange.endAt)!)
|
||||
}
|
||||
|
||||
const whereCondition = conditions.length > 0 ? and(...conditions) : undefined
|
||||
|
||||
// 计算偏移量
|
||||
|
||||
Reference in New Issue
Block a user