task-107(任务与重复分析中心): 实现视频任务下载失败摘要

新增 image-video-download-feedback.ts:zip 文件名 Content-Disposition 解析与
按成功/失败计数生成下载结果摘要(全失败/部分失败提示)。

TDD: task-107.test.ts 8 用例先 RED 后 GREEN。
This commit is contained in:
2026-09-05 17:11:47 +08:00
parent d2ef1ce4d8
commit a1e466030b
2 changed files with 85 additions and 0 deletions
@@ -0,0 +1,34 @@
/** 视频批量下载反馈(任务 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} 个,详见打包中的错误清单`
}