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 <noreply@anthropic.com>
This commit is contained in:
@@ -69,6 +69,14 @@ export async function ensureYtDlp(): Promise<string> {
|
|||||||
const probe = await probeVersion(target)
|
const probe = await probeVersion(target)
|
||||||
if (probe.ok) return 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
|
if (installPromise) return installPromise
|
||||||
installPromise = (async () => {
|
installPromise = (async () => {
|
||||||
try {
|
try {
|
||||||
@@ -83,13 +91,23 @@ export async function ensureYtDlp(): Promise<string> {
|
|||||||
async function prepareYtDlp(target: string): Promise<string> {
|
async function prepareYtDlp(target: string): Promise<string> {
|
||||||
const diagnostics: string[] = []
|
const diagnostics: string[] = []
|
||||||
|
|
||||||
// 1. 기존 파일이 있으면 우선 그걸로 시도
|
// 1a. 기존 네이티브 파일이 있으면 우선 그걸로 시도
|
||||||
if (await fileExists(target)) {
|
if (await fileExists(target)) {
|
||||||
const probe = await probeVersion(target)
|
const probe = await probeVersion(target)
|
||||||
if (probe.ok) return target
|
if (probe.ok) return target
|
||||||
diagnostics.push(`기존 ${path.basename(target)} 검증 실패: ${probe.detail}`)
|
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) 가 시스템 전역으로 설치돼 있으면 그걸 사용
|
// 2. PATH 에 yt-dlp(.exe) 가 시스템 전역으로 설치돼 있으면 그걸 사용
|
||||||
const pathCmd = process.platform === 'win32' ? 'yt-dlp.exe' : 'yt-dlp'
|
const pathCmd = process.platform === 'win32' ? 'yt-dlp.exe' : 'yt-dlp'
|
||||||
const pathProbe = await probeVersion(pathCmd)
|
const pathProbe = await probeVersion(pathCmd)
|
||||||
|
|||||||
Reference in New Issue
Block a user