瀏覽代碼

fix: filename space to md5

ryanemax 2 月之前
父節點
當前提交
8d0944ca3c
共有 2 個文件被更改,包括 12 次插入3 次删除
  1. 4 1
      server/cloud/tbook/test/test-export.js
  2. 8 2
      server/lib/docs/index.js

+ 4 - 1
server/cloud/tbook/test/test-export.js

@@ -33,8 +33,11 @@ async function main(){
         // console.log(await exportProcessReportDocs(null,["UUGgHPHsIC"]))
         // console.log(await exportProcessReportDocs(null,["KxhErArSbB"]))
         // console.log(await exportProcessReportDocs(null,["7cf69rSawD"]))
-        console.log(await exportProcessReportDocs(null,["kY6MbE1JXC"])) // 21个附件,超时
+        // console.log(await exportProcessReportDocs(null,["kY6MbE1JXC"])) // 21个附件,超时
         // console.log(await exportProcessReportDocs(null,["O8kCxqdasp"])) // \u0002 乱码
+        // console.log(await exportProcessReportDocs(null,["VK81UnQmkn"]))
+        // console.log(await exportProcessReportDocs(null,["SD0NCAdscz"]))
+        console.log(await exportProcessReportDocs(null,["sbVgvo4qEk"]))
         
         // console.log(await exportProcessReportDocs(null,["3wJSkW9HNV"]))
         // console.log(await exportProcessReportDocs(null,["tHhfIDBkhf"]))

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

@@ -181,7 +181,11 @@ async function downloadUrl(url,options) {
         let fileDir = path.dirname(filepath);
         let abc = String.fromCharCode(96+(index+1)); // 字母顺序不会出现 把 1 10 11 12 放在一起的情况
         let num = index+110; // 数字顺序从百位开始,避免首数字排序错乱
-        let fileName = num + "_" + path.basename(filepath)
+
+        let md5 = crypto.createHash('md5');
+        let outmd5 = md5.update(path.basename(filepath)).digest('hex');
+        let fileName = num + "_" + outmd5 + path.extname(filepath);
+
         let orderPath = path.join(fileDir,fileName)
         fs.cpSync(filepath,orderPath);
         fs.readFileSync(filepath);
@@ -241,7 +245,9 @@ async function downloadUrl(url,options) {
             convertOpts.files = [files[0]];
             console.log(convertOpts)
             let mainPdfBuffer = await LibreOffice.convert(convertOpts);
-            mainPdfPath = path.dirname(docxPath)+"/109_"+path.basename(docxPath)+".pdf"
+            let md5 = crypto.createHash('md5');
+            let outmd5 = md5.update(path.basename(docxPath)).digest('hex');
+            mainPdfPath = path.dirname(docxPath)+"/109_"+outmd5+".pdf"
             fs.writeFileSync(mainPdfPath,mainPdfBuffer)
         }