This commit is contained in:
Horis
2024-07-26 12:48:00 +08:00
parent d239583ced
commit c7fdefbb21
2 changed files with 12 additions and 6 deletions

View File

@@ -1,6 +1,7 @@
package io.legado.app.help.update
import com.google.gson.annotations.SerializedName
import io.legado.app.exception.NoStackTraceException
import java.time.Instant
data class AppReleaseInfo(
@@ -33,10 +34,10 @@ data class GithubRelease(
val isPreRelease: Boolean,
) {
fun gitReleaseToAppReleaseInfo(): List<AppReleaseInfo> {
assets ?: throw NoStackTraceException("获取新版本出错")
return assets
?.filter { it.isValid }
?.map { it.assetToAppReleaseInfo(isPreRelease, body) }
.orEmpty()
.filter { it.isValid }
.map { it.assetToAppReleaseInfo(isPreRelease, body) }
}
}

View File

@@ -5,8 +5,9 @@ import io.legado.app.constant.AppConst
import io.legado.app.exception.NoStackTraceException
import io.legado.app.help.config.AppConfig
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.http.newCallStrResponse
import io.legado.app.help.http.newCallResponse
import io.legado.app.help.http.okHttpClient
import io.legado.app.help.http.text
import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject
import kotlinx.coroutines.CoroutineScope
@@ -29,9 +30,13 @@ object AppUpdateGitHub : AppUpdate.AppUpdateInterface {
} else {
"https://api.github.com/repos/gedoor/legado/releases/latest"
}
val body = okHttpClient.newCallStrResponse {
val res = okHttpClient.newCallResponse {
url(lastReleaseUrl)
}.body
}
if (!res.isSuccessful) {
throw NoStackTraceException("获取新版本出错(${res.code})")
}
val body = res.body?.text()
if (body.isNullOrBlank()) {
throw NoStackTraceException("获取新版本出错")
}