퀴즈 편집 수정: 저장 중에 바꾼 내용이 응답으로 덮여 사라지고 '저장됨'으로 보이던 것(보낸 내용과 지금 내용이 다르면 지금 내용을 두고 새 곡 id만 붙임, 저장 안 됨 유지). 새로 추가한 서버 DB 곡의 하이라이트가 DB 값 대신 곡 길이 30%로 보이고 자동을 끄면 그 값으로 굳던 것(추가 즉시 /quizzes/pick/songs로 DB 정보를 받고, 받기 전엔 자동 스위치·표시 이동 잠금). e2e/quiz.e2e.ts로 두 경로 회귀 확인
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -85,6 +85,9 @@ test('editor API: save items with extra answers (into the DB aliases for linked
|
||||
const items = r.body.quiz.items as { id: number }[];
|
||||
const re = await api(s.base, `/api/admin/quizzes/${id}`, { method: 'PUT', cookie: sa, body: JSON.stringify({ name: '테스트', description: '설명', visibility: 'public', settings: settings(), items: [r.body.quiz.items[1], r.body.quiz.items[0]] }) });
|
||||
expect(re.body.quiz.items.map((i: { id: number }) => i.id)).toEqual([items[1]!.id, items[0]!.id]);
|
||||
// DB facts of a song added in the editor before saving (자동 uses the DB highlight)
|
||||
const facts = await api(s.base, `/api/admin/quizzes/pick/songs?ids=${song},999999`, { cookie: sa });
|
||||
expect(facts.body.db).toEqual({ [song]: { titleAliases: ['Good Day'], artistAliases: [], highlightSec: 61, durationSec: 230, videoId: 'goodday0001' } });
|
||||
// an admin who did not make it cannot open it
|
||||
s.db.query("INSERT INTO admins (discord_id, note, added_by, added_at) VALUES ('900000000000000077', null, null, 0)").run();
|
||||
const other = await adminCookie('900000000000000077');
|
||||
|
||||
@@ -206,26 +206,18 @@ export function mountQuizAdmin(app: Hono<Env>, d: QuizAdminDeps, h: { actor: (c:
|
||||
return job ? c.json({ job }) : c.json({ error: '가져오기 작업을 찾을 수 없어요.' }, 404);
|
||||
});
|
||||
|
||||
/** 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);
|
||||
return c.json({ db: dbFacts(d.db, ids) });
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------- one quiz
|
||||
app.get('/quizzes/:id', (c) => {
|
||||
const q = mine(c);
|
||||
if (!q) return c.json({ error: '퀴즈를 찾을 수 없어요.' }, 404);
|
||||
const detail = d.quizzes.get(q.id)!;
|
||||
// DB facts the editor shows next to each song: aliases that already count, the DB highlight for 자동.
|
||||
const ids = [...new Set(detail.items.map((i) => i.songId).filter((x): x is number => !!x))];
|
||||
const db: Record<number, { titleAliases: string[]; artistAliases: string[]; highlightSec: number | null; durationSec: number | null; videoId: string | null }> = {};
|
||||
for (const id of ids) {
|
||||
const s = d.db.query<{ highlight_sec: number | null; duration_sec: number | null; youtube_id: string | null }, [number]>('SELECT highlight_sec, duration_sec, youtube_id FROM songs WHERE id = ?').get(id);
|
||||
if (!s) continue;
|
||||
const al = d.db.query<{ part: string; alias: string }, [number]>('SELECT part, alias FROM song_aliases WHERE song_id = ?').all(id);
|
||||
db[id] = {
|
||||
titleAliases: al.filter((a) => a.part === 'title').map((a) => a.alias),
|
||||
artistAliases: al.filter((a) => a.part === 'artist').map((a) => a.alias),
|
||||
highlightSec: s.highlight_sec,
|
||||
durationSec: s.duration_sec,
|
||||
videoId: s.youtube_id,
|
||||
};
|
||||
}
|
||||
const db = dbFacts(d.db, detail.items.map((i) => i.songId).filter((x): x is number => !!x));
|
||||
return c.json({ quiz: detail, db, limits: d.limits() });
|
||||
});
|
||||
|
||||
@@ -253,3 +245,23 @@ export function mountQuizAdmin(app: Hono<Env>, d: QuizAdminDeps, h: { actor: (c:
|
||||
return c.json({ ok: true });
|
||||
});
|
||||
}
|
||||
|
||||
/** DB facts the editor shows next to each linked song: aliases that already count, the DB highlight/length/video for 자동. */
|
||||
function dbFacts(db: Database, songIds: number[]) {
|
||||
const out: Record<number, { titleAliases: string[]; artistAliases: string[]; highlightSec: number | null; durationSec: number | null; videoId: string | null }> = {};
|
||||
const song = db.query<{ highlight_sec: number | null; duration_sec: number | null; youtube_id: string | null }, [number]>('SELECT highlight_sec, duration_sec, youtube_id FROM songs WHERE id = ?');
|
||||
const aliases = db.query<{ part: string; alias: string }, [number]>('SELECT part, alias FROM song_aliases WHERE song_id = ?');
|
||||
for (const id of new Set(songIds)) {
|
||||
const s = song.get(id);
|
||||
if (!s) continue;
|
||||
const al = aliases.all(id);
|
||||
out[id] = {
|
||||
titleAliases: al.filter((a) => a.part === 'title').map((a) => a.alias),
|
||||
artistAliases: al.filter((a) => a.part === 'artist').map((a) => a.alias),
|
||||
highlightSec: s.highlight_sec,
|
||||
durationSec: s.duration_sec,
|
||||
videoId: s.youtube_id,
|
||||
};
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user