Added file upload UI
This commit is contained in:
19
frontend/src/app/format-file-size-pipe.pipe.ts
Normal file
19
frontend/src/app/format-file-size-pipe.pipe.ts
Normal 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]}`;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user