[fix]:[FL-226][ATP模型上传时去掉最外层目录]

修改上传逻辑,在打包ZIP时自动去掉选中文件夹的最外层目录名,
只保留里面的文件和子目录结构。

示例:
- 选择文件夹:/my-model/subdir/file.txt
- 之前上传后:my-model/subdir/file.txt
- 现在上传后:subdir/file.txt

实现细节:
- 解析webkitRelativePath,按/分割路径
- 使用slice(1)去掉第一个路径段(最外层目录名)
- 重新拼接剩余路径段

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
chengkai3
2026-06-28 22:43:46 +08:00
parent 75316e788e
commit febf8b6c67
+7 -2
View File
@@ -241,8 +241,13 @@ export default function AtpModelsPage() {
const JSZip = (await import("jszip")).default; const JSZip = (await import("jszip")).default;
const zip = new JSZip(); const zip = new JSZip();
for (const file of values.files) { for (const file of values.files) {
const path = (file as any).webkitRelativePath || file.name; const fullPath = (file as any).webkitRelativePath || file.name;
zip.file(path, file); // Strip the outermost directory level
const pathParts = fullPath.split('/');
const strippedPath = pathParts.length > 1 ? pathParts.slice(1).join('/') : fullPath;
if (strippedPath) {
zip.file(strippedPath, file);
}
} }
const zipBlob = await zip.generateAsync({ type: "blob" }); const zipBlob = await zip.generateAsync({ type: "blob" });
formData.append("files", zipBlob, "model.zip"); formData.append("files", zipBlob, "model.zip");