mirror of
https://github.com/tachiyomiorg/tachiyomi-extensions-inspector.git
synced 2025-02-04 11:26:22 +01:00
refactor
This commit is contained in:
parent
11000af718
commit
2a3c78d43e
@ -19,73 +19,41 @@ import kotlinx.serialization.json.int
|
||||
import kotlinx.serialization.json.jsonObject
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
|
||||
// import uy.kohesive.injekt.injectLazy
|
||||
|
||||
internal class ExtensionGithubApi {
|
||||
object ExtensionGithubApi {
|
||||
const val BASE_URL = "https://raw.githubusercontent.com"
|
||||
const val REPO_URL_PREFIX = "$BASE_URL/tachiyomiorg/tachiyomi-extensions/repo"
|
||||
|
||||
// private val preferences: PreferencesHelper by injectLazy()
|
||||
private fun parseResponse(json: JsonArray): List<Extension.Available> {
|
||||
return json
|
||||
.filter { element ->
|
||||
val versionName = element.jsonObject["version"]!!.jsonPrimitive.content
|
||||
val libVersion = versionName.substringBeforeLast('.').toDouble()
|
||||
libVersion >= ExtensionLoader.LIB_VERSION_MIN && libVersion <= ExtensionLoader.LIB_VERSION_MAX
|
||||
}
|
||||
.map { element ->
|
||||
val name = element.jsonObject["name"]!!.jsonPrimitive.content.substringAfter("Tachiyomi: ")
|
||||
val pkgName = element.jsonObject["pkg"]!!.jsonPrimitive.content
|
||||
val apkName = element.jsonObject["apk"]!!.jsonPrimitive.content
|
||||
val versionName = element.jsonObject["version"]!!.jsonPrimitive.content
|
||||
val versionCode = element.jsonObject["code"]!!.jsonPrimitive.int
|
||||
val lang = element.jsonObject["lang"]!!.jsonPrimitive.content
|
||||
val nsfw = element.jsonObject["nsfw"]!!.jsonPrimitive.int == 1
|
||||
val icon = "$REPO_URL_PREFIX/icon/${apkName.replace(".apk", ".png")}"
|
||||
|
||||
suspend fun findExtensions(): List<Extension.Available> {
|
||||
Extension.Available(name, pkgName, versionName, versionCode, lang, nsfw, apkName, icon)
|
||||
}
|
||||
}
|
||||
|
||||
fun findExtensions(): List<Extension.Available> {
|
||||
val service: ExtensionGithubService = ExtensionGithubService.create()
|
||||
|
||||
val response = service.getRepo()
|
||||
return parseResponse(response)
|
||||
}
|
||||
|
||||
// suspend fun checkForUpdates(): List<Extension.Installed> {
|
||||
// val extensions = fin dExtensions()
|
||||
//
|
||||
// // preferences.lastExtCheck().set(Date().time)
|
||||
//
|
||||
// val installedExtensions = ExtensionLoader.loadExtensions(context)
|
||||
// .filterIsInstance<LoadResult.Success>()
|
||||
// .map { it.extension }
|
||||
//
|
||||
// val extensionsWithUpdate = mutableListOf<Extension.Installed>()
|
||||
// for (installedExt in installedExtensions) {
|
||||
// val pkgName = installedExt.pkgName
|
||||
// val availableExt = extensions.find { it.pkgName == pkgName } ?: continue
|
||||
//
|
||||
// val hasUpdate = availableExt.versionCode > installedExt.versionCode
|
||||
// if (hasUpdate) {
|
||||
// extensionsWithUpdate.add(installedExt)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return extensionsWithUpdate
|
||||
// }
|
||||
|
||||
private fun parseResponse(json: JsonArray): List<Extension.Available> {
|
||||
return json
|
||||
.filter { element ->
|
||||
val versionName = element.jsonObject["version"]!!.jsonPrimitive.content
|
||||
val libVersion = versionName.substringBeforeLast('.').toDouble()
|
||||
libVersion >= ExtensionLoader.LIB_VERSION_MIN && libVersion <= ExtensionLoader.LIB_VERSION_MAX
|
||||
}
|
||||
.map { element ->
|
||||
val name = element.jsonObject["name"]!!.jsonPrimitive.content.substringAfter("Tachiyomi: ")
|
||||
val pkgName = element.jsonObject["pkg"]!!.jsonPrimitive.content
|
||||
val apkName = element.jsonObject["apk"]!!.jsonPrimitive.content
|
||||
val versionName = element.jsonObject["version"]!!.jsonPrimitive.content
|
||||
val versionCode = element.jsonObject["code"]!!.jsonPrimitive.int
|
||||
val lang = element.jsonObject["lang"]!!.jsonPrimitive.content
|
||||
val nsfw = element.jsonObject["nsfw"]!!.jsonPrimitive.int == 1
|
||||
val icon = "$REPO_URL_PREFIX/icon/${apkName.replace(".apk", ".png")}"
|
||||
|
||||
Extension.Available(name, pkgName, versionName, versionCode, lang, nsfw, apkName, icon)
|
||||
}
|
||||
}
|
||||
|
||||
fun getApkUrl(extension: Extension.Available): String {
|
||||
return "$REPO_URL_PREFIX/apk/${extension.apkName}"
|
||||
}
|
||||
|
||||
fun getApkUrl(extension: ExtensionDataClass): String {
|
||||
return "$REPO_URL_PREFIX/apk/${extension.apkName}"
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val BASE_URL = "https://raw.githubusercontent.com"
|
||||
const val REPO_URL_PREFIX = "$BASE_URL/tachiyomiorg/tachiyomi-extensions/repo"
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ import retrofit2.Retrofit
|
||||
import retrofit2.http.GET
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
|
||||
// import uy.kohesive.injekt.injectLazy
|
||||
|
||||
/**
|
||||
* Used to get the extension repo listing from GitHub.
|
||||
@ -44,5 +43,5 @@ interface ExtensionGithubService {
|
||||
}
|
||||
|
||||
@GET("${ExtensionGithubApi.REPO_URL_PREFIX}/index.json.gz")
|
||||
suspend fun getRepo(): JsonArray
|
||||
fun getRepo(): JsonArray
|
||||
}
|
||||
|
@ -94,8 +94,7 @@ fun installExtension(pkgName: String): Int {
|
||||
val jarPath = "${applicationDirs.extensionsRoot}/$fileNameWithoutType.jar"
|
||||
if (!File(jarPath).exists()) {
|
||||
runBlocking {
|
||||
val api = ExtensionGithubApi()
|
||||
val apkToDownload = api.getApkUrl(extensionRecord)
|
||||
val apkToDownload = ExtensionGithubApi.getApkUrl(extensionRecord)
|
||||
|
||||
val apkFilePath = "$dirPathWithoutType.apk"
|
||||
val jarFilePath = "$dirPathWithoutType.jar"
|
||||
|
@ -37,7 +37,7 @@ fun getExtensionList(): List<ExtensionDataClass> {
|
||||
logger.debug("Getting extensions list from the internet")
|
||||
ExtensionListData.lastUpdateCheck = System.currentTimeMillis()
|
||||
runBlocking {
|
||||
val foundExtensions = ExtensionGithubApi().findExtensions()
|
||||
val foundExtensions = ExtensionGithubApi.findExtensions()
|
||||
updateExtensionDatabase(foundExtensions)
|
||||
}
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user