matchingFeilType.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. function fileList(list) {
  2. let suffixList = {
  3. image: ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'svg', 'tiff'],
  4. video: ['mp4', 'ogg', 'webm'],
  5. word: ['doc', 'docx'],
  6. excel: ['xls', 'xlsx'],
  7. ppt: ['ppt', 'pptx'],
  8. txt: ['txt', 'md', 'js', 'json'],
  9. pdf: ['pdf'],
  10. rar: ['7z', 'zip', 'rar', 'kz', 'ace', 'arj', 'bz2', 'cab', 'gz', 'iso', 'jar', 'lzh', 'tar', 'z'],
  11. folder: ['"folder"']
  12. },
  13. typeList = [];
  14. for (let key in suffixList) typeList.push(key);
  15. for (let i = 0; i < list.length; i++) {
  16. list[i].fileType = 'unknown';
  17. list[i].cover = `/static/image/file/unknown.png`
  18. const suffix = list[i].postfix;
  19. if (suffix != "folder") {
  20. for (let key in suffixList) {
  21. if (suffixList[key].some(value => value == suffix)) {
  22. list[i].fileType = key;
  23. if (key == 'image') {
  24. list[i].cover = list[i].url;
  25. } else if (typeList.includes(key)) {
  26. list[i].cover = `/static/image/file/${key}.png`;
  27. }
  28. }
  29. }
  30. } else {
  31. list[i].fileType = "folder";
  32. list[i].cover = `/static/image/file/folder.png`
  33. }
  34. }
  35. return list;
  36. };
  37. //得到缩略图或者压缩图 getType默认得到缩略图传true得到压缩图
  38. function getSpecifiedImage(obj, getType = false) {
  39. let type = getType ? 'compressed' : 'thumbnail';
  40. let imgObj = obj.subfiles.find(v => v.type == type);
  41. return imgObj.url;
  42. }
  43. module.exports = {
  44. fileList,
  45. getSpecifiedImage
  46. }