이지선다 조회수 자동: 빈 양식에서 조회수 열을 빼고, 올린 뒤 서버가 곡마다 토픽 음원 + MV 조회수를 불러와 더함. 짝은 유튜브 뮤직 노래↔동영상 전환(watch 응답의 counterpart, 쿠키 필요), 조회수는 로그인 없이 player videoDetails.viewCount(안 되면 watch 화면 숫자). quizzes/duel-views.ts가 pending 곡을 한 곡씩 처리(재시작해도 이어서), 쿠키 만료면 남은 곡 모두 이유와 함께 failed. 짝이 없는 곡은 있는 영상 하나만 쓰고 비고 표시. 파일·편집기에 적은 숫자는 그대로 쓰고 다시 불러오기에서 빠짐, 칸을 비우고 저장하면 자동. 편집기: 조회수(토픽·MV)·비고 칸, 불러오는 중 표시와 2초 폴링(저장 안 됨으로 안 잡힘), 조회수 다시 불러오기(전체/곡), 저장 때 편집기의 옛 사본이 서버가 불러온 값을 덮지 않음. 내보내기는 직접 넣은 숫자만 조회수 열에. 파일로 만들기는 조회수 열이 없으면 고른 종류 유지. 014 마이그레이션, 단위·API 테스트, e2e duel 단계, docs 04·10·12
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -30,6 +30,18 @@ export const QuizItemSchema = z.object({
|
||||
startSec: sec,
|
||||
highlightSec: sec,
|
||||
views: z.number().int().min(0).max(1e15).nullable().default(null),
|
||||
viewsAuto: z
|
||||
.object({
|
||||
state: z.enum(['pending', 'done', 'failed']),
|
||||
topicId: z.string().regex(/^[\w-]{11}$/).nullable(),
|
||||
topicViews: z.number().int().min(0).max(1e15).nullable(),
|
||||
mvId: z.string().regex(/^[\w-]{11}$/).nullable(),
|
||||
mvViews: z.number().int().min(0).max(1e15).nullable(),
|
||||
error: z.string().max(300).nullable(),
|
||||
at: z.number().int().nullable(),
|
||||
})
|
||||
.nullable()
|
||||
.default(null),
|
||||
}).refine((it) => it.fromFile || it.artist.length > 0, { path: ['artist'], message: '가수를 넣어 주세요.' });
|
||||
|
||||
export const QuizSaveSchema = z.object({
|
||||
|
||||
@@ -49,8 +49,40 @@ export interface QuizItem {
|
||||
auto: boolean;
|
||||
startSec: number | null;
|
||||
highlightSec: number | null;
|
||||
/** 이지선다 퀴즈: the video's view count as written in the file (null = not given; such songs are left out of games). */
|
||||
/**
|
||||
* 이지선다 퀴즈: 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 {
|
||||
|
||||
@@ -74,8 +74,8 @@ test('rows → quiz songs: as written, 순번 order, bad links / no answer / rep
|
||||
|
||||
test('our export reads back to the same songs (answers, own positions, several hints) and the template is valid', () => {
|
||||
const items = [
|
||||
{ songId: null, videoId: 'iIIjS6yDMQo', title: '감옥탈출', artist: '트레일러', titleAnswers: ['구토할배'], artistAnswers: ['trailer'], hints: ['방탈출', '플래시'], fromFile: true, durationSec: null, auto: false, startSec: 12, highlightSec: 61.5, views: null },
|
||||
{ songId: 3, videoId: 'x0-xFqvJ-U8', title: '갓 오브 워 2', artist: '', titleAnswers: [], artistAnswers: [], hints: [], fromFile: false, durationSec: 200, auto: true, startSec: null, highlightSec: null, views: null },
|
||||
{ songId: null, videoId: 'iIIjS6yDMQo', title: '감옥탈출', artist: '트레일러', titleAnswers: ['구토할배'], artistAnswers: ['trailer'], hints: ['방탈출', '플래시'], fromFile: true, durationSec: null, auto: false, startSec: 12, highlightSec: 61.5, views: null, viewsAuto: null },
|
||||
{ songId: 3, videoId: 'x0-xFqvJ-U8', title: '갓 오브 워 2', artist: '', titleAnswers: [], artistAnswers: [], hints: [], fromFile: false, durationSec: 200, auto: true, startSec: null, highlightSec: null, views: null, viewsAuto: null },
|
||||
];
|
||||
const { rows } = quizToRows(items);
|
||||
const text = rows.map((r) => r.map((c) => (c === null ? '' : String(c))));
|
||||
@@ -111,7 +111,7 @@ test('조회수 as people write it', () => {
|
||||
expect(parseViews('많음')).toBeUndefined();
|
||||
});
|
||||
|
||||
test('이지선다 파일: 제목·가수·조회수, rows without views are left out, export and template read back', () => {
|
||||
test('이지선다 파일: 제목·가수, 조회수 optional (empty = fetched by the server), export and template read back', () => {
|
||||
const rows = [
|
||||
['순번', '유튜브 링크', '제목', '가수', '조회수'],
|
||||
['2', 'https://youtu.be/iIIjS6yDMQo', '감옥탈출', '트레일러', '1.2억'],
|
||||
@@ -122,17 +122,23 @@ test('이지선다 파일: 제목·가수·조회수, rows without views are lef
|
||||
const cols = guessColumns(rows[0]!);
|
||||
expect(cols).toEqual(['order', 'link', 'answer', 'desc', 'views']);
|
||||
const p = parseQuizRows(rows, cols, 0, 'duel');
|
||||
expect(p.items.map((i) => [i.title, i.artist, i.views])).toEqual([
|
||||
['갓 오브 워', '', 3456789],
|
||||
['감옥탈출', '트레일러', 120000000],
|
||||
expect(p.items.map((i) => [i.title, i.artist, i.views, i.viewsAuto])).toEqual([
|
||||
['갓 오브 워', '', 3456789, null],
|
||||
['감옥탈출', '트레일러', 120000000, null],
|
||||
['조회수 없음', '누구', null, null],
|
||||
]);
|
||||
expect(p.rows.filter((r) => r.problem).map((r) => [r.line, r.problem])).toEqual([
|
||||
[4, '조회수가 비어 있어요'],
|
||||
[5, '조회수를 읽을 수 없어요 (많음)'],
|
||||
]);
|
||||
const { rows: out } = quizToRows(p.items, 'duel');
|
||||
expect(p.rows.filter((r) => r.problem).map((r) => [r.line, r.problem])).toEqual([[5, '조회수를 읽을 수 없어요 (많음)']]);
|
||||
// export: written numbers come back as written, fetched ones (and empty ones) come back empty
|
||||
const fetched = { state: 'done' as const, topicId: 'aaaaaaaaaaa', topicViews: 10, mvId: 'bbbbbbbbbbb', mvViews: 20, error: null, at: 1 };
|
||||
const withAuto = p.items.map((it, i) => (i === 1 ? { ...it, views: 30, viewsAuto: fetched } : it));
|
||||
const { rows: out } = quizToRows(withAuto, 'duel');
|
||||
expect(out[0]).toEqual(['순번', '유튜브 영상 링크', '제목', '가수', '조회수', '시작(초)', '하이라이트(초)']);
|
||||
const text = out.map((r) => r.map((c) => (c === null ? '' : String(c))));
|
||||
expect(parseQuizRows(text, guessColumns(text[0]!), 0, 'duel').items).toEqual(p.items);
|
||||
expect(parseQuizRows(text, guessColumns(text[0]!), 0, 'duel').items.map((i) => i.views)).toEqual([3456789, null, null]);
|
||||
// nothing written by hand: no 조회수 column at all
|
||||
expect(quizToRows([{ ...p.items[2]! }], 'duel').rows[0]).not.toContain('조회수');
|
||||
// 빈 양식: no 조회수 column, the example row reads back with its views left to the server
|
||||
const t = quizTemplateRows('duel').rows.map((r) => r.map((c) => (c === null ? '' : String(c))));
|
||||
expect(parseQuizRows(t, guessColumns(t[0]!), 0, 'duel').items).toHaveLength(1);
|
||||
expect(t[0]).toEqual(['순번', '유튜브 영상 링크', '제목', '가수', '시작(초)', '하이라이트(초)']);
|
||||
expect(parseQuizRows(t, guessColumns(t[0]!), 0, 'duel').items.map((i) => [i.title, i.views])).toEqual([['라일락', null]]);
|
||||
});
|
||||
|
||||
@@ -133,7 +133,8 @@ export interface ParsedQuizFile {
|
||||
/**
|
||||
* Sheet rows (header at `headerAt`) → quiz songs. Empty rows are skipped silently; rows with a bad link, no answer or a
|
||||
* video already used above are listed with the reason and left out. A 순번 column decides the order (rows without one last).
|
||||
* 이지선다 (`kind` duel): 정답 = 제목, 설명 = 가수, and every song needs its 조회수.
|
||||
* 이지선다 (`kind` duel): 정답 = 제목, 설명 = 가수. 조회수 is optional: a number written there is used as is,
|
||||
* an empty one is fetched by the server after upload (토픽 + MV).
|
||||
*/
|
||||
export function parseQuizRows(rows: string[][], columns: (QuizColumn | null)[], headerAt = 0, kind: QuizKind = 'normal'): ParsedQuizFile {
|
||||
const duel = kind === 'duel';
|
||||
@@ -167,9 +168,7 @@ export function parseQuizRows(rows: string[][], columns: (QuizColumn | null)[],
|
||||
? duel
|
||||
? '제목이 비어 있어요'
|
||||
: '정답이 비어 있어요'
|
||||
: views === null && duel
|
||||
? '조회수가 비어 있어요'
|
||||
: views === undefined
|
||||
: views === undefined
|
||||
? `조회수를 읽을 수 없어요 (${cell(r, at('views')).slice(0, 30)})`
|
||||
: seen.has(videoId)
|
||||
? `${seen.get(videoId)}번째 줄과 같은 영상이에요`
|
||||
@@ -200,6 +199,7 @@ export function parseQuizRows(rows: string[][], columns: (QuizColumn | null)[],
|
||||
startSec: own ? (start ?? 0) : null,
|
||||
highlightSec: own ? (highlight ?? null) : null,
|
||||
views: duel ? (views ?? null) : null,
|
||||
viewsAuto: null,
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -209,9 +209,12 @@ export function parseQuizRows(rows: string[][], columns: (QuizColumn | null)[],
|
||||
/** Quiz songs → sheet rows with the headers this file format reads back (내보내기, 빈 양식). */
|
||||
export function quizToRows(items: QuizItem[], kind: QuizKind = 'normal'): { rows: (string | number | null)[][]; widths: number[] } {
|
||||
if (kind === 'duel') {
|
||||
const header = ['순번', QUIZ_COLUMN_LABEL.link, '제목', '가수', '조회수', '시작(초)', '하이라이트(초)'];
|
||||
const rows = items.map((it, i) => [i + 1, `https://youtu.be/${it.videoId}`, it.title, it.artist, it.views, it.auto ? null : (it.startSec ?? 0), it.auto ? null : it.highlightSec]);
|
||||
return { rows: [header, ...rows], widths: [6, 32, 30, 24, 16, 10, 14] };
|
||||
// 조회수 only for numbers written by hand: fetched ones (and empty ones) are fetched again when the file comes back
|
||||
const own = (it: QuizItem) => (it.viewsAuto ? null : it.views);
|
||||
const withViews = items.some((it) => own(it) !== null);
|
||||
const header = ['순번', QUIZ_COLUMN_LABEL.link, '제목', '가수', ...(withViews ? ['조회수'] : []), '시작(초)', '하이라이트(초)'];
|
||||
const rows = items.map((it, i) => [i + 1, `https://youtu.be/${it.videoId}`, it.title, it.artist, ...(withViews ? [own(it)] : []), it.auto ? null : (it.startSec ?? 0), it.auto ? null : it.highlightSec]);
|
||||
return { rows: [header, ...rows], widths: [6, 32, 30, 24, ...(withViews ? [16] : []), 10, 14] };
|
||||
}
|
||||
const hintN = Math.max(1, ...items.map((i) => i.hints.length));
|
||||
const hintHeads = hintN === 1 ? ['힌트'] : Array.from({ length: hintN }, (_, i) => `힌트${i + 1}`);
|
||||
@@ -235,7 +238,7 @@ export function quizTemplateRows(kind: QuizKind = 'normal'): { rows: (string | n
|
||||
if (kind === 'duel')
|
||||
return quizToRows(
|
||||
[
|
||||
{ songId: null, videoId: 'v7bnOxV4jAc', title: '라일락', artist: '아이유', titleAnswers: [], artistAnswers: [], hints: [], fromFile: true, durationSec: null, auto: true, startSec: null, highlightSec: null, views: 123456789 },
|
||||
{ songId: null, videoId: 'v7bnOxV4jAc', title: '라일락', artist: '아이유', titleAnswers: [], artistAnswers: [], hints: [], fromFile: true, durationSec: null, auto: true, startSec: null, highlightSec: null, views: null, viewsAuto: null },
|
||||
],
|
||||
'duel',
|
||||
);
|
||||
@@ -254,6 +257,7 @@ export function quizTemplateRows(kind: QuizKind = 'normal'): { rows: (string | n
|
||||
startSec: null,
|
||||
highlightSec: null,
|
||||
views: null,
|
||||
viewsAuto: null,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user