FormatTheAttachment.js 1.7 KB

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