Initial commit
This commit is contained in:
68
src/utils/fileHelpers.ts
Normal file
68
src/utils/fileHelpers.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import { FileEntityObject } from '@FileManager/models/entity'
|
||||
|
||||
/**
|
||||
* Get the appropriate icon for a file based on its MIME type
|
||||
*/
|
||||
export function getFileIcon(entity: FileEntityObject): string {
|
||||
const mime = entity.mime || ''
|
||||
if (!mime) return 'mdi-file'
|
||||
if (mime.startsWith('image/')) return 'mdi-file-image'
|
||||
if (mime.startsWith('video/')) return 'mdi-file-video'
|
||||
if (mime.startsWith('audio/')) return 'mdi-file-music'
|
||||
if (mime.startsWith('text/')) return 'mdi-file-document'
|
||||
if (mime === 'application/pdf') return 'mdi-file-pdf-box'
|
||||
if (mime.includes('zip') || mime.includes('tar') || mime.includes('compressed')) return 'mdi-folder-zip'
|
||||
if (mime.includes('word') || mime.includes('document')) return 'mdi-file-word'
|
||||
if (mime.includes('excel') || mime.includes('spreadsheet')) return 'mdi-file-excel'
|
||||
if (mime.includes('powerpoint') || mime.includes('presentation')) return 'mdi-file-powerpoint'
|
||||
return 'mdi-file'
|
||||
}
|
||||
|
||||
/**
|
||||
* Format file size in human readable format
|
||||
*/
|
||||
export function formatSize(bytes: number): string {
|
||||
if (bytes === 0) return '0 B'
|
||||
const k = 1024
|
||||
const sizes = ['B', 'KB', 'MB', 'GB', 'TB']
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]
|
||||
}
|
||||
|
||||
/**
|
||||
* Format date string to localized format
|
||||
*/
|
||||
export function formatDate(dateStr: string): string {
|
||||
if (!dateStr) return '—'
|
||||
return new Date(dateStr).toLocaleDateString('en-US', {
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Get upload status icon
|
||||
*/
|
||||
export function getUploadStatusIcon(status: string): string {
|
||||
switch (status) {
|
||||
case 'pending': return 'mdi-clock-outline'
|
||||
case 'uploading': return 'mdi-loading mdi-spin'
|
||||
case 'completed': return 'mdi-check-circle'
|
||||
case 'error': return 'mdi-alert-circle'
|
||||
default: return 'mdi-file'
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get upload status color
|
||||
*/
|
||||
export function getUploadStatusColor(status: string): string {
|
||||
switch (status) {
|
||||
case 'pending': return 'grey'
|
||||
case 'uploading': return 'primary'
|
||||
case 'completed': return 'success'
|
||||
case 'error': return 'error'
|
||||
default: return 'grey'
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user