From 1ac13a03fffb774bb9befb72e695fbeb32847a1c Mon Sep 17 00:00:00 2001 From: claude-bot Date: Mon, 25 May 2026 16:39:10 +0900 Subject: [PATCH] server-youtube: fast-path reuse for cached zipapp ensureYtDlp() and prepareYtDlp() now check the on-disk yt-dlp_zipapp before re-running the native-fail -> network-download path. On Linux servers where the native binary always fails verification (glibc/musl/ arch mismatch), every previous request was re-downloading both the native (~33MB) and the zipapp (~3MB). With the fast path, after the first successful zipapp install all subsequent requests short-circuit to the cached zipapp. Co-Authored-By: Claude Opus 4.7 --- src/server/youtube.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/server/youtube.ts b/src/server/youtube.ts index 8b64286..02c7831 100644 --- a/src/server/youtube.ts +++ b/src/server/youtube.ts @@ -69,6 +69,14 @@ export async function ensureYtDlp(): Promise { const probe = await probeVersion(target) if (probe.ok) return target } + // Fast path: 네이티브가 안 도는 환경에서 이전에 받아둔 zipapp 이 살아있으면 그걸 재사용 + if (process.platform !== 'win32') { + const zipappPath = getYtDlpZipappPath() + if (await fileExists(zipappPath)) { + const probe = await probeVersion(zipappPath) + if (probe.ok) return zipappPath + } + } if (installPromise) return installPromise installPromise = (async () => { try { @@ -83,13 +91,23 @@ export async function ensureYtDlp(): Promise { async function prepareYtDlp(target: string): Promise { const diagnostics: string[] = [] - // 1. 기존 파일이 있으면 우선 그걸로 시도 + // 1a. 기존 네이티브 파일이 있으면 우선 그걸로 시도 if (await fileExists(target)) { const probe = await probeVersion(target) if (probe.ok) return target diagnostics.push(`기존 ${path.basename(target)} 검증 실패: ${probe.detail}`) } + // 1b. (POSIX) 기존 zipapp 이 있으면 재다운로드 전에 먼저 시도 + if (process.platform !== 'win32') { + const existingZipapp = getYtDlpZipappPath() + if (await fileExists(existingZipapp)) { + const probe = await probeVersion(existingZipapp) + if (probe.ok) return existingZipapp + diagnostics.push(`기존 yt-dlp_zipapp 검증 실패: ${probe.detail}`) + } + } + // 2. PATH 에 yt-dlp(.exe) 가 시스템 전역으로 설치돼 있으면 그걸 사용 const pathCmd = process.platform === 'win32' ? 'yt-dlp.exe' : 'yt-dlp' const pathProbe = await probeVersion(pathCmd)