function fileList(list) { if (!Array.isArray(list) || list.length === 0) return []; const 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'] }; return list.map(file => { const suffix = file.postfix ? file.postfix.toLowerCase() : ''; const fileType = suffixList.folder.includes(suffix) ? 'folder' : Object.keys(suffixList).find(key => suffixList[key].includes(suffix)) || 'unknown'; return { ...file, fileType, cover: fileType === 'image' ? file.url : fileType !== 'unknown' ? `/static/image/file/${fileType}.png` : `/static/image/file/unknown.png` }; }); } //得到缩略图或者压缩图 getType默认得到缩略图传true得到压缩图 function getSpecifiedImage(obj, getType = false) { if (!obj || !Array.isArray(obj.subfiles)) return ""; const type = getType ? 'compressed' : 'thumbnail'; const imgObj = obj.subfiles.find(v => v.type === type); return imgObj ? imgObj.url : ""; } module.exports = { fileList, getSpecifiedImage }