Adding the ability to track file upload percentage and currently uploaded/total upload

This commit is contained in:
Alex Yong 2024-04-11 19:32:33 +00:00
parent ae0af1f996
commit 7634992946
2 changed files with 14 additions and 0 deletions

View File

@ -10,6 +10,8 @@
<div class="upload-info"> <div class="upload-info">
<div class="upload-speed">{{ uploadSpeed.toFixed(2) }} MB/s</div> <div class="upload-speed">{{ uploadSpeed.toFixed(2) }} MB/s</div>
<div class="upload-eta">{{ formattedETA }} remaining</div> <div class="upload-eta">{{ formattedETA }} remaining</div>
<div class="upload-percentage"> {{ getProgress }} % Completed </div>
<div class="upload-fraction"> / {{ getTotalSize }} </div>
</div> </div>
<button <button
class="action" class="action"
@ -72,6 +74,8 @@ export default {
"filesInUploadCount", "filesInUploadCount",
"uploadSpeed", "uploadSpeed",
"getETA", "getETA",
"getProgress",
"getTotalSize"
]), ]),
...mapWritableState(useFileStore, ["reload"]), ...mapWritableState(useFileStore, ["reload"]),
...mapActions(useUploadStore, ["reset"]), ...mapActions(useUploadStore, ["reset"]),

View File

@ -47,6 +47,16 @@ export const useUploadStore = defineStore("upload", {
const sum = state.progress.reduce((acc, val) => +acc + +val) as number; const sum = state.progress.reduce((acc, val) => +acc + +val) as number;
return Math.ceil((sum / totalSize) * 100); return Math.ceil((sum / totalSize) * 100);
}, },
getTotalSize: (state) => {
if (state.sizes.length === 0) {
return '0 Bytes';
}
const totalSize = state.sizes.reduce((a, b) => a + b, 0);
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const i = Math.floor(Math.log(totalSize) / Math.log(1024));
return parseFloat((totalSize / Math.pow(1024, i)).toFixed(2)) + ' ' + sizes[i];
},
filesInUploadCount: (state) => { filesInUploadCount: (state) => {
return Object.keys(state.uploads).length + state.queue.length; return Object.keys(state.uploads).length + state.queue.length;
}, },