제작된 퀴즈 5단계: 검토 대기(전체공개 퀴즈 → 서버 노래 DB). 저장할 때 DB에 없는 곡과 영상·제목·가수·직접 정한 하이라이트가 DB와 다른 곡을 모아 관리자가 항목마다 DB 유지/퀴즈 값을 고르거나 새 곡을 연도·장르·난이도와 함께 추가(퀴즈 곡이 그 DB 곡에 연결). 복수정답은 DB 별칭에, 한 번 정한 값은 다시 묻지 않음. 관리자 메뉴 '검토 대기'(개수 표시), 처리한 것 기록·감사 로그

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-22 13:07:41 +09:00
parent 4a40be696b
commit b999310eb9
10 changed files with 632 additions and 4 deletions

View File

@@ -12,6 +12,7 @@ import { pickSearcher } from '../collector/ytmusic';
import { listSongs } from '../songs/store';
import { audioFile, type AudioLinks } from '../songs/audio';
import { getImportJob, startImport, type Lavalink } from '../quizzes/playlist';
import { applyReview, listReviews, pendingCount, rejectReview, syncReviews } from '../quizzes/review';
import { checkEmbed, type EmbedState } from '../collector/oembed';
type Env = { Variables: { userId: string | null; role: Role } };
@@ -61,6 +62,48 @@ export function mountQuizAdmin(app: Hono<Env>, d: QuizAdminDeps, h: { actor: (c:
return c.json({ id });
});
// ---------------------------------------------------------------- 검토 대기 (전체공개 퀴즈 → 서버 노래 DB)
app.get('/reviews/count', (c) => c.json({ pending: pendingCount(d.db) }));
app.get('/reviews', (c) => c.json({ reviews: listReviews(d.db, c.req.query('status') === 'done' ? 'done' : 'pending'), pending: pendingCount(d.db) }));
app.post('/reviews/:id/apply', async (c) => {
const id = Number(c.req.param('id'));
const p = z
.object({
take: z.array(z.enum(['title', 'artist', 'video', 'highlight'])).optional(),
song: z
.object({
title: z.string().trim().max(200).optional(),
artist: z.string().trim().max(200).optional(),
year: z.number().int().min(1900).max(2100).nullable().optional(),
genres: z.array(z.string().max(30)).max(20).optional(),
level: z.number().int().min(1).max(10).nullable().optional(),
})
.optional(),
})
.safeParse(await h.body(c));
if (!p.success) return c.json({ error: '입력 값이 올바르지 않아요.' }, 400);
const r = listReviews(d.db).find((x) => x.id === id);
if (!r) return c.json({ error: '이미 처리했거나 없는 검토예요.' }, 404);
// a video that becomes the DB video is checked like any admin edit
let embed: { author: string; title: string } | undefined;
if (r.kind === 'new' || p.data.take?.includes('video')) {
const v = await d.videoOf(r.proposal.videoId);
if (typeof v === 'string') return c.json({ error: v }, 400);
embed = { author: v.author, title: v.title };
}
const result = applyReview(d.db, id, p.data, h.actor(c), embed);
if (result.startsWith('!')) return c.json({ error: result.slice(1) }, 400);
d.audit.log(h.actor(c), 'review.apply', String(id), { quiz: r.quiz.name, song: r.db?.id ?? null }, { result, take: p.data.take ?? null });
d.onChange?.();
return c.json({ ok: true, result, pending: pendingCount(d.db) });
});
app.post('/reviews/:id/reject', (c) => {
const id = Number(c.req.param('id'));
if (!rejectReview(d.db, id, h.actor(c))) return c.json({ error: '이미 처리했거나 없는 검토예요.' }, 404);
d.audit.log(h.actor(c), 'review.reject', String(id), null, null);
return c.json({ ok: true, pending: pendingCount(d.db) });
});
// ---------------------------------------------------------------- song pickers (before /quizzes/:id)
/** 서버 노래 검색: title/artist/초성, songs with a confirmed video first. */
app.get('/quizzes/pick/db', (c) => {
@@ -188,15 +231,18 @@ export function mountQuizAdmin(app: Hono<Env>, d: QuizAdminDeps, h: { actor: (c:
if (!p.success) return c.json({ error: `저장할 내용이 올바르지 않아요: ${p.error.issues.slice(0, 3).map((i) => i.path.join('.')).join(', ')}` }, 400);
const saved = d.quizzes.save(q.id, p.data, d.limits());
if (typeof saved === 'string') return c.json({ error: saved }, 400);
// 전체공개: songs that differ from the server DB wait for an admin (검토 대기)
const reviews = syncReviews(d.db, q.id);
d.audit.log(h.actor(c), 'quiz.save', String(q.id), { name: q.name, songs: q.songs, visibility: q.visibility }, { name: saved.name, songs: saved.items.length, visibility: saved.visibility });
d.onChange?.();
return c.json({ quiz: saved });
return c.json({ quiz: saved, reviews });
});
app.delete('/quizzes/:id', (c) => {
const q = mine(c);
if (!q) return c.json({ error: '퀴즈를 찾을 수 없어요.' }, 404);
d.quizzes.remove(q.id);
syncReviews(d.db, q.id);
d.audit.log(h.actor(c), 'quiz.delete', String(q.id), { name: q.name, songs: q.songs }, null);
d.onChange?.();
return c.json({ ok: true });