/** 视频批量下载反馈(任务 107):zip 文件名解析与下载失败摘要,纯逻辑。 */ /** 从 Content-Disposition 解析下载文件名(rfc5987 优先),失败回默认名。 */ export function zipFilenameFromDisposition(disposition: string | undefined): string { const text = typeof disposition === 'string' ? disposition : '' const encoded = /filename\*=UTF-8''([^;]+)/i.exec(text) if (encoded) { try { const decoded = decodeURIComponent(encoded[1]) if (decoded.trim()) return decoded.trim() } catch { // 回退到普通 filename } } const plain = /filename="?([^";]+)"?/i.exec(text) return plain && plain[1] ? plain[1].trim() : 'video-tasks.zip' } function finiteCount(value: number | undefined): number { return typeof value === 'number' && Number.isFinite(value) && value > 0 ? Math.floor(value) : 0 } /** 依据服务端成功/失败计数生成下载结果摘要文案。 */ export function downloadResultSummary(counts: { fileCount?: number; errorCount?: number; selected?: number }): string { const fileCount = finiteCount(counts.fileCount) const errorCount = finiteCount(counts.errorCount) const selected = finiteCount(counts.selected) if (fileCount === 0 && errorCount === 0) return '未产生下载结果' if (errorCount === 0) return `已下载 ${fileCount} 个视频` const allFailed = fileCount === 0 || (selected > 0 && errorCount >= selected) return allFailed ? `全部 ${errorCount} 个视频下载失败,详见打包中的错误清单` : `打包完成:成功 ${fileCount} 个,失败 ${errorCount} 个,详见打包中的错误清单` }