Skip to content

Commit

Permalink
fix(core-websdk/cloud_config): fix null value
Browse files Browse the repository at this point in the history
Use data classes directly to avoid null
  • Loading branch information
xz-dev committed Aug 13, 2022
1 parent 8096e27 commit 9758d27
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 37 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ android {
minSdkVersion 21
targetSdkVersion 33
versionCode 101
versionName "0.13-alpha.5"
versionName "0.13-beta.1"
if (project.hasProperty('appVerName')) {
versionName = "${versionName}_${appVerName}"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.xzos.upgradeall.core.websdk.api.client_proxy.cloud_config

import com.google.gson.Gson
import net.xzos.upgradeall.core.websdk.api.client_proxy.cloud_config.migration.app1to2
import net.xzos.upgradeall.core.websdk.api.client_proxy.cloud_config.migration.hub5to6
import net.xzos.upgradeall.core.websdk.api.web.http.HttpRequestData
Expand All @@ -21,20 +20,12 @@ internal class CloudConfig(private val okHttpApi: OkhttpProxy) {
val hubList = mutableListOf<HubConfigGson>()
for (i in 0 until appJsonList.length()) {
val appJson = appJsonList.getJSONObject(i)
app1to2(appJson)?.toString()?.let {
appList.add(gson.fromJson(it, AppConfigGson::class.java))
}
app1to2(appJson)?.let { appList.add(it) }
}
for (i in 0 until hubJsonList.length()) {
val hubJson = hubJsonList.getJSONObject(i)
hub5to6(hubJson)?.toString()?.let {
hubList.add(gson.fromJson(it, HubConfigGson::class.java))
}
hub5to6(hubJson)?.let { hubList.add(it) }
}
return CloudConfigList(appList, hubList)
}

companion object {
private val gson = Gson()
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package net.xzos.upgradeall.core.websdk.api.client_proxy.cloud_config.migration

import net.xzos.upgradeall.core.websdk.json.AppConfigGson
import org.json.JSONObject

fun app1to2(oldJson: JSONObject): JSONObject? {
fun app1to2(oldJson: JSONObject): AppConfigGson? {
fun apiConvert(s: String) = when (s.lowercase()) {
"app_package" -> "android_app_package"
"magisk_module" -> "android_magisk_module"
Expand All @@ -14,20 +15,20 @@ fun app1to2(oldJson: JSONObject): JSONObject? {
if (oldJson.optInt("base_version") != 1) return null
val targetCheckerJson = oldJson.getJSONObject("app_config")
.getJSONObject("target_checker")
val map = mapOf(
"base_version" to 2,
"config_version" to oldJson.getJSONObject("info").optInt("config_version"),
"uuid" to oldJson.optString("uuid"),
"base_hub_uuid" to oldJson.getJSONObject("app_config")
return AppConfigGson(
baseVersion = 2,
configVersion = oldJson.getJSONObject("info").optInt("config_version"),
uuid = oldJson.optString("uuid"),
baseHubUuid = oldJson.getJSONObject("app_config")
.getJSONObject("hub_info")
.optString("hub_uuid"),
"info" to mapOf(
"name" to oldJson.getJSONObject("info").optString("app_name"),
"url" to oldJson.getJSONObject("info").optString("url"),
"extra_map" to mapOf(
info = AppConfigGson.InfoBean(
name = oldJson.getJSONObject("info").optString("app_name"),
url = oldJson.getJSONObject("info").optString("url"),
desc = null,
extraMap = mapOf(
apiConvert(targetCheckerJson.getString("api")) to targetCheckerJson.optString("extra_string")
)
),
),
)
)
return JSONObject(map)
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
package net.xzos.upgradeall.core.websdk.api.client_proxy.cloud_config.migration

import net.xzos.upgradeall.core.utils.asSequence
import net.xzos.upgradeall.core.websdk.json.HubConfigGson
import org.json.JSONObject

fun hub5to6(oldJson: JSONObject): JSONObject? {
fun hub5to6(oldJson: JSONObject): HubConfigGson? {
val versionCodeHubs = listOf(
"1c010cc9-cff8-4461-8993-a86cd190d377",
"6a6d590b-1809-41bf-8ce3-7e3f6c8da945",
)
if (oldJson.optInt("base_version") != 5) return null
val uuid = oldJson.optString("uuid")
val map = mapOf(
"base_version" to 6,
"config_version" to oldJson.getJSONObject("info").optString("config_version"),
"uuid" to uuid,
"info" to mapOf(
"hub_name" to oldJson.getJSONObject("info").optString("hub_name"),
"hub_icon_url" to "",
return HubConfigGson(
baseVersion = 6,
configVersion = oldJson.getJSONObject("info").optInt("config_version"),
uuid = uuid,
info = HubConfigGson.InfoBean(
hubName = oldJson.getJSONObject("info").optString("hub_name"),
hubIconUrl = null,
),
"target_check_api" to if (uuid in versionCodeHubs) "index" else "version_number",
"api_keywords" to oldJson.optJSONArray("api_keywords"),
"app_url_templates" to oldJson.optJSONArray("app_url_templates"),
apiKeywords = oldJson.getJSONArray("api_keywords").asSequence<String>().toList(),
appUrlTemplates = oldJson.getJSONArray("app_url_templates").asSequence<String>().toList(),
targetCheckApi = if (uuid in versionCodeHubs) "index" else "version_number",
)
return JSONObject(map)
}

0 comments on commit 9758d27

Please sign in to comment.