mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-19 18:53:35 -05:00
[skip ci] Formatting
This commit is contained in:
@@ -78,8 +78,8 @@ object Extension {
|
||||
suspend fun installExternalExtension(
|
||||
inputStream: InputStream,
|
||||
apkName: String,
|
||||
): Int {
|
||||
return installAPK(true) {
|
||||
): Int =
|
||||
installAPK(true) {
|
||||
val savePath = "${applicationDirs.extensionsRoot}/$apkName"
|
||||
logger.debug { "Saving apk at $apkName" }
|
||||
// download apk file
|
||||
@@ -92,7 +92,6 @@ object Extension {
|
||||
}
|
||||
savePath
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun installAPK(
|
||||
forceReinstall: Boolean = false,
|
||||
@@ -174,7 +173,10 @@ object Extension {
|
||||
else -> "all"
|
||||
}
|
||||
|
||||
val extensionName = packageInfo.applicationInfo.nonLocalizedLabel.toString().substringAfter("Tachiyomi: ")
|
||||
val extensionName =
|
||||
packageInfo.applicationInfo.nonLocalizedLabel
|
||||
.toString()
|
||||
.substringAfter("Tachiyomi: ")
|
||||
|
||||
// update extension info
|
||||
transaction {
|
||||
@@ -277,9 +279,10 @@ object Extension {
|
||||
savePath: String,
|
||||
) {
|
||||
val response =
|
||||
network.client.newCall(
|
||||
GET(url, cache = CacheControl.FORCE_NETWORK),
|
||||
).await()
|
||||
network.client
|
||||
.newCall(
|
||||
GET(url, cache = CacheControl.FORCE_NETWORK),
|
||||
).await()
|
||||
|
||||
val downloadedFile = File(savePath)
|
||||
downloadedFile.sink().buffer().use { sink ->
|
||||
@@ -355,13 +358,12 @@ object Extension {
|
||||
val cacheSaveDir = "${applicationDirs.extensionsRoot}/icon"
|
||||
|
||||
return getImageResponse(cacheSaveDir, apkName) {
|
||||
network.client.newCall(
|
||||
GET(iconUrl, cache = CacheControl.FORCE_NETWORK),
|
||||
).await()
|
||||
network.client
|
||||
.newCall(
|
||||
GET(iconUrl, cache = CacheControl.FORCE_NETWORK),
|
||||
).await()
|
||||
}
|
||||
}
|
||||
|
||||
fun getExtensionIconUrl(apkName: String): String {
|
||||
return "/api/v1/extension/icon/$apkName"
|
||||
}
|
||||
fun getExtensionIconUrl(apkName: String): String = "/api/v1/extension/icon/$apkName"
|
||||
}
|
||||
|
||||
@@ -39,13 +39,14 @@ object ExtensionsList {
|
||||
// update if 60 seconds has passed or requested offline and database is empty
|
||||
val extensions =
|
||||
serverConfig.extensionRepos.value.map { repo ->
|
||||
kotlin.runCatching {
|
||||
ExtensionGithubApi.findExtensions(repo.repoUrlReplace())
|
||||
}.onFailure {
|
||||
logger.warn(it) {
|
||||
"Failed to fetch extensions for repo: $repo"
|
||||
kotlin
|
||||
.runCatching {
|
||||
ExtensionGithubApi.findExtensions(repo.repoUrlReplace())
|
||||
}.onFailure {
|
||||
logger.warn(it) {
|
||||
"Failed to fetch extensions for repo: $repo"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
val foundExtensions = extensions.mapNotNull { it.getOrNull() }.flatten()
|
||||
updateExtensionDatabase(foundExtensions)
|
||||
@@ -94,12 +95,15 @@ object ExtensionsList {
|
||||
updateExtensionDatabaseMutex.withLock {
|
||||
transaction {
|
||||
val uniqueExtensions =
|
||||
foundExtensions.groupBy { it.pkgName }.mapValues {
|
||||
(_, extension) ->
|
||||
extension.maxBy { it.versionCode }
|
||||
}.values
|
||||
foundExtensions
|
||||
.groupBy { it.pkgName }
|
||||
.mapValues { (_, extension) ->
|
||||
extension.maxBy { it.versionCode }
|
||||
}.values
|
||||
val installedExtensions =
|
||||
ExtensionTable.selectAll().toList()
|
||||
ExtensionTable
|
||||
.selectAll()
|
||||
.toList()
|
||||
.associateBy { it[ExtensionTable.pkgName] }
|
||||
val extensionsToUpdate = mutableListOf<Pair<OnlineExtension, ResultRow>>()
|
||||
val extensionsToInsert = mutableListOf<OnlineExtension>()
|
||||
@@ -189,7 +193,8 @@ object ExtensionsList {
|
||||
|
||||
// deal with obsolete extensions
|
||||
val extensionsToRemove =
|
||||
extensionsToDelete.groupBy { it[ExtensionTable.isInstalled] }
|
||||
extensionsToDelete
|
||||
.groupBy { it[ExtensionTable.isInstalled] }
|
||||
.mapValues { (_, extensions) -> extensions.map { it[ExtensionTable.pkgName] } }
|
||||
// not in the repo, so these extensions are obsolete
|
||||
val obsoleteExtensions = extensionsToRemove[true].orEmpty()
|
||||
@@ -207,8 +212,8 @@ object ExtensionsList {
|
||||
}
|
||||
}
|
||||
|
||||
private fun String.repoUrlReplace(): String {
|
||||
return if (contains("github")) {
|
||||
private fun String.repoUrlReplace(): String =
|
||||
if (contains("github")) {
|
||||
replace(repoMatchRegex) {
|
||||
"https://raw.githubusercontent.com/${it.groupValues[2]}/${it.groupValues[3]}/" +
|
||||
(it.groupValues.getOrNull(4)?.ifBlank { null } ?: "repo") +
|
||||
@@ -218,7 +223,6 @@ object ExtensionsList {
|
||||
} else {
|
||||
this
|
||||
}
|
||||
}
|
||||
|
||||
private val repoMatchRegex =
|
||||
(
|
||||
|
||||
@@ -58,29 +58,27 @@ object ExtensionGithubApi {
|
||||
fun getApkUrl(
|
||||
repo: String,
|
||||
apkName: String,
|
||||
): String {
|
||||
return "${repo}apk/$apkName"
|
||||
}
|
||||
): String = "${repo}apk/$apkName"
|
||||
|
||||
private val client by lazy {
|
||||
val network: NetworkHelper by injectLazy()
|
||||
network.client.newBuilder()
|
||||
network.client
|
||||
.newBuilder()
|
||||
.addNetworkInterceptor { chain ->
|
||||
val originalResponse = chain.proceed(chain.request())
|
||||
originalResponse.newBuilder()
|
||||
originalResponse
|
||||
.newBuilder()
|
||||
.header("Content-Type", "application/json")
|
||||
.build()
|
||||
}
|
||||
.build()
|
||||
}.build()
|
||||
}
|
||||
|
||||
private fun List<ExtensionJsonObject>.toExtensions(repo: String): List<OnlineExtension> {
|
||||
return this
|
||||
private fun List<ExtensionJsonObject>.toExtensions(repo: String): List<OnlineExtension> =
|
||||
this
|
||||
.filter {
|
||||
val libVersion = it.version.substringBeforeLast('.').toDouble()
|
||||
libVersion in LIB_VERSION_MIN..LIB_VERSION_MAX
|
||||
}
|
||||
.map {
|
||||
}.map {
|
||||
OnlineExtension(
|
||||
repo = repo,
|
||||
name = it.name.substringAfter("Tachiyomi: "),
|
||||
@@ -96,10 +94,9 @@ object ExtensionGithubApi {
|
||||
iconUrl = "${repo}icon/${it.pkg}.png",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun List<ExtensionSourceJsonObject>.toExtensionSources(): List<OnlineExtensionSource> {
|
||||
return this.map {
|
||||
private fun List<ExtensionSourceJsonObject>.toExtensionSources(): List<OnlineExtensionSource> =
|
||||
this.map {
|
||||
OnlineExtensionSource(
|
||||
name = it.name,
|
||||
lang = it.lang,
|
||||
@@ -107,5 +104,4 @@ object ExtensionGithubApi {
|
||||
baseUrl = it.baseUrl,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user