lsc 2 days ago
parent
commit
d6ecfcf9fb
1 changed files with 10 additions and 19 deletions
  1. 10 19
      js/Desktop/DeskTop.js

+ 10 - 19
js/Desktop/DeskTop.js

@@ -11550,17 +11550,16 @@ U.MD.D.I.setContents = function (cid, s, task, t, uid, type, text, loading, span
 }
 
 U.MD.D.I.downloadFile = function (cid, s, task, t, uid, type, text, loading, span, files, yuType) {
-    // 合并处理并优化,遍历 files 并上传
+    // 遍历 files,上传后只把 dataURL 变成链接,其它结构不变
     let _fileArray = Object.keys(files);
-    if (!_fileArray.length){
+    if (!_fileArray.length) {
         let text_str = JSON.stringify({
             element: text,
             files: []
         });
-        U.MD.D.I.setContents(cid, s, task, t, uid, type, text_str, loading, span)
+        U.MD.D.I.setContents(cid, s, task, t, uid, type, text_str, loading, span);
         return;
     }
-    // 一次性为 S3 配置好凭据和桶
     var credentials = {
         accessKeyId: "AKIATLPEDU37QV5CHLMH",
         secretAccessKey: "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",
@@ -11571,19 +11570,17 @@ U.MD.D.I.downloadFile = function (cid, s, task, t, uid, type, text, loading, spa
         params: { Bucket: "ccrb" }
     });
 
-    // 用于追踪上传数量,收集所有 url
     let uploadedCount = 0;
     let total = _fileArray.length;
-    let uploadedFiles = [];
     _fileArray.forEach(function (key, idx) {
         let fileObj = files[key];
         if (!fileObj || !fileObj.dataURL) {
-            uploadedFiles[idx] = null;
+            // 没有内容就直接加计数
             uploadedCount++;
             if (uploadedCount === total) finalizeUpload();
             return;
         }
-        // 若 dataURL 是 base64,则转为 File
+        // 是 base64 字符串转 File
         if (typeof fileObj.dataURL === "string") {
             let filename = fileObj.name || ('file_' + key);
             fileObj.dataURL = dataURLtoFile_shishi(fileObj.dataURL, filename);
@@ -11606,32 +11603,26 @@ U.MD.D.I.downloadFile = function (cid, s, task, t, uid, type, text, loading, spa
             };
             bucket.upload(params, options)
                 .on("httpUploadProgress", function (evt) {
-                    // 如有需要可处理进度
+                    // 进度处理
                 })
                 .send(function (err, data) {
                     if (data) {
-                        console.log(data.Location);
+                        // 只将 dataURL 字段替换为链接,其它原样不动
                         files[key].dataURL = data.Location;
-                        uploadedFiles[idx] = {
-                            name: fileObj.name || '',
-                            url: data.Location
-                        };
-                    } else {
-                        uploadedFiles[idx] = null;
                     }
+                    // 上传出错仍然整体结构
                     uploadedCount++;
                     if (uploadedCount === total) finalizeUpload();
                 });
         } else {
-            uploadedFiles[idx] = null;
             uploadedCount++;
             if (uploadedCount === total) finalizeUpload();
         }
     });
 
     function finalizeUpload() {
-        // 过滤掉空的项
-        let fileList = uploadedFiles.filter(Boolean);
+        // 最终打包时,files结构不变,只是dataURL变为链接
+        let fileList = _fileArray.map(key => files[key]);
         let text_str = JSON.stringify({
             element: text,
             files: fileList