Fix incorrect progress when resuming resumable image downloads (#3616)

This commit is contained in:
Mohannad
2026-07-21 14:46:57 +03:00
committed by GitHub
parent 47aa9190d4
commit 6981185f4b
3 changed files with 10 additions and 2 deletions
+1
View File
@@ -14,6 +14,7 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co
### Added
- Support resumable image downloads if supported by source ([@xMohnad](https://github.com/xMohnad)) ([#3167](https://github.com/mihonapp/mihon/pull/3167))
- Fix HTTP Error 416 not being handled properly ([@AntsyLich](https://github.com/AntsyLich)) ([#3563](https://github.com/mihonapp/mihon/pull/3563))
- Fix incorrect progress when resuming downloads ([@xMohnad](https://github.com/xMohnad)) ([#3616](https://github.com/mihonapp/mihon/pull/3616))
### Changed
- Detect Shizuku with permission check ([@Small-Ku](https://github.com/Small-Ku)) ([#3565](https://github.com/mihonapp/mihon/pull/3565))
@@ -136,8 +136,9 @@ fun OkHttpClient.newCachelessCallWithProgress(
.build()
val originalResponse = chain.proceed(request)
val actualExistingSize = if (originalResponse.code == 206) existingSize else 0L
originalResponse.newBuilder()
.body(ProgressResponseBody(originalResponse.body, listener, existingSize))
.body(ProgressResponseBody(originalResponse.body, listener, actualExistingSize))
.build()
}
.build()
@@ -40,9 +40,15 @@ class ProgressResponseBody(
val bytesRead = super.read(sink, byteCount)
// read() returns the number of bytes read, or -1 if this source is exhausted.
totalBytesRead += if (bytesRead != -1L) bytesRead else 0
// contentLength() returns -1L if Content-Length is missing
val totalLength = responseBody.contentLength().let {
if (it != -1L) it + existingSize else -1L
}
progressListener.update(
totalBytesRead,
responseBody.contentLength(),
totalLength,
bytesRead == -1L,
)
return bytesRead