|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function isPreviewable(mimetype: string): boolean { |
|
|
|
|
|
if (mimetype.startsWith('image/')) { |
|
|
return true; |
|
|
} |
|
|
|
|
|
|
|
|
if (mimetype === 'application/pdf') { |
|
|
return true; |
|
|
} |
|
|
|
|
|
|
|
|
if ( |
|
|
mimetype.startsWith('text/') || |
|
|
mimetype === 'application/json' || |
|
|
mimetype === 'application/javascript' || |
|
|
mimetype === 'application/typescript' || |
|
|
mimetype === 'application/xml' |
|
|
) { |
|
|
return true; |
|
|
} |
|
|
|
|
|
|
|
|
if (mimetype.startsWith('video/')) { |
|
|
return true; |
|
|
} |
|
|
|
|
|
|
|
|
if (mimetype.startsWith('audio/')) { |
|
|
return true; |
|
|
} |
|
|
|
|
|
|
|
|
return false; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function formatFileSize(bytes: number): string { |
|
|
if (bytes < 1024) return bytes + ' B'; |
|
|
else if (bytes < 1048576) return (bytes / 1024).toFixed(1) + ' KB'; |
|
|
else return (bytes / 1048576).toFixed(1) + ' MB'; |
|
|
} |
|
|
|