xiaohaizhao 3 лет назад
Родитель
Сommit
cd055c9f2e
1 измененных файлов с 38 добавлено и 37 удалено
  1. 38 37
      utils/matchingFeilType.js

+ 38 - 37
utils/matchingFeilType.js

@@ -1,48 +1,49 @@
 function fileList(list) {
-  let suffixList = {
-      image: ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'svg', 'tiff'],
-      video: ['mp4', 'ogg', 'webm'],
-      word: ['doc', 'docx'],
-      excel: ['xls', 'xlsx'],
-      ppt: ['ppt', 'pptx'],
-      txt: ['txt', 'md', 'js', 'json'],
-      pdf: ['pdf'],
-      rar: ['7z', 'zip', 'rar', 'kz', 'ace', 'arj', 'bz2', 'cab', 'gz', 'iso', 'jar', 'lzh', 'tar', 'z'],
-      folder: ['"folder"']
-    },
-    typeList = [];
-  for (let key in suffixList) typeList.push(key);
-  for (let i = 0; i < list.length; i++) {
-    list[i].fileType = 'unknown';
-    list[i].cover = `/static/image/file/unknown.png`
-    const suffix = list[i].postfix.toLowerCase();
-    if (suffix != "folder") {
-      for (var key in suffixList) {
-        if (suffixList[key].some(value => value == suffix)) {
-          list[i].fileType = key;
-          if (key == 'image') {
-            list[i].cover = list[i].url;
-          } else if (typeList.includes(key)) {
-            list[i].cover = `/static/image/file/${key}.png`;
-          }
+    if (list.length == 0) return [];
+    let suffixList = {
+            image: ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'svg', 'tiff'],
+            video: ['mp4', 'ogg', 'webm'],
+            word: ['doc', 'docx'],
+            excel: ['xls', 'xlsx'],
+            ppt: ['ppt', 'pptx'],
+            txt: ['txt', 'md', 'js', 'json'],
+            pdf: ['pdf'],
+            rar: ['7z', 'zip', 'rar', 'kz', 'ace', 'arj', 'bz2', 'cab', 'gz', 'iso', 'jar', 'lzh', 'tar', 'z'],
+            folder: ['"folder"']
+        },
+        typeList = [];
+    for (let key in suffixList) typeList.push(key);
+    for (let i = 0; i < list.length; i++) {
+        list[i].fileType = 'unknown';
+        list[i].cover = `/static/image/file/unknown.png`
+        const suffix = list[i].postfix.toLowerCase();
+        if (suffix != "folder") {
+            for (var key in suffixList) {
+                if (suffixList[key].some(value => value == suffix)) {
+                    list[i].fileType = key;
+                    if (key == 'image') {
+                        list[i].cover = list[i].url;
+                    } else if (typeList.includes(key)) {
+                        list[i].cover = `/static/image/file/${key}.png`;
+                    }
+                }
+            }
+        } else {
+            list[i].fileType = "folder";
+            list[i].cover = `/static/image/file/folder.png`
         }
-      }
-    } else {
-      list[i].fileType = "folder";
-      list[i].cover = `/static/image/file/folder.png`
     }
-  }
-  return list;
+    return list;
 };
 
 //得到缩略图或者压缩图  getType默认得到缩略图传true得到压缩图
 function getSpecifiedImage(obj, getType = false) {
-  let type = getType ? 'compressed' : 'thumbnail';
-  let imgObj = obj.subfiles.find(v => v.type == type);
-  return imgObj ? imgObj.url : "";
+    let type = getType ? 'compressed' : 'thumbnail';
+    let imgObj = obj.subfiles.find(v => v.type == type);
+    return imgObj ? imgObj.url : "";
 }
 
 module.exports = {
-  fileList,
-  getSpecifiedImage
+    fileList,
+    getSpecifiedImage
 }