엑셀 양식 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

@@ -1,7 +1,8 @@
/**
* 재생목록으로 엑셀 만들기 (관리자 → 퀴즈): a playlist address → the server checks every song (플레이리스트 가져오기의 같은
* 작업: 서버 DB 곡, 영상 제목 정리, 스포티파이는 유튜브 뮤직에서 찾기, 다른 사이트 재생 확인) → a quiz file to fill in
* 시작·하이라이트 and upload with 파일로 만들기 (일반 or 이지선다). Songs that would not play go to the sheet 빠진 곡.
* 시작·하이라이트 and upload with 파일로 만들기. Two forms (docs/13): 일반 퀴즈 (제목·가수·정답·가수 정답·힌트) and
* 이지선다 (제목·가수·an empty 조회수 column). Songs that would not play go to the sheet 빠진 곡.
*/
import { useEffect, useMemo, useState } from 'react';
import { playlistSheets, writeXlsxSheets, type PlaylistSheetRow } from '@mq/shared/lite';
@@ -57,9 +58,10 @@ export function PlaylistSheet({ onClose }: { onClose: () => void }) {
}
};
const sheets = useMemo(() => (job?.status === 'done' ? playlistSheets(job.rows) : null), [job]);
const duelSheets = useMemo(() => (job?.status === 'done' ? playlistSheets(job.rows, 'duel') : null), [job]);
const kept = sheets ? sheets[0]!.rows.slice(1) : [];
const left = sheets ? sheets[1]!.rows.slice(1) : [];
const toCheck = kept.filter((r) => String(r[7] ?? '').includes('확인 필요')).length;
const toCheck = kept.filter((r) => String(r[r.length - 1] ?? '').includes('확인 필요')).length;
const fileName = job?.name.trim() || '재생목록 퀴즈';
return (
<div className="card stack" style={{ gap: 10 }}>
@@ -82,9 +84,13 @@ export function PlaylistSheet({ onClose }: { onClose: () => void }) {
</button>
</form>
<p className="muted small" style={{ margin: 0 }}>
곡마다 서버 노래 DB, 영상 제목, 다른 사이트 재생 여부를 확인해서 <b>순번 · 유튜브 영상 링크 · 제목 · 가수 · 시작(초) · 하이라이트(초) · 길이(초) · 비고</b> 엑셀을
만들어요. 시작·하이라이트를 채우고(비워 두면 올릴 때 자동 / 처음부터 중에 골라요) <b>파일로 만들기</b>에 그대로 올리면 돼요. 일반 퀴즈는 제목이 정답, 가수가 정답 공개 때
같이 보이는 설명이 되고, 이지선다는 조회수를 서버가 불러와요. 재생이 막혔거나 없는 영상, 같은 영상은 <b>빠진 곡</b> 시트로 옮겨요.
곡마다 서버 노래 DB, 영상 제목, 다른 사이트 재생 여부를 확인해서 엑셀을 만들어요. 제목의 괄호·feat.·버전 표시는 지우고, 정답으로 인정할 다른 표기는{' '}
<b>정답 · 가수 정답</b> 열에 ;로 나눠 적어 둬요(제목·가수는 적지 않아도 늘 정답이에요). 양식은 두 가지예요.
<br />· <b>일반 퀴즈용</b>: 순번 · 링크 · 제목 · 가수 · 정답 · 가수 정답 · 힌트 · 시작(초) · 하이라이트(초) · 길이(초) · 비고
<br />· <b>이지선다용</b>: 순번 · 링크 · 제목 · 가수 · 조회수 · 시작(초) · 하이라이트(초) · 길이(초) · 비고 — 조회수는 비워 두면 서버가 불러와요
<br />
시작·하이라이트를 채우고(비워 두면 올릴 때 자동 / 처음부터 중에 골라요) <b>파일로 만들기</b>에 그대로 올리면 돼요. 재생이 막혔거나 없는 영상, 같은 영상은{' '}
<b>빠진 곡</b> 시트로 옮겨요.
</p>
{job && (
<div className="stack" style={{ gap: 4 }}>
@@ -129,7 +135,10 @@ export function PlaylistSheet({ onClose }: { onClose: () => void }) {
)}
<div className="row">
<button type="button" className="btn btn-primary" disabled={!kept.length && !left.length} onClick={() => download(fileName, writeXlsxSheets(sheets))}>
📥 엑셀 받기 ({kept.length}곡)
📥 일반 퀴즈용 엑셀 ({kept.length}곡)
</button>
<button type="button" className="btn" disabled={!kept.length && !left.length} onClick={() => download(`${fileName} (이지선다)`, writeXlsxSheets(duelSheets!))}>
📥 이지선다용 엑셀 ({kept.length}곡)
</button>
{toCheck > 0 && <span className="muted small">비고에 "확인 필요"라고 적힌 곡은 영상을 보고 제목·가수를 고쳐 주세요.</span>}
</div>

View File

@@ -1,9 +1,10 @@
/**
* 퀴즈 파일 (관리자 → 퀴즈): 파일로 만들기 (a new quiz from .xlsx / .csv), 파일에서 가져오기 (into the open quiz),
* 엑셀로 내보내기 and 빈 양식. The browser reads the file; columns are recognised by their headers and can be changed.
* Values are used as written — bad links and repeated videos are listed and left out.
* Values are used as written — bad links and repeated videos are listed and left out. 일반 퀴즈 songs whose 정답 /
* 가수 정답 cells are empty get answers worked out by the server (docs/13).
*/
import { useMemo, useState } from 'react';
import { useEffect, useMemo, useState } from 'react';
import {
DUEL_COLUMN_LABEL,
QUIZ_COLUMN_LABEL,
@@ -23,6 +24,7 @@ import {
type Sheet,
} from '@mq/shared/lite';
import { toast } from '../../store/toast';
import { apiCall } from '../../net/api';
import { ConfirmSheet } from '../../components/ui';
import { Seg } from '../../components/RoomSettings';
@@ -112,7 +114,38 @@ export function QuizFileImport({
const missing = (['link', 'answer'] as const).filter((c) => !columns.includes(c));
const duel = kind === 'duel';
const bad = parsed?.rows.filter((r) => r.problem) ?? [];
const items = parsed?.items ?? [];
// 정답 자동 채우기: the songs whose 정답 / 가수 정답 cells were empty, answered by the server
const toFill = useMemo(() => (duel ? [] : (parsed?.rows ?? []).filter((r) => r.item && (r.fill.title || r.fill.artist))), [parsed, duel]);
const fillKey = (it: { title: string; artist: string }) => `${it.title}\u0000${it.artist}`;
const [filled, setFilled] = useState<Record<string, { titleAnswers: string[]; artistAnswers: string[] }>>({});
const [filling, setFilling] = useState(false);
useEffect(() => {
const want = [...new Map(toFill.map((r) => [fillKey(r.item!), { title: r.item!.title, artist: r.item!.artist }])).values()].filter((x) => !filled[fillKey(x)]);
if (!want.length) return;
let live = true;
setFilling(true);
apiCall<{ answers: { titleAnswers: string[]; artistAnswers: string[] }[] }>('POST', '/api/admin/quizzes/answers', { songs: want.slice(0, 1000) })
.then((r) => live && setFilled((cur) => ({ ...cur, ...Object.fromEntries(want.map((x, i) => [fillKey(x), r.answers[i] ?? { titleAnswers: [], artistAnswers: [] }])) })))
.catch((e: Error) => live && toast(`정답 자동 채우기를 못 했어요(적힌 정답만 써요): ${e.message}`, 'error'))
.finally(() => live && setFilling(false));
return () => {
live = false;
};
}, [toFill]); // eslint-disable-line react-hooks/exhaustive-deps
const items = useMemo(() => {
const fill = new Map(toFill.map((r) => [r.item!, r.fill]));
return (parsed?.items ?? []).map((it) => {
const f = fill.get(it);
const got = f && filled[fillKey(it)];
if (!f || !got) return it;
const merge = (a: string[], b: string[], except: string) => [...new Set([...a, ...b])].filter((x) => x !== except).slice(0, 30);
return {
...it,
titleAnswers: f.title ? merge(it.titleAnswers, got.titleAnswers, it.title) : it.titleAnswers,
artistAnswers: f.artist ? merge(it.artistAnswers, got.artistAnswers, it.artist) : it.artistAnswers,
};
});
}, [parsed, toFill, filled]);
const inList = new Set(existing.map((x) => x.videoId));
const appendable = items.filter((x) => !inList.has(x.videoId));
const width = Math.max(header.length, ...(sheet?.rows.slice(headerAt, headerAt + 20).map((r) => r.length) ?? [0]));
@@ -189,8 +222,10 @@ export function QuizFileImport({
)}
{!file && !duel && (
<p className="muted small" style={{ margin: 0 }}>
한 줄에 한 곡씩, 첫 줄은 열 이름이에요. <b>유튜브 영상 링크</b>와 <b>정답</b>(예: 게임 제목)은 꼭 있어야 하고, <b>설명</b>(예: 노래 제목)은 정답을 공개할 때 같이
보여요. <b>힌트</b> 열은 문제마다 먼저 나오고, 그다음 힌트로 초성이 나와요. <b>순번</b> 열이 있으면 그 순서대로 넣어요. 적힌 값은 고치지 않고 그대로 써요.
한 줄에 한 곡씩, 첫 줄은 열 이름이에요. <b>유튜브 영상 링크</b>와 <b>제목</b>은 꼭 있어야 하고, <b>가수</b>는 정답을 공개할 때 같이 보여요. 제목·가수는 늘
정답이고, <b>정답 · 가수 정답</b> 열에 다른 표기를 ;로 나눠 적으면(예: 라일락; LILAC) 그것도 정답이 돼요. 이 칸이 비어 있으면 서버가 다른 표기(괄호 안 이름, 한글
발음 등)를 자동으로 채워요. 제목의 괄호·feat.·버전 표시는 지워서 보여 줘요. <b>힌트</b> 열은 문제마다 먼저 나오고, 그다음 힌트로 초성이 나와요. <b>순번</b> 열이
있으면 그 순서대로 넣어요. 예전 양식(정답 · 설명 · 다른 정답)도 그대로 읽어요.
</p>
)}
{file && sheet && (
@@ -235,6 +270,7 @@ export function QuizFileImport({
<b>{items.length}곡</b>
{bad.length > 0 && <span className="warn-text"> · 빠지는 줄 {bad.length}개</span>}
{mode === 'into' && items.length > appendable.length && <span className="muted"> · 이미 목록에 있는 영상 {items.length - appendable.length}곡</span>}
{toFill.length > 0 && <span className="muted"> · 정답 칸이 빈 곡 {toFill.length}곡{filling ? ' (자동으로 채우는 중…)' : ' (자동으로 채웠어요)'}</span>}
</div>
{blankCount > 0 && (
<div className="stack" style={{ gap: 4 }}>
@@ -288,8 +324,8 @@ export function QuizFileImport({
<thead>
<tr>
<th style={{ width: 44 }}>#</th>
<th>{duel ? '제목' : '정답'}</th>
<th>{duel ? '가수' : '설명'}</th>
<th>제목</th>
<th>가수</th>
<th>{duel ? '조회수' : '힌트'}</th>
<th>영상</th>
</tr>
@@ -302,7 +338,10 @@ export function QuizFileImport({
<b>{it.title}</b>
{it.titleAnswers.length > 0 && <div className="muted small">또는 {it.titleAnswers.join(', ')}</div>}
</td>
<td className="small">{it.artist || <span className="muted">-</span>}</td>
<td className="small">
{it.artist || <span className="muted">-</span>}
{it.artistAnswers.length > 0 && <div className="muted small">또는 {it.artistAnswers.join(', ')}</div>}
</td>
{duel ? (
<td className="small mono" title={it.views !== null ? `${it.views.toLocaleString('ko-KR')}회 (파일에 적힌 값)` : '올린 뒤 토픽 + MV 조회수를 불러와요'}>
{it.views !== null ? `${viewsLabel(it.views)}회` : <span className="muted">자동</span>}
@@ -333,16 +372,16 @@ export function QuizFileImport({
퀴즈 이름
<input className="input grow" value={name} maxLength={60} onChange={(e) => setName(e.target.value)} aria-label="퀴즈 이름" />
</label>
<button className="btn btn-primary" disabled={busy || !name.trim() || items.length < (duel ? 2 : 1)}>
<button className="btn btn-primary" disabled={busy || filling || !name.trim() || items.length < (duel ? 2 : 1)}>
{busy ? '만드는 중…' : `${items.length}곡으로 ${duel ? '이지선다 ' : ''}만들기`}
</button>
</form>
) : (
<div className="row">
<button type="button" className="btn btn-primary" disabled={!appendable.length} onClick={() => onApply?.(appendable, false)}>
<button type="button" className="btn btn-primary" disabled={filling || !appendable.length} onClick={() => onApply?.(appendable, false)}>
{appendable.length}곡 목록 뒤에 추가
</button>
<button type="button" className="btn btn-danger" disabled={!items.length} onClick={() => setConfirmReplace(true)}>
<button type="button" className="btn btn-danger" disabled={filling || !items.length} onClick={() => setConfirmReplace(true)}>
지금 목록을 지우고 바꾸기
</button>
</div>

View File

@@ -612,7 +612,9 @@ function SongsTab({
if (seen.has(r.videoId!) || (r.songId && seen.has(`s${r.songId}`))) continue;
seen.add(r.videoId!);
if (r.songId) seen.add(`s${r.songId}`);
added.push({ ...fresh({ songId: r.songId, videoId: r.videoId!, title: r.title, artist: r.artist, durationSec: r.durationSec }), key: newKey() });
// answers worked out by the server (other names, 한글 발음 …, docs/13)
const it = fresh({ songId: r.songId, videoId: r.videoId!, title: r.title, artist: r.artist, durationSec: r.durationSec });
added.push({ ...it, titleAnswers: r.titleAnswers ?? [], artistAnswers: r.artistAnswers ?? [], key: newKey() });
}
onItems([...base, ...added]);
setSel(null);
@@ -898,6 +900,8 @@ interface ImportRow {
source: { title: string; artist: string };
title: string;
artist: string;
titleAnswers: string[];
artistAnswers: string[];
durationSec: number | null;
videoId: string | null;
songId: number | null;