Add transactional file storage workflows, typed API contracts, recursive category handling, frontend component separation, and Files API coverage.
32 lines
813 B
TypeScript
32 lines
813 B
TypeScript
export function formatFileSize(bytes: number): string {
|
|
if (bytes === 0) return '0 B'
|
|
const units = ['B', 'KB', 'MB', 'GB']
|
|
const index = Math.min(Math.floor(Math.log(bytes) / Math.log(1024)), units.length - 1)
|
|
return `${(bytes / Math.pow(1024, index)).toFixed(index === 0 ? 0 : 1)} ${units[index]}`
|
|
}
|
|
|
|
const extensionColors: Record<string, string> = {
|
|
txt: '#666666',
|
|
md: '#1677ff',
|
|
json: '#389e0d',
|
|
yaml: '#08979c',
|
|
yml: '#08979c',
|
|
csv: '#d46b08',
|
|
xml: '#531dab',
|
|
xlsx: '#237804',
|
|
xls: '#237804',
|
|
png: '#c41d7f',
|
|
jpg: '#c41d7f',
|
|
jpeg: '#c41d7f',
|
|
gif: '#c41d7f',
|
|
svg: '#c41d7f',
|
|
zip: '#cf1322',
|
|
py: '#1d39c4',
|
|
js: '#ad8b00',
|
|
ts: '#0958d9',
|
|
}
|
|
|
|
export function extensionColor(extension: string): string {
|
|
return extensionColors[extension.toLowerCase()] || '#595959'
|
|
}
|