FormatTheAttachment.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. list[i].fileType = 'unknown';
  18. list[i].cover = `/static/image/file/unknown.png`
  19. const suffix = list[i].postfix.toLowerCase();
  20. if (suffix != "folder") {
  21. for (let key in suffixList) {
  22. if (suffixList[key].some(value => value == suffix)) {
  23. list[i].fileType = key;
  24. if (key == 'image') {
  25. list[i].cover = list[i].url;
  26. } else if (typeList.includes(key)) {
  27. list[i].cover = `/static/image/file/${key}.png`;
  28. }
  29. }
  30. }
  31. } else {
  32. list[i].fileType = "folder";
  33. list[i].cover = `/static/image/file/folder.png`
  34. }
  35. }
  36. return list;
  37. };
  38. //得到缩略图或者压缩图 getType默认得到缩略图传true得到压缩图
  39. function getSpecifiedImage(obj, getType = false) {
  40. let type = getType ? 'compressed' : 'thumbnail';
  41. let imgObj = obj.subfiles.find(v => v.type == type);
  42. return imgObj.url;
  43. }
  44. module.exports = {
  45. fileList,
  46. getSpecifiedImage
  47. }