download speed
This commit is contained in:
@@ -15,7 +15,7 @@
|
|||||||
* [x] Link sharing and better workflow
|
* [x] Link sharing and better workflow
|
||||||
* [x] Multiple peers
|
* [x] Multiple peers
|
||||||
* [x] Get peer data
|
* [x] Get peer data
|
||||||
* [ ] See download speed
|
* [x] See download speed
|
||||||
* [ ] DaisyUI redesign
|
* [ ] DaisyUI redesign
|
||||||
* [ ] QRCode
|
* [ ] QRCode
|
||||||
* [ ] Multiple files
|
* [ ] Multiple files
|
||||||
|
|||||||
+2
-1
@@ -58,7 +58,8 @@
|
|||||||
<br>
|
<br>
|
||||||
</template>
|
</template>
|
||||||
<template v-if="downloading">
|
<template v-if="downloading">
|
||||||
<progress :value="downloadProgress" :max="downloadTotal"></progress>
|
<progress :value="downloadProgress" :max="downloadTotal"></progress><br>
|
||||||
|
<label>{{ prettyDownloadSpeed }}</label><label v-if="!client.downloadEnd"> - {{ prettyRemainingTime }}</label>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -23,7 +23,35 @@ const utils = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 'Unknown'
|
return 'Unknown'
|
||||||
}
|
},
|
||||||
|
prettyBytes(byteCount) {
|
||||||
|
let size = byteCount / 1000;
|
||||||
|
if (size < 1000) {
|
||||||
|
return `${size.toFixed(2)} KB`;
|
||||||
|
}
|
||||||
|
size /= 1000;
|
||||||
|
if (size < 1000) {
|
||||||
|
return `${size.toFixed(2)} MB`;
|
||||||
|
}
|
||||||
|
size /= 1000;
|
||||||
|
return `${size.toFixed(2)} GB`;
|
||||||
|
},
|
||||||
|
|
||||||
|
prettyTime(deltaMillisecond) {
|
||||||
|
let time = deltaMillisecond / 1000;
|
||||||
|
if (time <= 1) {
|
||||||
|
return `<1s`;
|
||||||
|
}
|
||||||
|
if (time < 60) {
|
||||||
|
return `${Math.floor(time).toFixed(0).padStart(2, '0')}s`;
|
||||||
|
}
|
||||||
|
time /= 60;
|
||||||
|
if (time < 60) {
|
||||||
|
return `${Math.floor(time).toFixed(0).padStart(2, '0')}m${((time * 60) % 60).toFixed(0).padStart(2, '0')}s`;
|
||||||
|
}
|
||||||
|
time /= 60;
|
||||||
|
return `${Math.floor(time).toFixed(0).padStart(2, '0')}h${((time * 60) % 60).toFixed(0).padStart(2, '0')}m`;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const MESSAGE_TYPE = {
|
const MESSAGE_TYPE = {
|
||||||
@@ -57,6 +85,7 @@ const app = createApp({
|
|||||||
connection: null,
|
connection: null,
|
||||||
connected: false,
|
connected: false,
|
||||||
downloadStart: null,
|
downloadStart: null,
|
||||||
|
downloadEnd: null,
|
||||||
received: [],
|
received: [],
|
||||||
buffer: null, // TODO multiple files
|
buffer: null, // TODO multiple files
|
||||||
},
|
},
|
||||||
@@ -113,22 +142,31 @@ const app = createApp({
|
|||||||
if (! this.downloading) {
|
if (! this.downloading) {
|
||||||
return 'Waiting for file info...';
|
return 'Waiting for file info...';
|
||||||
}
|
}
|
||||||
if (this.downloadProgress > this.downloadTotal) {
|
if (this.client.downloadEnd) {
|
||||||
return 'File downloaded';
|
return 'File downloaded';
|
||||||
}
|
}
|
||||||
return 'Downloading...';
|
return 'Downloading...';
|
||||||
},
|
},
|
||||||
prettyFileSize() {
|
prettyFileSize() {
|
||||||
let size = this.fileSize / 1000;
|
return utils.prettyBytes(this.fileSize);
|
||||||
if (size < 1000) {
|
},
|
||||||
return `${size.toFixed(2)} KB`;
|
prettyDownloadSpeed() {
|
||||||
|
if (! this.client.downloadStart) {
|
||||||
|
return '';
|
||||||
}
|
}
|
||||||
size /= 1000;
|
const time = (this.client.downloadEnd ?? (new Date())) - this.client.downloadStart;
|
||||||
if (size < 1000) {
|
const speed = 1000 * this.downloadProgress / time;
|
||||||
return `${size.toFixed(2)} MB`;
|
return `${utils.prettyBytes(speed)}/s`;
|
||||||
|
},
|
||||||
|
prettyRemainingTime() {
|
||||||
|
if (! this.client.downloadStart || this.client.downloadEnd) {
|
||||||
|
return '';
|
||||||
}
|
}
|
||||||
size /= 1000;
|
const time = (this.client.downloadEnd ?? (new Date())) - this.client.downloadStart;
|
||||||
return `${size.toFixed(2)} GB`;
|
const speed = this.downloadProgress / time;
|
||||||
|
const remainingBytes = this.downloadTotal - this.downloadProgress;
|
||||||
|
const remainingTime = remainingBytes / speed;
|
||||||
|
return `${utils.prettyTime(remainingTime)}`;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
watch: {},
|
watch: {},
|
||||||
@@ -364,6 +402,7 @@ const app = createApp({
|
|||||||
if (indexes.length) {
|
if (indexes.length) {
|
||||||
this.sendClientSeek(indexes);
|
this.sendClientSeek(indexes);
|
||||||
} else {
|
} else {
|
||||||
|
this.client.downloadEnd = new Date();
|
||||||
this.sendClientDone();
|
this.sendClientDone();
|
||||||
this.clientDownloadFile();
|
this.clientDownloadFile();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user