퀴즈 파일 A단계: 관리자 → 퀴즈 '파일로 만들기'(.xlsx·.csv를 브라우저가 라이브러리 없이 읽음, 열 이름으로 링크·정답·설명·힌트·순번 인식, 시트 선택, 잘못된 링크·중복 영상 표시), 편집 화면 '파일에서 가져오기'(뒤에 추가·목록 바꾸기)·'엑셀로 내보내기'·빈 양식. 파일 곡은 적힌 값 그대로(DB 연결·검토 대기 없음). 곡별 힌트를 하나씩 보여 준 뒤 초성 힌트(자동은 N초마다, 투표는 한 번에 하나)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-23 18:06:28 +09:00
parent e44df482a6
commit 3c5e26f9b7
23 changed files with 1285 additions and 55 deletions

View File

@@ -4,7 +4,7 @@
*/
import type { Context, Hono } from 'hono';
import { z } from 'zod';
import { QuizSaveSchema, songMatchKey, type Role } from '@mq/shared';
import { DEFAULT_QUIZ_SETTINGS, QuizSaveSchema, songMatchKey, type Role } from '@mq/shared';
import type { Database } from 'bun:sqlite';
import { CustomQuizzes, type QuizLimits } from '../quizzes/store';
import type { YtmSong } from '../collector/ytmusic';
@@ -63,6 +63,24 @@ export function mountQuizAdmin(app: Hono<Env>, d: QuizAdminDeps, h: { actor: (c:
return c.json({ id });
});
/** 파일로 만들기: a new quiz with the songs read from a file (the browser reads the file; values used as written). */
app.post('/quizzes/file', async (c) => {
const p = z.object({ name: z.string().trim().min(1).max(60), items: QuizSaveSchema.shape.items.min(1) }).safeParse(await h.body(c));
if (!p.success) return c.json({ error: `만들 내용이 올바르지 않아요: ${p.error.issues.slice(0, 3).map((i) => i.path.join('.') || i.message).join(', ')}` }, 400);
const limits = d.limits();
if (limits.maxSongs && p.data.items.length > limits.maxSongs) return c.json({ error: `퀴즈 하나에는 곡을 ${limits.maxSongs}곡까지 넣을 수 있어요.` }, 400);
const id = d.quizzes.create(h.actor(c), p.data.name, limits);
if (typeof id === 'string') return c.json({ error: id }, 400);
const items = p.data.items.map((it) => ({ ...it, id: undefined, songId: null, fromFile: true }));
// songs with their own hints: hints come by vote unless the maker changes it in 설정
const settings = { ...DEFAULT_QUIZ_SETTINGS, ...(items.some((it) => it.hints.length) ? { hint: 'manual' as const } : {}) };
const saved = d.quizzes.save(id, { name: p.data.name, description: '', visibility: 'private', settings, items }, limits);
if (typeof saved === 'string') return c.json({ error: saved }, 400);
d.audit.log(h.actor(c), 'quiz.create', String(id), null, { name: p.data.name, songs: items.length, from: 'file' });
d.onChange?.();
return c.json({ id });
});
// ---------------------------------------------------------------- 검토 대기 (전체공개 퀴즈 → 서버 노래 DB)
app.get('/reviews/count', (c) => {
const levels = playStats(d.db, { sort: 'suggest', size: 1 }).suggestions;