lrf402788946 4 years ago
parent
commit
8aa4d3720d
1 changed files with 24 additions and 24 deletions
  1. 24 24
      app/controller/files.js

+ 24 - 24
app/controller/files.js

@@ -9,7 +9,7 @@ const sendToWormhole = require('stream-wormhole');
 const assert = require('assert');
 const wxstream = require('stream');
 const ffmpeg = require('fluent-ffmpeg');
-// const sharp = require('sharp');
+const sharp = require('sharp');
 class FilesController extends Controller {
 
   async upload() {
@@ -61,30 +61,30 @@ class FilesController extends Controller {
       await sendToWormhole(stream);
       throw err;
     }
-    // // 判断是不是作业的图片,是=>统一转换
-    // const arr = fileName.split('.');
-    // if (arr.length > 0 && filePath.includes('task')) {
-    //   const suffix = arr.find(
-    //     f =>
-    //       f.includes('jpg') ||
-    //       f.includes('jpeg') ||
-    //       f.includes('bmp') ||
-    //       f.includes('gif') ||
-    //       f.includes('png')
+    // 判断是不是作业的图片,是=>统一转换
+    const arr = fileName.split('.');
+    if (arr.length > 0 && filePath.includes('task')) {
+      const suffix = arr.find(
+        f =>
+          f.includes('jpg') ||
+          f.includes('jpeg') ||
+          f.includes('bmp') ||
+          f.includes('gif') ||
+          f.includes('png')
 
-    //   );
-    //   if (suffix) {
-    //     await sharp(`${filePath}${fileName}`)
-    //       .resize(1000)
-    //       .toFile(`${filePath}${name}_.jpg`)
-    //       .then(data => {
-    //         // 将转换之前的文件删除
-    //         fs.unlinkSync(`${filePath}${fileName}`);
-    //         fileName = `${name}_.jpg`;
-    //         name = `${name}_`;
-    //       });
-    //   }
-    // }
+      );
+      if (suffix) {
+        await sharp(`${filePath}${fileName}`)
+          .resize(1000)
+          .toFile(`${filePath}${name}_.jpg`)
+          .then(data => {
+            // 将转换之前的文件删除
+            fs.unlinkSync(`${filePath}${fileName}`);
+            fileName = `${name}_.jpg`;
+            name = `${name}_`;
+          });
+      }
+    }
     return { filePath, fileName, id: name };
   }