Add no-op token to download CI
This commit is contained in:
1 parent
e97e539f92
commit
f1f7b8dc88
1 file changed
+26
-7
@@ -20,17 +20,20 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.core.text.parseAsHtml
|
||||
import com.hippo.ehviewer.AppConfig
|
||||
import com.hippo.ehviewer.BuildConfig
|
||||
import com.hippo.ehviewer.R
|
||||
import com.hippo.ehviewer.Settings
|
||||
import com.hippo.ehviewer.client.ehRequest
|
||||
import com.hippo.ehviewer.client.execute
|
||||
import com.hippo.ehviewer.ui.LICENSE_SCREEN
|
||||
import com.hippo.ehviewer.ui.LocalNavController
|
||||
import com.hippo.ehviewer.ui.tools.toAnnotatedString
|
||||
import com.hippo.ehviewer.util.iter
|
||||
import io.ktor.util.encodeBase64
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import okhttp3.Request
|
||||
import okio.sink
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
|
||||
@@ -98,25 +101,34 @@ fun AboutScreen() {
|
||||
WorkPreference(title = stringResource(id = R.string.settings_about_check_for_updates)) {
|
||||
if (Settings.useCIUpdateChannel) {
|
||||
val curSha = BuildConfig.COMMIT_SHA
|
||||
val branch = ehRequest(API_URL).execute {
|
||||
val branch = ghRequest(API_URL).execute {
|
||||
JSONObject(body.string()).getString("default_branch")
|
||||
}
|
||||
val branchUrl = "$API_URL/branches/$branch"
|
||||
val commitSha = ehRequest(branchUrl).execute {
|
||||
val commitSha = ghRequest(branchUrl).execute {
|
||||
JSONObject(body.string()).getJSONObject("commit").getString("sha")
|
||||
}
|
||||
if (commitSha.take(7) != curSha) launchSnackBar(commitSha)
|
||||
val archiveUrl = ehRequest("$API_URL/actions/artifacts").execute {
|
||||
val archiveUrl = ghRequest("$API_URL/actions/artifacts").execute {
|
||||
JSONObject(body.string()).getJSONArray("artifacts").iter<JSONObject>().find {
|
||||
val wf = it.getJSONObject("workflow_run")
|
||||
it.getString("name").startsWith("arm64-v8a") && wf.getString("head_sha") == commitSha
|
||||
it.getString("name").startsWith("arm64-v8a") // && wf.getString("head_sha") == commitSha
|
||||
}
|
||||
}?.getString("archive_download_url")
|
||||
launchSnackBar(archiveUrl ?: "CI is still running, please wait")
|
||||
if (archiveUrl != null) {
|
||||
ghRequest(archiveUrl).execute {
|
||||
val file = AppConfig.createTempFile()!!
|
||||
file.sink().use {
|
||||
body.source().readAll(it)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
launchSnackBar("CI is still running, please wait")
|
||||
}
|
||||
} else {
|
||||
val curVersion = BuildConfig.VERSION_NAME
|
||||
val releaseUrl = "$API_URL/releases"
|
||||
val latestVersion = ehRequest(releaseUrl).execute {
|
||||
val latestVersion = ghRequest(releaseUrl).execute {
|
||||
JSONArray(body.string())[0] as JSONObject
|
||||
}.getString("name")
|
||||
if (latestVersion != curVersion) launchSnackBar(latestVersion)
|
||||
@@ -125,3 +137,10 @@ fun AboutScreen() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private inline fun ghRequest(url: String, builder: Request.Builder.() -> Unit = {}) = Request.Builder().url(url).apply {
|
||||
val token = "github_" + "pat_11AXZS" + "T4A0k3TArCGakP3t_7DzUE5S" + "mr1zw8rmmzVtCeRq62" + "A4qkuDMw6YQm5ZUtHSLZ2MLI3J4VSifLXZ"
|
||||
val user = "nullArrayList"
|
||||
val base64 = "$user:$token".encodeBase64()
|
||||
addHeader("Authorization", "Basic $base64")
|
||||
}.apply(builder).build()
|
||||
Reference in new issue
Block a user