mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-04 11:24:35 -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,22 @@ data class ExtensionDataClass(
|
||||
val lang: String,
|
||||
val isNsfw: Boolean,
|
||||
val apkName: String,
|
||||
val iconUrl : String,
|
||||
val iconUrl: String,
|
||||
val installed: Boolean,
|
||||
val classFQName: String,
|
||||
)
|
||||
|
||||
class ExtensionEntity(id: EntityID<Int>) : IntEntity(id) {
|
||||
companion object : IntEntityClass<ExtensionEntity>(ExtensionsTable)
|
||||
|
||||
var name by ExtensionsTable.name
|
||||
var pkgName by ExtensionsTable.pkgName
|
||||
var versionName by ExtensionsTable.versionName
|
||||
var versionCode by ExtensionsTable.versionCode
|
||||
var lang by ExtensionsTable.lang
|
||||
var isNsfw by ExtensionsTable.isNsfw
|
||||
var apkName by ExtensionsTable.apkName
|
||||
var iconUrl by ExtensionsTable.iconUrl
|
||||
var installed by ExtensionsTable.installed
|
||||
var classFQName by ExtensionsTable.classFQName
|
||||
}
|
||||
|
||||
@@ -1,26 +1,48 @@
|
||||
package ir.armor.tachidesk.database.model
|
||||
|
||||
import org.jetbrains.exposed.dao.Entity
|
||||
import org.jetbrains.exposed.dao.IntEntity
|
||||
import org.jetbrains.exposed.dao.IntEntityClass
|
||||
import org.jetbrains.exposed.dao.*
|
||||
import org.jetbrains.exposed.dao.id.EntityID
|
||||
import org.jetbrains.exposed.dao.id.IdTable
|
||||
import org.jetbrains.exposed.dao.id.IntIdTable
|
||||
import org.jetbrains.exposed.sql.Column
|
||||
import org.jetbrains.exposed.sql.Table
|
||||
|
||||
object SourcesTable : Table() {
|
||||
val id: Column<Long> = long("id")
|
||||
val name: Column<String> = varchar("name", 128)
|
||||
object SourcesTable : IntIdTable() {
|
||||
val sourceId = long("source_id")
|
||||
val name= varchar("name", 128)
|
||||
val lang= varchar("lang", 5)
|
||||
val extension = reference("extension", ExtensionsTable)
|
||||
override val primaryKey = PrimaryKey(id)
|
||||
val partOfFactorySource = bool("part_of_factory_source").default(false)
|
||||
val positionInFactorySource = integer("position_in_factory_source").nullable()
|
||||
}
|
||||
|
||||
//class Source : Entity() {
|
||||
// companion object : Entity<Source>(SourcesTable)
|
||||
class SourceEntity(id: EntityID<Int>) : IntEntity(id) {
|
||||
companion object : IntEntityClass<SourceEntity>(SourcesTable)
|
||||
|
||||
var sourceId by SourcesTable.sourceId
|
||||
var name by SourcesTable.name
|
||||
var lang by SourcesTable.lang
|
||||
var extension by ExtensionEntity referencedOn SourcesTable.extension
|
||||
var partOfFactorySource by SourcesTable.partOfFactorySource
|
||||
var positionInFactorySource by SourcesTable.positionInFactorySource
|
||||
}
|
||||
|
||||
|
||||
//object SourcesTable : IdTable<Long>() {
|
||||
// override val id = long("id").entityId()
|
||||
// val name= varchar("name", 128)
|
||||
// val extension = reference("extension", ExtensionsTable)
|
||||
// val partOfFactorySource = bool("part_of_factory_source").default(false)
|
||||
// val positionInFactorySource = integer("position_in_factory_source").nullable()
|
||||
//
|
||||
// val name by ExtensionsTable.name
|
||||
// val pkgName by ExtensionsTable.pkgName
|
||||
// val versionName by ExtensionsTable.versionName
|
||||
// val versionCode by ExtensionsTable.versionCode
|
||||
// val lang by ExtensionsTable.lang
|
||||
// val isNsfw by ExtensionsTable.isNsfw
|
||||
//}
|
||||
// override val primaryKey = PrimaryKey(id)
|
||||
//}
|
||||
//
|
||||
//class SourceEntity(id: EntityID<Long>) : LongEntity(id) {
|
||||
// companion object : LongEntityClass<SourceEntity>(SourcesTable)
|
||||
//
|
||||
// var name by SourcesTable.name
|
||||
// var extension by SourcesTable.extension
|
||||
// var partOfFactorySource by SourcesTable.partOfFactorySource
|
||||
// var positionInFactorySource by SourcesTable.positionInFactorySource
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user