diff --git a/frontend/src/app/format-file-size-pipe.pipe.spec.ts b/frontend/src/app/format-file-size-pipe.pipe.spec.ts new file mode 100644 index 0000000..0d1235e --- /dev/null +++ b/frontend/src/app/format-file-size-pipe.pipe.spec.ts @@ -0,0 +1,8 @@ +import { FormatFileSizePipePipe } from './format-file-size-pipe.pipe'; + +describe('FormatFileSizePipePipe', () => { + it('create an instance', () => { + const pipe = new FormatFileSizePipePipe(); + expect(pipe).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/format-file-size-pipe.pipe.ts b/frontend/src/app/format-file-size-pipe.pipe.ts new file mode 100644 index 0000000..b7c1040 --- /dev/null +++ b/frontend/src/app/format-file-size-pipe.pipe.ts @@ -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]}`; + } + +} diff --git a/frontend/src/app/upload/upload.component.html b/frontend/src/app/upload/upload.component.html index 2be1da3..f905d7d 100644 --- a/frontend/src/app/upload/upload.component.html +++ b/frontend/src/app/upload/upload.component.html @@ -1,34 +1,63 @@
Drag and drop your files here or browse
- + +{{ fileToUpload.name }}
+{{ fileToUpload.size | formatFileSizePipe }}
Uploading {{ fileToUpload.name }}...
+File uploaded successfully!
+Drag and drop files, or click to select the files you want to share.