Browse Source

feat: merge file with md5 name

ryanemax 7 months ago
parent
commit
0e62a85fb5
1 changed files with 11 additions and 3 deletions
  1. 11 3
      server/lib/docs/index.js

+ 11 - 3
server/lib/docs/index.js

@@ -102,7 +102,8 @@ module.exports.createZip = createZip
 
 const download = require('download')
 async function downloadUrl(url) {
-    let filename = path.basename(url)
+    let md5 = crypto.createHash('md5');
+    let filename = md5.update(url).digest('hex') + path.extname(url)
     let filepath = path.join(tempDir,filename)
     // console.log(filename,filepath)
     try{
@@ -139,7 +140,7 @@ async function downloadUrl(url) {
         }
         merge = true;
     }
-
+    // console.log("merge",filePathList)
     try {
         let docxBuffer = fs.readFileSync(docxPath);
 
@@ -302,4 +303,11 @@ export function replaceDocx(inputDocxPath, outputDocxPath, options,eventMap) {
 
 }
 
-module.exports.replaceDocx = replaceDocx
+module.exports.replaceDocx = replaceDocx
+function generateObjectId(inputString) {
+    inputString = inputString || ""
+    inputString = String(inputString)
+    const hash = crypto.createHash('sha256').update(inputString).digest('hex');
+    const objectId = hash;
+    return objectId;
+}