8단계 관리자: 노래 추가·초성 검색·일괄 작업·휴지통·가져오기/내보내기·중복 병합·하이라이트 지정, 가수 별칭, 장르, 통계와 난이도 제안, 방 강제 종료, 수집 실행/멈추기, 새 방 기본 설정·잠금 + 출제 기록(song_plays)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,7 @@ import { toPublicUser, type Users } from '../auth/users';
|
||||
import type { Database } from 'bun:sqlite';
|
||||
import { catalogStats, genreList, getSong, listSongs, updateSong } from '../songs/store';
|
||||
import { checkEmbed, type EmbedState } from '../collector/oembed';
|
||||
import { mountCatalogAdmin, songFilterFrom, type CollectControl } from './admin-catalog';
|
||||
|
||||
export interface AdminDeps {
|
||||
users: Users;
|
||||
@@ -23,6 +24,13 @@ export interface AdminDeps {
|
||||
checkEmbed?: (videoId: string) => Promise<EmbedState>;
|
||||
/** Lobby song counts depend on the catalog. */
|
||||
onCatalogChange?: () => void;
|
||||
/** Genre names shown on room cards. */
|
||||
onGenresChange?: () => void;
|
||||
rooms?: {
|
||||
adminList(): unknown[];
|
||||
adminClose(code: string): boolean;
|
||||
};
|
||||
collect?: CollectControl;
|
||||
}
|
||||
|
||||
type Env = { Variables: { userId: string | null; role: Role } };
|
||||
@@ -93,27 +101,21 @@ export function createAdminApp(d: AdminDeps) {
|
||||
// ------------------------------------------------------------ songs (docs/02 노래 관리)
|
||||
app.get('/catalog', (c) => c.json(catalogStats(d.db)));
|
||||
app.get('/genres', (c) => c.json({ genres: genreList(d.db) }));
|
||||
app.get('/songs', (c) => {
|
||||
const q = (k: string) => c.req.query(k) || undefined;
|
||||
const num = (k: string) => (q(k) ? Number(q(k)) || undefined : undefined);
|
||||
const yt = q('youtube');
|
||||
const sort = q('sort');
|
||||
return c.json(
|
||||
listSongs(d.db, {
|
||||
q: q('q')?.trim().slice(0, 100),
|
||||
genres: q('genres')?.split(',').filter(Boolean),
|
||||
yearFrom: num('yearFrom'),
|
||||
yearTo: num('yearTo'),
|
||||
level: num('level'),
|
||||
youtube: yt && ['matched', 'candidate', 'none', 'dead'].includes(yt) ? (yt as 'matched') : undefined,
|
||||
source: q('source'),
|
||||
hidden: q('hidden') === undefined ? undefined : q('hidden') === '1',
|
||||
lyrics: q('lyrics') === undefined ? undefined : q('lyrics') === '1',
|
||||
sort: sort && ['recent', 'year', 'level', 'peak', 'title'].includes(sort) ? (sort as 'recent') : undefined,
|
||||
page: num('page'),
|
||||
}),
|
||||
);
|
||||
// Static paths (/songs/export, /songs/bulk …) before /songs/:id.
|
||||
mountCatalogAdmin(app, d, {
|
||||
actor,
|
||||
body,
|
||||
videoOf: async (url) => {
|
||||
const id = parseVideoId(url);
|
||||
if (!id) return '유튜브 주소를 알아볼 수 없어요. https://youtu.be/… 형식으로 넣어 주세요.';
|
||||
const e = await (d.checkEmbed ?? checkEmbed)(id);
|
||||
if (e.state === 'noembed') return '이 영상은 다른 사이트에서 재생할 수 없게 막혀 있어요(퍼가기 금지). 다른 영상을 골라 주세요.';
|
||||
if (e.state === 'dead') return '없는 영상이에요.';
|
||||
if (e.state === 'error') return '유튜브 확인에 실패했어요. 잠시 후 다시 시도해 주세요.';
|
||||
return { id, author: e.author, title: e.title };
|
||||
},
|
||||
});
|
||||
app.get('/songs', (c) => c.json(listSongs(d.db, songFilterFrom(c))));
|
||||
app.get('/songs/:id', (c) => {
|
||||
const r = getSong(d.db, Number(c.req.param('id')));
|
||||
return r ? c.json(r) : c.json({ error: '노래를 찾을 수 없어요.' }, 404);
|
||||
|
||||
Reference in New Issue
Block a user