const sizes = ['B', 'KB', 'MB', 'GB'] export const formatFileSize = (bytes) => { if (!bytes) { return `0 ${sizes[0]}` } const k = 1024 const i = Math.floor(Math.log(bytes) / Math.log(k)) const formattedSize = parseFloat((bytes / Math.pow(k, i)).toFixed(1)) return `${formattedSize} ${sizes[i]}` } export const downloadFiles = (files) => { files.forEach((file) => { const link = document.createElement('a') link.href = file.url link.download = file.filename || '' document.body.appendChild(link) link.click() link.remove() }) }