제작된 퀴즈 1~3단계: 관리자 → 퀴즈(목록·추가·곡 목록: 서버 DB/유튜브 검색·주소로 추가, 끌어서·▲▼·번호로 순서, 복수정답은 연결된 DB 곡 별칭에도, 영상 바꾸기 / 설정: 설명·공개방식(비공개·일부공개·전체공개)·문제 순서·재생위치 기본·방 규칙). 저장은 버튼·Ctrl+S로만, 안 저장 시 탭 제목·표시·나가기 확인. 곡마다 처음·하이라이트 위치 편집기(영상+큰 재생바, 끌기·지금 위치로·여기서 듣기·±1초, 자동=0초+DB 하이라이트, 연령제한은 받아 둔 음원). 방 설정 '직접 선택 / 제작된 퀴즈'(검색·비공개/일부공개 먼저), 고르면 퀴즈 설정이 방 설정으로, 듣고맞추기·곡 전부, 곡별 위치로 재생, 플레이 수. 퀴즈당 곡 수·계정당 퀴즈 수 제한(사이트 설정, 기본 무제한). '퀴즈 저장·불러오기'는 '진행 저장·불러오기'로 이름 변경

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-22 08:36:40 +09:00
parent e3cb623773
commit b56d1a8d0e
29 changed files with 2366 additions and 111 deletions

View File

@@ -5,7 +5,12 @@ import type { Database } from 'bun:sqlite';
import type { RoomConfig } from '@mq/shared';
export interface QuizSong {
/** Song id, or the item id in a 제작된 퀴즈 game. */
id: number;
/** The server DB song (stats, 재생 불가 marking): the song itself, a quiz item's linked song, or null. */
dbSongId: number | null;
/** 제작된 퀴즈: the item's own 처음 position (null = 0). */
startSec?: number | null;
title: string;
artist: string;
year: number | null;
@@ -38,6 +43,7 @@ export function quizSong(db: Database, id: number): QuizSong | null {
const col = <T>(sql: string) => db.query<{ v: T }, [number]>(sql).all(id).map((r) => r.v);
return {
id: s.id,
dbSongId: s.id,
title: s.title,
artist: s.artist,
year: s.year,
@@ -60,6 +66,46 @@ export function quizSong(db: Database, id: number): QuizSong | null {
};
}
/**
* One song of a 제작된 퀴즈 (quizzes/store.ts): the item's video, title, artist and positions; a linked DB song adds its
* aliases, genres, level and — only for the same video — loudness, highlight and 연령제한 audio.
*/
export function quizItemSong(db: Database, quizId: number, itemId: number): QuizSong | null {
const it = db
.query<
{ id: number; song_id: number | null; video_id: string; title: string; artist: string; title_answers: string; artist_answers: string; duration_sec: number | null; auto: number; start_sec: number | null; highlight_sec: number | null },
[number, number]
>('SELECT id, song_id, video_id, title, artist, title_answers, artist_answers, duration_sec, auto, start_sec, highlight_sec FROM custom_quiz_items WHERE quiz_id = ? AND id = ?')
.get(quizId, itemId);
if (!it) return null;
const base = it.song_id ? quizSong(db, it.song_id) : null;
const same = !!base && db.query<{ y: string | null }, [number]>('SELECT youtube_id y FROM songs WHERE id = ?').get(it.song_id!)?.y === it.video_id;
const audio = same ? db.query<{ age_video: string | null; audio_video: string | null; loudness_video: string | null; loudness_lufs: number | null }, [number]>('SELECT age_video, audio_video, loudness_video, loudness_lufs FROM songs WHERE id = ?').get(it.song_id!)! : null;
const uniq = (xs: string[]) => [...new Set(xs.filter(Boolean))];
return {
id: it.id,
dbSongId: base ? it.song_id : null,
title: it.title,
artist: it.artist,
year: base?.year ?? null,
durationSec: it.duration_sec ?? (same ? (base?.durationSec ?? null) : null),
videoId: it.video_id,
loudness: audio && audio.loudness_video === it.video_id ? audio.loudness_lufs : null,
// 자동: the DB highlight of this very video; 직접: the item's own positions
highlightSec: it.auto ? (same ? (base?.highlightSec ?? null) : null) : it.highlight_sec,
startSec: it.auto ? 0 : (it.start_sec ?? 0),
ageRestricted: !!audio && audio.age_video === it.video_id,
audio: !!audio && audio.age_video === it.video_id && audio.audio_video === it.video_id,
genres: base?.genres ?? [],
level: base?.level ?? null,
// the DB title/artist count too when the quiz spells them differently
titleAliases: uniq([...(JSON.parse(it.title_answers) as string[]), ...(base ? [base.title, ...base.titleAliases] : [])]),
artistAliases: uniq([...(JSON.parse(it.artist_answers) as string[]), ...(base ? [base.artist, ...base.artistAliases] : [])]),
artistIds: base?.artistIds ?? [],
lyrics: base?.lyrics ?? null,
};
}
/** First main artist per song, for spreading singers apart. */
export function mainArtists(db: Database, ids: number[]): Map<number, number> {
const out = new Map<number, number>();
@@ -106,8 +152,8 @@ export function loudnessGain(lufs: number | null, file = false): number {
/** Where playback starts and how long the clip is (docs/04 재생위치, docs/08 하이라이트). */
export function clipOf(song: QuizSong, c: RoomConfig): { startSec: number; endSec: number | null } {
const dur = song.durationSec;
let start = 0;
if (c.startAt === 'highlight') start = song.highlightSec ?? (dur ? Math.round(dur * 0.3) : 0);
let start = song.startSec ?? 0;
if (c.startAt === 'highlight') start = song.highlightSec ?? (dur ? Math.round(dur * 0.3) : start);
if (dur && start > dur - 5) start = 0;
if (c.listenSec === 0) return { startSec: start, endSec: dur };
const end = start + c.listenSec;