添加共存版的检查更新
This commit is contained in:
@@ -1,51 +1,34 @@
|
||||
package io.legado.app
|
||||
|
||||
import com.google.gson.Gson
|
||||
import io.legado.app.exception.NoStackTraceException
|
||||
import io.legado.app.help.http.okHttpClient
|
||||
import io.legado.app.utils.channel
|
||||
import io.legado.app.utils.jsonPath
|
||||
import io.legado.app.model.GithubRelease
|
||||
import io.legado.app.utils.fromJsonArray
|
||||
import okhttp3.Request
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import splitties.init.appCtx
|
||||
|
||||
class UpdateTest {
|
||||
|
||||
private val lastReleaseUrl = "https://api.github.com/repos/gedoor/legado/releases/latest"
|
||||
private val lastReleaseUrl =
|
||||
"https://api.github.com/repos/gedoor/legado/releases?page=1?per_page=1"
|
||||
|
||||
@Test
|
||||
fun updateApp() {
|
||||
val body = okHttpClient.newCall(Request.Builder().url(lastReleaseUrl).build()).execute()
|
||||
.body!!.string()
|
||||
val rootDoc = jsonPath.parse(body)
|
||||
val downloadUrl =
|
||||
rootDoc.read<List<String>>("\$.assets[?(@.name =~ /legado_app_.*?apk\$/)].browser_download_url")
|
||||
print(downloadUrl)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun updateLollipop() {
|
||||
val body = okHttpClient.newCall(Request.Builder().url(lastReleaseUrl).build()).execute()
|
||||
.body!!.string()
|
||||
val rootDoc = jsonPath.parse(body)
|
||||
val downloadUrl =
|
||||
rootDoc.read<List<String>>("\$.assets[?(@.name =~ /legado_lollipop_.*?apk\$/)].browser_download_url")
|
||||
print(downloadUrl)
|
||||
}
|
||||
val releaseList = Gson().fromJsonArray<GithubRelease>(body)
|
||||
.getOrElse {
|
||||
throw NoStackTraceException("获取新版本出错 " + it.localizedMessage)
|
||||
}
|
||||
.flatMap { it.gitReleaseToAppReleaseInfo() }
|
||||
.sortedByDescending { it.createdAt }
|
||||
|
||||
@Test
|
||||
fun updateChannel() {
|
||||
val body = okHttpClient.newCall(Request.Builder().url(lastReleaseUrl).build()).execute()
|
||||
.body!!.string()
|
||||
val rootDoc = jsonPath.parse(body)
|
||||
val path = "\$.assets[?(@.name =~ /legado_${appCtx.channel}_.*?apk\$/)]"
|
||||
val downloadUrl = rootDoc.read<List<String>>("${path}.browser_download_url")
|
||||
.firstOrNull()
|
||||
?: throw NoStackTraceException("获取新版本出错")
|
||||
val fileName = rootDoc.read<List<String>>("${path}.name")
|
||||
.firstOrNull()
|
||||
?: throw NoStackTraceException("获取新版本出错")
|
||||
print(downloadUrl)
|
||||
print(fileName)
|
||||
assertTrue(releaseList.isNotEmpty())
|
||||
assertTrue(releaseList.all { it.downloadUrl.isNotBlank() })
|
||||
assertTrue(releaseList.all { it.versionName.isNotBlank() })
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user