From e3f4c24983e7265eb5aa8afca0f52708393a164c Mon Sep 17 00:00:00 2001 From: FooIbar <118464521+FooIbar@users.noreply.github.com> Date: Sat, 9 Nov 2024 13:49:46 +0800 Subject: [PATCH] Extend update download request timeout --- .../com/hippo/ehviewer/updater/AppUpdater.kt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/hippo/ehviewer/updater/AppUpdater.kt b/app/src/main/kotlin/com/hippo/ehviewer/updater/AppUpdater.kt index 4176b2cf6..06bc77a73 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/updater/AppUpdater.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/updater/AppUpdater.kt @@ -7,6 +7,8 @@ import com.hippo.ehviewer.client.executeAndParseAs import com.hippo.ehviewer.client.executeSafely import com.hippo.ehviewer.util.copyTo import com.hippo.ehviewer.util.ensureSuccess +import io.ktor.client.plugins.timeout +import io.ktor.client.request.HttpRequestBuilder import io.ktor.client.request.header import io.ktor.client.request.prepareGet import io.ktor.client.statement.bodyAsChannel @@ -66,7 +68,11 @@ object AppUpdater { return null } - suspend fun downloadUpdate(url: String, file: File) = ghStatement(url).executeSafely { response -> + suspend fun downloadUpdate(url: String, file: File) = ghStatement(url) { + timeout { + requestTimeoutMillis = 60_000 + } + }.executeSafely { response -> response.status.ensureSuccess() if (url.endsWith("zip")) { response.bodyAsChannel().toInputStream().use { stream -> @@ -83,8 +89,12 @@ object AppUpdater { } } -private suspend inline fun ghStatement(url: String) = ktorClient.prepareGet(url) { +private suspend inline fun ghStatement( + url: String, + builder: HttpRequestBuilder.() -> Unit = {}, +) = ktorClient.prepareGet(url) { header("Authorization", GithubTokenParts.joinToString("_", prefix = "Bearer ")) + apply(builder) } private val GithubTokenParts = arrayOf(