Skip to content

Commit

Permalink
fix: incorrect ETA
Browse files Browse the repository at this point in the history
  • Loading branch information
AnotiaWang committed Jan 18, 2024
1 parent ac14883 commit 19b131f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/handler/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,13 @@ export async function transfer(msg: Api.Message) {
})
downloadedChunks += chunksToDownload

const now = Date.now()
// Update the progress message every 3 seconds
if (downloadedBytes && Date.now() - lastEditTime > 3000) {
if (downloadedBytes && now - lastEditTime > 3000) {
// Convert to MB
const downloaded = +(downloadedBytes / 1000 / 1000).toFixed(2)
const total = +(fileSize / 1000 / 1000).toFixed(2)
const speed = +((downloaded - lastDownloadSize) / 3).toFixed(2)
const speed = +((downloaded - lastDownloadSize) / ((now - lastEditTime) / 1000)).toFixed(2)
const percent = Math.round((downloaded / total) * 100)
const text =
strings[lang]['downloadProgress']
Expand All @@ -145,7 +146,7 @@ export async function transfer(msg: Api.Message) {
.replace('{3}', speed.toString())
.replace('{4}', secToTime(Math.round((total - downloaded) / speed))) +
`\n\n<code>[${'●'.repeat(percent / 5.5)}${'○'.repeat(18 - percent / 5.5)}]</code>`
lastEditTime = Date.now()
lastEditTime = now
lastDownloadSize = downloaded

bot
Expand Down

0 comments on commit 19b131f

Please sign in to comment.