refactor: standardize design
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { FileEntityObject } from '@FilesManager/models/entity'
|
||||
import { EntityObject } from '@DocumentsManager/models/entity'
|
||||
|
||||
/**
|
||||
* Get the appropriate icon for a file based on its MIME type
|
||||
*/
|
||||
export function getFileIcon(entity: FileEntityObject): string {
|
||||
const mime = entity.mime || ''
|
||||
export function getFileIcon(entity: EntityObject): string {
|
||||
const mime = entity.properties.mime || ''
|
||||
if (!mime) return 'mdi-file'
|
||||
if (mime.startsWith('image/')) return 'mdi-file-image'
|
||||
if (mime.startsWith('video/')) return 'mdi-file-video'
|
||||
@@ -22,19 +22,22 @@ export function getFileIcon(entity: FileEntityObject): string {
|
||||
* Format file size in human readable format
|
||||
*/
|
||||
export function formatSize(bytes: number): string {
|
||||
if (bytes === 0) return '0 B'
|
||||
const safeBytes = Number.isFinite(bytes) ? bytes : 0
|
||||
if (safeBytes === 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]
|
||||
const i = Math.floor(Math.log(safeBytes) / Math.log(k))
|
||||
return parseFloat((safeBytes / 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', {
|
||||
export function formatDate(value: Date | string | null | undefined): string {
|
||||
if (!value) return '—'
|
||||
const date = value instanceof Date ? value : new Date(value)
|
||||
if (Number.isNaN(date.getTime())) return '—'
|
||||
return date.toLocaleDateString('en-US', {
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
|
||||
Reference in New Issue
Block a user