Browse Source

fix: mergeFiles order

ryanemax 6 months ago
parent
commit
f30ca7d27d
1 changed files with 5 additions and 2 deletions
  1. 5 2
      server/lib/docs/index.js

+ 5 - 2
server/lib/docs/index.js

@@ -148,8 +148,8 @@ async function downloadUrl(url) {
  */
  export async function docxToPdf(docxPath, outputPath,options) {
     let mergeFiles = options?.mergeFiles || []
-    let filePathList = []
     let merge = false;
+    let mergeFileMap = {};
     if(mergeFiles?.length){
         let plist = []
         for (let index = 0; index < mergeFiles.length; index++) {
@@ -159,7 +159,8 @@ async function downloadUrl(url) {
                     filePath = await downloadUrl(mergeFiles[index]);
                 }catch(err){}
                 if(filePath){
-                    filePathList.push(filePath)
+                    mergeFileMap[index] = filePath // 按原有顺序整理
+                    // filePathList.push(filePath)
                 }
                 return
             })())
@@ -167,6 +168,8 @@ async function downloadUrl(url) {
         await Promise.all(plist);
         merge = true;
     }
+    let filePathList = mergeFiles.map((item,index)=>mergeFileMap[index]).filter(item=>item)
+
     console.log("DOWNLOADED:",filePathList)
     try {
         let docxBuffer = fs.readFileSync(docxPath);