제작된 퀴즈 4단계: 플레이리스트 가져오기(유튜브·유튜브 뮤직·스포티파이 주소를 .6 Lavalink로). 서버 DB 곡(같은 영상·같은 제목+가수)은 그 곡, 유튜브는 그 영상(Official MV 등 제목 정리, 퍼가기 막힌 영상 표시), 스포티파이는 유튜브 뮤직 검색을 원곡 찾기 기준으로(애매하면 확인 필요). 백그라운드 작업+진행률, 결과에서 골라 뒤에 추가 또는 목록 바꾸기(이미 있는 곡 제외). LAVALINK_URL·LAVALINK_PW 환경변수
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -11,6 +11,8 @@ import type { YtmSong } from '../collector/ytmusic';
|
||||
import { pickSearcher } from '../collector/ytmusic';
|
||||
import { listSongs } from '../songs/store';
|
||||
import { audioFile, type AudioLinks } from '../songs/audio';
|
||||
import { getImportJob, startImport, type Lavalink } from '../quizzes/playlist';
|
||||
import { checkEmbed, type EmbedState } from '../collector/oembed';
|
||||
|
||||
type Env = { Variables: { userId: string | null; role: Role } };
|
||||
|
||||
@@ -22,6 +24,11 @@ export interface QuizAdminDeps {
|
||||
/** YouTube Music song search (cookie) with the plain YouTube fallback; injected in tests. */
|
||||
searchYoutube?: (q: string) => Promise<YtmSong[]>;
|
||||
audio?: AudioLinks;
|
||||
/** 플레이리스트 가져오기 through the .6 Lavalink (LAVALINK_URL / LAVALINK_PW); tests inject a fake fetch. */
|
||||
lavalink?: Lavalink | null;
|
||||
lavalinkFetch?: typeof fetch;
|
||||
checkEmbed?: (videoId: string) => Promise<EmbedState>;
|
||||
importDelayMs?: number;
|
||||
videoOf: (url: string) => Promise<{ id: string; author: string; title: string } | string>;
|
||||
onChange?: () => void;
|
||||
}
|
||||
@@ -132,6 +139,25 @@ export function mountQuizAdmin(app: Hono<Env>, d: QuizAdminDeps, h: { actor: (c:
|
||||
return c.json({ src: d.audio.link(v) });
|
||||
});
|
||||
|
||||
/** 플레이리스트 가져오기: starts a background job; the editor polls it. */
|
||||
app.post('/quizzes/pick/playlist', async (c) => {
|
||||
const p = z.object({ url: z.string().trim().min(1).max(500) }).safeParse(await h.body(c));
|
||||
if (!p.success) return c.json({ error: '플레이리스트 주소를 넣어 주세요.' }, 400);
|
||||
const lavalink =
|
||||
d.lavalink !== undefined ? d.lavalink : process.env.LAVALINK_URL && process.env.LAVALINK_PW ? { url: process.env.LAVALINK_URL, password: process.env.LAVALINK_PW } : null;
|
||||
const job = await startImport(
|
||||
{ db: d.db, lavalink, search: d.searchYoutube ?? defaultSearch, embed: d.checkEmbed ?? ((id) => checkEmbed(id)), delayMs: d.importDelayMs, fetchImpl: d.lavalinkFetch },
|
||||
h.actor(c),
|
||||
p.data.url,
|
||||
);
|
||||
if (typeof job === 'string') return c.json({ error: job }, 400);
|
||||
return c.json({ job });
|
||||
});
|
||||
app.get('/quizzes/pick/playlist/:job', (c) => {
|
||||
const job = getImportJob(c.req.param('job'), h.actor(c));
|
||||
return job ? c.json({ job }) : c.json({ error: '가져오기 작업을 찾을 수 없어요.' }, 404);
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------- one quiz
|
||||
app.get('/quizzes/:id', (c) => {
|
||||
const q = mine(c);
|
||||
|
||||
Reference in New Issue
Block a user