UNPKG

ice.fo.utils

Version:

24 lines (18 loc) 589 B
import makeIconForExtension from './makeIconForExtension'; export default function makeFileInfo(data) { if (!data) { return {}; } const { fileName = '', fileSize, storePath } = data; const actualFileSize = fileSize ? fileSize / (1024 * 1024) : 0; const fileExtension = fileName.split('.').pop(); const link = storePath && storePath.startsWith('/file') ? storePath : `/file/${storePath}`; const icon = makeIconForExtension(fileExtension); return { icon, size: `${actualFileSize.toFixed(2)}MB`, link, name: fileName, url: storePath || '', }; }