mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-04 03:14:40 -05:00
refactor
This commit is contained in:
@@ -19,41 +19,10 @@ import kotlinx.serialization.json.int
|
|||||||
import kotlinx.serialization.json.jsonObject
|
import kotlinx.serialization.json.jsonObject
|
||||||
import kotlinx.serialization.json.jsonPrimitive
|
import kotlinx.serialization.json.jsonPrimitive
|
||||||
|
|
||||||
// import uy.kohesive.injekt.injectLazy
|
|
||||||
|
|
||||||
internal class ExtensionGithubApi {
|
object ExtensionGithubApi {
|
||||||
|
const val BASE_URL = "https://raw.githubusercontent.com"
|
||||||
// private val preferences: PreferencesHelper by injectLazy()
|
const val REPO_URL_PREFIX = "$BASE_URL/tachiyomiorg/tachiyomi-extensions/repo"
|
||||||
|
|
||||||
suspend 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> {
|
private fun parseResponse(json: JsonArray): List<Extension.Available> {
|
||||||
return json
|
return json
|
||||||
@@ -76,16 +45,15 @@ internal class ExtensionGithubApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getApkUrl(extension: Extension.Available): String {
|
fun findExtensions(): List<Extension.Available> {
|
||||||
return "$REPO_URL_PREFIX/apk/${extension.apkName}"
|
val service: ExtensionGithubService = ExtensionGithubService.create()
|
||||||
|
|
||||||
|
val response = service.getRepo()
|
||||||
|
return parseResponse(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getApkUrl(extension: ExtensionDataClass): String {
|
fun getApkUrl(extension: ExtensionDataClass): String {
|
||||||
return "$REPO_URL_PREFIX/apk/${extension.apkName}"
|
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 retrofit2.http.GET
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
|
||||||
// import uy.kohesive.injekt.injectLazy
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to get the extension repo listing from GitHub.
|
* Used to get the extension repo listing from GitHub.
|
||||||
@@ -44,5 +43,5 @@ interface ExtensionGithubService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GET("${ExtensionGithubApi.REPO_URL_PREFIX}/index.json.gz")
|
@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"
|
val jarPath = "${applicationDirs.extensionsRoot}/$fileNameWithoutType.jar"
|
||||||
if (!File(jarPath).exists()) {
|
if (!File(jarPath).exists()) {
|
||||||
runBlocking {
|
runBlocking {
|
||||||
val api = ExtensionGithubApi()
|
val apkToDownload = ExtensionGithubApi.getApkUrl(extensionRecord)
|
||||||
val apkToDownload = api.getApkUrl(extensionRecord)
|
|
||||||
|
|
||||||
val apkFilePath = "$dirPathWithoutType.apk"
|
val apkFilePath = "$dirPathWithoutType.apk"
|
||||||
val jarFilePath = "$dirPathWithoutType.jar"
|
val jarFilePath = "$dirPathWithoutType.jar"
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ fun getExtensionList(): List<ExtensionDataClass> {
|
|||||||
logger.debug("Getting extensions list from the internet")
|
logger.debug("Getting extensions list from the internet")
|
||||||
ExtensionListData.lastUpdateCheck = System.currentTimeMillis()
|
ExtensionListData.lastUpdateCheck = System.currentTimeMillis()
|
||||||
runBlocking {
|
runBlocking {
|
||||||
val foundExtensions = ExtensionGithubApi().findExtensions()
|
val foundExtensions = ExtensionGithubApi.findExtensions()
|
||||||
updateExtensionDatabase(foundExtensions)
|
updateExtensionDatabase(foundExtensions)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user