feat(video): 视频页「导出全部」— 把项目所有视频片段打包成 zip 下载

- 后端 ProjectViewSet 加 export-clips action:逐段从 TOS 拉取已采用视频片段、内存 zip 打包返回下载
  (单段失败跳过不毁整包;空项目 400);文件名走 RFC5987 UTF-8 编码兼容中文
- 前端视频阶段 queue-bar 在「上传视频」旁加「导出全部」按钮(下载图标 + 导出中/失败态),
  api.exportProjectClips 取 blob → 触发浏览器下载;仅有已完成片段时可点
- 单测 ExportClipsTests:打包全部片段 + 空项目 400

验收:后端单测绿(基线 4 失败零新增);tsc+build 绿;真打包 补水面膜 项目得 950KB zip;无头 0 报错
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
seaislee1209
2026-06-21 20:38:31 +08:00
parent 9e791a4db9
commit a39d2b8603
5 changed files with 158 additions and 1 deletions
+29
View File
@@ -2093,6 +2093,30 @@ export function PipelinePage(props: {
setUploadTargetSeg(segmentId);
videoUploadRef.current?.click();
}
// 导出全部:把本项目所有已采用视频片段打成一个 zip 下载
const [exporting, setExporting] = useState(false);
const [exportErr, setExportErr] = useState("");
async function exportAllVideos() {
if (exporting) return;
setExporting(true);
setExportErr("");
try {
const blob = await api.exportProjectClips(project.id);
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = `${project.name}-视频素材.zip`;
document.body.appendChild(a);
a.click();
a.remove();
URL.revokeObjectURL(url);
} catch (err) {
setExportErr(err instanceof ApiError ? err.message : "导出失败,请重试");
window.setTimeout(() => setExportErr(""), 3000);
} finally {
setExporting(false);
}
}
function onPickBgmFile(event: ChangeEvent<HTMLInputElement>) {
const file = event.target.files?.[0];
event.target.value = "";
@@ -2977,6 +3001,11 @@ export function PipelinePage(props: {
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" style={{ marginRight: "4px" }}><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" /><path d="M17 8l-5-5-5 5" /><path d="M12 3v12" /></svg>
</button>
{/* 导出全部:把所有已完成片段打包成 zip 一次性下载 */}
<button className="btn btn-sm" type="button" disabled={exporting || segDone === 0} title={exportErr || "把所有已完成视频片段打包下载"} onClick={() => void exportAllVideos()}>
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" style={{ marginRight: "4px" }}><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" /><path d="M7 10l5 5 5-5" /><path d="M12 15V3" /></svg>
{exporting ? "导出中…" : exportErr ? "导出失败" : "导出全部"}
</button>
</div>
<input ref={videoUploadRef} type="file" accept="video/*" style={{ display: "none" }} onChange={onPickVideoFile} />