From 2f69317f5d056d2be0dc63c2c2d4b04b22a7e481 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 29 Feb 2020 13:35:07 -0500 Subject: [PATCH] Enforce maximum extension lib version of 1.2 --- .../extension/api/ExtensionGithubApi.kt | 27 ++++++++++++------- .../extension/util/ExtensionLoader.kt | 10 +++---- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt index f8ef81b89..0a7fde183 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt @@ -7,6 +7,7 @@ import com.github.salomonbrys.kotson.string import com.google.gson.Gson import com.google.gson.JsonArray import eu.kanade.tachiyomi.extension.model.Extension +import eu.kanade.tachiyomi.extension.util.ExtensionLoader import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.NetworkHelper import eu.kanade.tachiyomi.network.asObservableSuccess @@ -36,17 +37,23 @@ internal class ExtensionGithubApi { val json = gson.fromJson(text) - return json.map { element -> - val name = element["name"].string.substringAfter("Tachiyomi: ") - val pkgName = element["pkg"].string - val apkName = element["apk"].string - val versionName = element["version"].string - val versionCode = element["code"].int - val lang = element["lang"].string - val icon = "$repoUrl/icon/${apkName.replace(".apk", ".png")}" + return json + .filter { element -> + val versionName = element["version"].string + val libVersion = versionName.substringBeforeLast('.').toDouble() + libVersion >= ExtensionLoader.LIB_VERSION_MIN && libVersion <= ExtensionLoader.LIB_VERSION_MAX + } + .map { element -> + val name = element["name"].string.substringAfter("Tachiyomi: ") + val pkgName = element["pkg"].string + val apkName = element["apk"].string + val versionName = element["version"].string + val versionCode = element["code"].int + val lang = element["lang"].string + val icon = "$repoUrl/icon/${apkName.replace(".apk", ".png")}" - Extension.Available(name, pkgName, versionName, versionCode, lang, apkName, icon) - } + Extension.Available(name, pkgName, versionName, versionCode, lang, apkName, icon) + } } fun getApkUrl(extension: Extension.Available): String { diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt index 7e3998d27..d5ee747d2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt @@ -27,8 +27,8 @@ internal object ExtensionLoader { private const val EXTENSION_FEATURE = "tachiyomi.extension" private const val METADATA_SOURCE_CLASS = "tachiyomi.extension.class" - private const val LIB_VERSION_MIN = 1 - private const val LIB_VERSION_MAX = 1 + const val LIB_VERSION_MIN = 1.0 + const val LIB_VERSION_MAX = 1.2 private const val PACKAGE_FLAGS = PackageManager.GET_CONFIGURATIONS or PackageManager.GET_SIGNATURES @@ -107,9 +107,9 @@ internal object ExtensionLoader { } // Validate lib version - val majorLibVersion = versionName.substringBefore('.').toInt() - if (majorLibVersion < LIB_VERSION_MIN || majorLibVersion > LIB_VERSION_MAX) { - val exception = Exception("Lib version is $majorLibVersion, while only versions " + + val libVersion = versionName.substringBeforeLast('.').toDouble() + if (libVersion < LIB_VERSION_MIN || libVersion > LIB_VERSION_MAX) { + val exception = Exception("Lib version is $libVersion, while only versions " + "$LIB_VERSION_MIN to $LIB_VERSION_MAX are allowed") Timber.w(exception) return LoadResult.Error(exception)