엑셀 양식 2단계: 일반 퀴즈 파일을 제목·가수·정답·가수 정답으로 나눔(정답은 ;로 여러 개, 제목·가수는 늘 정답, 내보내기는 제목·가수를 정답 칸 맨 앞에), 길이·비고 열. 예전 양식(정답=제목·설명·다른 정답)은 '제목' 열이 없으면 그대로 읽음. 파일 제목도 괄호·feat.·버전 표시를 지우고 괄호 안 다른 이름은 정답으로. 정답·가수 정답 칸이 빈 곡은 서버가 채움(POST /api/admin/quizzes/answers — 제목 정리 별칭 + 같은 DB 곡 별칭, answers/index.ts). 재생목록으로 엑셀 만들기: 일반 퀴즈용(정답·가수 정답·힌트)과 이지선다용(빈 조회수 열 → 파일로 만들기가 이지선다로 고름) 두 양식, 플레이리스트 가져오기 결과에 정리된 제목과 정답. 단위·API 테스트, e2e quiz(두 양식 받기)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-11-04 16:00:33 +09:00
parent 2e333dd3f7
commit 74eaeb85da
11 changed files with 331 additions and 117 deletions

View File

@@ -16,6 +16,7 @@ import { getImportJob, startImport, type Lavalink } from '../quizzes/playlist';
import { applyReview, listReviews, pendingCount, rejectReview, syncReviews } from '../quizzes/review';
import { checkEmbed, type EmbedState } from '../collector/oembed';
import { DuelViewsJob, type ViewsSource } from '../quizzes/duel-views';
import { songAnswers } from '../answers';
type Env = { Variables: { userId: string | null; role: Role } };
@@ -246,6 +247,24 @@ export function mountQuizAdmin(app: Hono<Env>, d: QuizAdminDeps, h: { actor: (c:
return job ? c.json({ job }) : c.json({ error: '가져오기 작업을 찾을 수 없어요.' }, 404);
});
/**
* 정답 자동 채우기 (파일로 만들기·파일에서 가져오기, docs/13): answers for songs whose 정답 / 가수 정답 cells were empty.
* A song the server DB has (same title + artist) lends its aliases too.
*/
app.post('/quizzes/answers', async (c) => {
const p = z
.object({ songs: z.array(z.object({ title: z.string().max(200), artist: z.string().max(200).default('') })).max(1000) })
.safeParse(await h.body(c));
if (!p.success) return c.json({ error: '입력 값이 올바르지 않아요.' }, 400);
const byKey = d.db.query<{ id: number }, [string]>('SELECT id FROM songs WHERE match_key = ? AND deleted_at IS NULL ORDER BY id LIMIT 1');
const answers = p.data.songs.map((s) => {
const songId = s.artist ? (byKey.get(songMatchKey(s.title, s.artist))?.id ?? null) : null;
const a = songAnswers(d.db, { ...s, songId });
return { titleAnswers: a.titleAnswers, artistAnswers: a.artistAnswers };
});
return c.json({ answers });
});
/** DB facts of songs just added in the editor (before saving): aliases and the DB highlight for 자동. */
app.get('/quizzes/pick/songs', (c) => {
const ids = (c.req.query('ids') ?? '').split(',').map(Number).filter((x) => Number.isInteger(x) && x > 0).slice(0, 500);