Added file upload UI

This commit is contained in:
2024-02-07 23:51:58 +01:00
parent c05cd770c6
commit b15529008b
6 changed files with 136 additions and 12 deletions

View File

@@ -0,0 +1,19 @@
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'formatFileSizePipe',
standalone: true
})
export class FormatFileSizePipePipe implements PipeTransform {
transform(value: number, ...args: unknown[]): string {
if (value === null || value === 0) return '0 Bytes';
const units = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const index = Math.min(Math.floor(Math.log(value) / Math.log(1024)), units.length - 1);
const filesize = Number((value / Math.pow(1024, index)).toFixed(2));
return `${filesize.toLocaleString()} ${units[index]}`;
}
}