105 lines
4.7 KiB
TypeScript
105 lines
4.7 KiB
TypeScript
/**
|
|
* 제작된 퀴즈 (admin-made quizzes): a list of songs with their own answers and start/highlight positions,
|
|
* plus the room settings a room takes over when it picks the quiz. Plain data for the browser; zod in custom-quiz-schema.ts.
|
|
*/
|
|
import { DEFAULT_ROOM_CONFIG, type RoomConfig } from './room-config';
|
|
|
|
/** 비공개: only the maker's rooms · 일부공개: the maker's and admins' rooms · 전체공개: everyone. */
|
|
export const QUIZ_VISIBILITIES = [
|
|
{ id: 'private', label: '비공개', help: '내 계정으로 방을 만들 때만 고를 수 있어요.' },
|
|
{ id: 'partial', label: '일부공개', help: '나와 관리자 계정으로 방을 만들 때만 고를 수 있어요.' },
|
|
{ id: 'public', label: '전체공개', help: '누구나 고를 수 있어요. 곡은 관리자 검토를 거쳐 서버 노래 DB에도 들어가요.' },
|
|
] as const;
|
|
export type QuizVisibility = (typeof QUIZ_VISIBILITIES)[number]['id'];
|
|
|
|
/** 일반 퀴즈 (듣고맞추기) or 이지선다 퀴즈 (조회수가 더 높은 곡 고르기): each is played only in its own mode. */
|
|
export type QuizKind = 'normal' | 'duel';
|
|
|
|
/** Room settings a quiz carries as its defaults (the host may still change them in the room). */
|
|
export const QUIZ_ROOM_KEYS = ['listenSec', 'startAt', 'answer', 'strict', 'hint', 'hintVotes', 'skipVotes', 'replayVotes', 'revealSec', 'nextVotes', 'duelSec', 'duelFlow'] as const;
|
|
export type QuizRoomDefaults = Pick<RoomConfig, (typeof QUIZ_ROOM_KEYS)[number]>;
|
|
|
|
export interface QuizSettings extends QuizRoomDefaults {
|
|
/** 문제 순서: as listed or shuffled each game. */
|
|
order: 'ordered' | 'random';
|
|
}
|
|
|
|
export const DEFAULT_QUIZ_SETTINGS: QuizSettings = {
|
|
...(Object.fromEntries(QUIZ_ROOM_KEYS.map((k) => [k, DEFAULT_ROOM_CONFIG[k]])) as QuizRoomDefaults),
|
|
order: 'ordered',
|
|
};
|
|
|
|
export interface QuizItem {
|
|
/** Stable id once saved; absent for a song added since the last save. */
|
|
id?: number;
|
|
/** The server DB song this item is (its aliases also count as answers), null when it is not in the DB. */
|
|
songId: number | null;
|
|
videoId: string;
|
|
title: string;
|
|
artist: string;
|
|
/** Extra accepted answers for this quiz (also added to the DB song's aliases on save). */
|
|
titleAnswers: string[];
|
|
artistAnswers: string[];
|
|
/** Hints of this song, shown one by one before the 초성 hint (파일로 만들기의 힌트 열). */
|
|
hints: string[];
|
|
/** Came from a quiz file: used as written, never sent to 검토 대기 (서버 노래 DB). */
|
|
fromFile: boolean;
|
|
durationSec: number | null;
|
|
/** 자동: start at 0 and the DB highlight; off = startSec/highlightSec below. */
|
|
auto: boolean;
|
|
startSec: number | null;
|
|
highlightSec: number | null;
|
|
/**
|
|
* 이지선다 퀴즈: the view count the game compares (null = none yet; such songs are left out of games).
|
|
* Written by hand / in the file (viewsAuto null) or the server's 토픽 + MV sum (viewsAuto).
|
|
*/
|
|
views: number | null;
|
|
/** 이지선다 퀴즈: views the server fetched (토픽 음원 + its MV, paired by YouTube Music); null = written by hand / in the file. */
|
|
viewsAuto: DuelViews | null;
|
|
}
|
|
|
|
/** 조회수 자동: the 토픽 (art track) and MV of one song, paired by YouTube Music's 노래 ↔ 동영상 switch. */
|
|
export interface DuelViews {
|
|
/** pending: waiting for the server · done: views = topicViews + mvViews · failed: see error (views stays as it was). */
|
|
state: 'pending' | 'done' | 'failed';
|
|
topicId: string | null;
|
|
topicViews: number | null;
|
|
/** The music video, or the linked video itself when it is not a 토픽 and has no 토픽 pair. */
|
|
mvId: string | null;
|
|
mvViews: number | null;
|
|
error: string | null;
|
|
/** When it was last fetched. */
|
|
at: number | null;
|
|
}
|
|
|
|
export const PENDING_VIEWS: DuelViews = { state: 'pending', topicId: null, topicViews: null, mvId: null, mvViews: null, error: null, at: null };
|
|
|
|
/** 비고 of an 이지선다 song: where its views come from when that is not the usual 토픽 + MV. */
|
|
export function duelViewsNote(it: Pick<QuizItem, 'views' | 'viewsAuto' | 'fromFile'>): string | null {
|
|
const a = it.viewsAuto;
|
|
if (!a) return it.views === null ? null : it.fromFile ? '파일에 적힌 조회수' : '직접 넣은 조회수';
|
|
if (a.state === 'failed') return a.error;
|
|
if (a.state !== 'done') return null;
|
|
if (!a.topicId) return '토픽 없음 (MV 조회수만)';
|
|
if (!a.mvId) return 'MV 없음 (토픽 조회수만)';
|
|
return null;
|
|
}
|
|
|
|
export interface QuizSummary {
|
|
id: number;
|
|
kind: QuizKind;
|
|
name: string;
|
|
description: string;
|
|
visibility: QuizVisibility;
|
|
songs: number;
|
|
plays: number;
|
|
ownerId: string;
|
|
ownerName: string;
|
|
updatedAt: number;
|
|
}
|
|
|
|
export interface QuizDetail extends QuizSummary {
|
|
settings: QuizSettings;
|
|
items: QuizItem[];
|
|
}
|