mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-04 03:14:40 -05:00
save sources list
This commit is contained in:
@@ -4,12 +4,12 @@ import com.googlecode.dex2jar.tools.Dex2jarCmd
|
||||
import eu.kanade.tachiyomi.extension.api.ExtensionGithubApi
|
||||
import eu.kanade.tachiyomi.extension.model.Extension
|
||||
import eu.kanade.tachiyomi.network.NetworkHelper
|
||||
import eu.kanade.tachiyomi.source.SourceFactory
|
||||
import eu.kanade.tachiyomi.source.model.MangasPage
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
import io.javalin.Javalin
|
||||
import ir.armor.tachidesk.database.makeDataBaseTables
|
||||
import ir.armor.tachidesk.database.model.ExtensionDataClass
|
||||
import ir.armor.tachidesk.database.model.ExtensionsTable
|
||||
import ir.armor.tachidesk.database.model.*
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import okhttp3.Request
|
||||
import okio.buffer
|
||||
@@ -144,7 +144,7 @@ class Main {
|
||||
}
|
||||
|
||||
fun downloadApk(apkName: String): Int {
|
||||
val extension = getExtensionList(true).first { it.apkName == apkName }
|
||||
val extensionRecord = getExtensionList(true).first { it.apkName == apkName }
|
||||
val fileNameWithoutType = apkName.substringBefore(".apk")
|
||||
val dirPathWithoutType = "${Config.extensionsRoot}/$apkName"
|
||||
|
||||
@@ -153,7 +153,7 @@ class Main {
|
||||
if (!File(dexPath).exists()) {
|
||||
runBlocking {
|
||||
val api = ExtensionGithubApi()
|
||||
val apkToDownload = api.getApkUrl(extension)
|
||||
val apkToDownload = api.getApkUrl(extensionRecord)
|
||||
|
||||
val apkFilePath = "$dirPathWithoutType.apk"
|
||||
val jarFilePath = "$dirPathWithoutType.jar"
|
||||
@@ -164,14 +164,67 @@ class Main {
|
||||
|
||||
|
||||
val className: String = APKExtractor.extract_dex_and_read_className(apkFilePath, dexFilePath)
|
||||
|
||||
println(className)
|
||||
// dex -> jar
|
||||
Dex2jarCmd.main(dexFilePath, "-o", jarFilePath, "--force")
|
||||
|
||||
File(apkFilePath).delete()
|
||||
|
||||
// update sources of the extension
|
||||
val child = URLClassLoader(arrayOf<URL>(URL("file:$jarFilePath")), this::class.java.classLoader)
|
||||
val classToLoad = Class.forName(className, true, child)
|
||||
val instance = classToLoad.newInstance()
|
||||
|
||||
val extensionId = transaction {
|
||||
return@transaction ExtensionsTable.select { ExtensionsTable.name eq extensionRecord.name }.first()[ExtensionsTable.id]
|
||||
}
|
||||
|
||||
if (instance is HttpSource) {// single source
|
||||
val httpSource = instance as HttpSource
|
||||
transaction {
|
||||
// SourceEntity.new {
|
||||
// sourceId = httpSource.id
|
||||
// name = httpSource.name
|
||||
// this.extension = ExtensionEntity.find { ExtensionsTable.name eq extension.name }.first().id
|
||||
// }
|
||||
if (SourcesTable.select { SourcesTable.sourceId eq httpSource.id }.count() == 0L) {
|
||||
SourcesTable.insert {
|
||||
it[this.sourceId] = httpSource.id
|
||||
it[name] = httpSource.name
|
||||
it[this.lang] = httpSource.lang
|
||||
it[extension] = extensionId
|
||||
}
|
||||
}
|
||||
// println(httpSource.id)
|
||||
// println(httpSource.name)
|
||||
// println()
|
||||
}
|
||||
|
||||
} else { // multi source
|
||||
val sourceFactory = instance as SourceFactory
|
||||
transaction {
|
||||
sourceFactory.createSources().forEachIndexed { index, source ->
|
||||
val httpSource = source as HttpSource
|
||||
if (SourcesTable.select { SourcesTable.sourceId eq httpSource.id }.count() == 0L) {
|
||||
SourcesTable.insert {
|
||||
it[this.sourceId] = httpSource.id
|
||||
it[name] = httpSource.name
|
||||
it[this.lang] = httpSource.lang
|
||||
it[extension] = extensionId
|
||||
it[partOfFactorySource] = true
|
||||
it[positionInFactorySource] = index
|
||||
}
|
||||
}
|
||||
// println(httpSource.id)
|
||||
// println(httpSource.name)
|
||||
// println()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update extension info
|
||||
transaction {
|
||||
ExtensionsTable.update({ ExtensionsTable.name eq extension.name }) {
|
||||
ExtensionsTable.update({ ExtensionsTable.name eq extensionRecord.name }) {
|
||||
it[installed] = true
|
||||
it[classFQName] = className
|
||||
}
|
||||
@@ -179,8 +232,7 @@ class Main {
|
||||
|
||||
}
|
||||
return 201 // we downloaded successfully
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return 302
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user