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
@@ -1,6 +1,7 @@
package io.legado.app.help.update package io.legado.app.help.update
import com.google.gson.annotations.SerializedName import com.google.gson.annotations.SerializedName
import io.legado.app.exception.NoStackTraceException
import java.time.Instant import java.time.Instant
data class AppReleaseInfo( data class AppReleaseInfo(
@@ -33,10 +34,10 @@ data class GithubRelease(
val isPreRelease: Boolean, val isPreRelease: Boolean,
) { ) {
fun gitReleaseToAppReleaseInfo(): List<AppReleaseInfo> { fun gitReleaseToAppReleaseInfo(): List<AppReleaseInfo> {
assets ?: throw NoStackTraceException("获取新版本出错")
return assets return assets
?.filter { it.isValid } .filter { it.isValid }
?.map { it.assetToAppReleaseInfo(isPreRelease, body) } .map { it.assetToAppReleaseInfo(isPreRelease, body) }
.orEmpty()
} }
} }
@@ -5,8 +5,9 @@ import io.legado.app.constant.AppConst
import io.legado.app.exception.NoStackTraceException import io.legado.app.exception.NoStackTraceException
import io.legado.app.help.config.AppConfig import io.legado.app.help.config.AppConfig
import io.legado.app.help.coroutine.Coroutine 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.okHttpClient
import io.legado.app.help.http.text
import io.legado.app.utils.GSON import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject import io.legado.app.utils.fromJsonObject
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
@@ -29,9 +30,13 @@ object AppUpdateGitHub : AppUpdate.AppUpdateInterface {
} else { } else {
"https://api.github.com/repos/gedoor/legado/releases/latest" "https://api.github.com/repos/gedoor/legado/releases/latest"
} }
val body = okHttpClient.newCallStrResponse { val res = okHttpClient.newCallResponse {
url(lastReleaseUrl) url(lastReleaseUrl)
}.body }
if (!res.isSuccessful) {
throw NoStackTraceException("获取新版本出错(${res.code})")
}
val body = res.body?.text()
if (body.isNullOrBlank()) { if (body.isNullOrBlank()) {
throw NoStackTraceException("获取新版本出错") throw NoStackTraceException("获取新版本出错")
} }