Fix incorrect progress when resuming resumable image downloads (#3616)
This commit is contained in:
@@ -14,6 +14,7 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co
|
|||||||
### Added
|
### Added
|
||||||
- Support resumable image downloads if supported by source ([@xMohnad](https://github.com/xMohnad)) ([#3167](https://github.com/mihonapp/mihon/pull/3167))
|
- 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 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
|
### Changed
|
||||||
- Detect Shizuku with permission check ([@Small-Ku](https://github.com/Small-Ku)) ([#3565](https://github.com/mihonapp/mihon/pull/3565))
|
- 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()
|
.build()
|
||||||
|
|
||||||
val originalResponse = chain.proceed(request)
|
val originalResponse = chain.proceed(request)
|
||||||
|
val actualExistingSize = if (originalResponse.code == 206) existingSize else 0L
|
||||||
originalResponse.newBuilder()
|
originalResponse.newBuilder()
|
||||||
.body(ProgressResponseBody(originalResponse.body, listener, existingSize))
|
.body(ProgressResponseBody(originalResponse.body, listener, actualExistingSize))
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
.build()
|
.build()
|
||||||
|
|||||||
@@ -40,9 +40,15 @@ class ProgressResponseBody(
|
|||||||
val bytesRead = super.read(sink, byteCount)
|
val bytesRead = super.read(sink, byteCount)
|
||||||
// read() returns the number of bytes read, or -1 if this source is exhausted.
|
// read() returns the number of bytes read, or -1 if this source is exhausted.
|
||||||
totalBytesRead += if (bytesRead != -1L) bytesRead else 0
|
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(
|
progressListener.update(
|
||||||
totalBytesRead,
|
totalBytesRead,
|
||||||
responseBody.contentLength(),
|
totalLength,
|
||||||
bytesRead == -1L,
|
bytesRead == -1L,
|
||||||
)
|
)
|
||||||
return bytesRead
|
return bytesRead
|
||||||
|
|||||||
Reference in New Issue
Block a user