From d57827b6d3e11458e9eeedca5ed1957f81ff89f9 Mon Sep 17 00:00:00 2001 From: Aria Moradi Date: Thu, 24 Dec 2020 19:37:27 +0330 Subject: [PATCH] commit what we got --- server/build.gradle.kts | 11 ++++ .../main/kotlin/ir/armor/tachidesk/Config.kt | 7 +++ .../main/kotlin/ir/armor/tachidesk/Main.kt | 50 +++++++++++++------ .../ir/armor/tachidesk/database/DBMangaer.kt | 24 +++++++++ .../database/model/ExtensionTable.kt | 30 +++++++++++ .../tachidesk/database/model/SourcesTable.kt | 26 ++++++++++ .../ir/armor/tachidesk/extension/Extension.kt | 4 ++ 7 files changed, 138 insertions(+), 14 deletions(-) create mode 100644 server/src/main/kotlin/ir/armor/tachidesk/Config.kt create mode 100644 server/src/main/kotlin/ir/armor/tachidesk/database/DBMangaer.kt create mode 100644 server/src/main/kotlin/ir/armor/tachidesk/database/model/ExtensionTable.kt create mode 100644 server/src/main/kotlin/ir/armor/tachidesk/database/model/SourcesTable.kt create mode 100644 server/src/main/kotlin/ir/armor/tachidesk/extension/Extension.kt diff --git a/server/build.gradle.kts b/server/build.gradle.kts index 47c3b91..9d167ab 100644 --- a/server/build.gradle.kts +++ b/server/build.gradle.kts @@ -15,6 +15,7 @@ compileKotlin.kotlinOptions { repositories { mavenCentral() + jcenter() } dependencies { @@ -69,6 +70,16 @@ dependencies { implementation("org.slf4j:slf4j-api:1.8.0-beta4") implementation("com.fasterxml.jackson.core:jackson-databind:2.10.3") + // to get application content root + implementation("net.harawata:appdirs:1.2.0") + + // Exposed ORM + val exposed_version = "0.28.1" + implementation ("org.jetbrains.exposed:exposed-core:$exposed_version") + implementation ("org.jetbrains.exposed:exposed-dao:$exposed_version") + implementation ("org.jetbrains.exposed:exposed-jdbc:$exposed_version") + implementation ("org.xerial:sqlite-jdbc:3.30.1") + testImplementation("org.jetbrains.kotlin:kotlin-test") testImplementation("org.jetbrains.kotlin:kotlin-test-junit") diff --git a/server/src/main/kotlin/ir/armor/tachidesk/Config.kt b/server/src/main/kotlin/ir/armor/tachidesk/Config.kt new file mode 100644 index 0000000..40bdbbd --- /dev/null +++ b/server/src/main/kotlin/ir/armor/tachidesk/Config.kt @@ -0,0 +1,7 @@ +package ir.armor.tachidesk + +import net.harawata.appdirs.AppDirsFactory + +object Config { + val dataRoot = AppDirsFactory.getInstance().getUserDataDir("Tachidesk",null, null) +} \ No newline at end of file diff --git a/server/src/main/kotlin/ir/armor/tachidesk/Main.kt b/server/src/main/kotlin/ir/armor/tachidesk/Main.kt index 3dab39e..089dc71 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/Main.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/Main.kt @@ -7,19 +7,25 @@ import eu.kanade.tachiyomi.source.model.MangasPage import eu.kanade.tachiyomi.source.online.HttpSource import io.javalin.Javalin import io.javalin.http.Context +import ir.armor.tachidesk.database.DBMangaer +import ir.armor.tachidesk.database.makeDataBaseTables +import ir.armor.tachidesk.database.model.ExtensionsTable +import ir.armor.tachidesk.database.model.SourcesTable import kotlinx.coroutines.runBlocking +import net.harawata.appdirs.AppDirsFactory import okhttp3.Request import okio.buffer import okio.sink +import org.jetbrains.exposed.sql.Database import java.io.File import java.net.URL import java.net.URLClassLoader +import org.jetbrains.exposed.sql.SchemaUtils +import org.jetbrains.exposed.sql.transactions.transaction class Main { companion object { - const val contentRoot = "/tmp/tachidesk" - @JvmStatic fun downloadAPK(url: String, apkPath: String){ val request = Request.Builder().url(url).build() @@ -33,6 +39,7 @@ class Main { @JvmStatic fun testExtensionExecution(){ + val contentRoot = Config.dataRoot + "/extensions" File(contentRoot).mkdirs() var sourcePkg = "" @@ -61,7 +68,7 @@ class Main { // dex -> jar Dex2jarCmd.main(dexFilePath, "-o", jarFilePath, "--force") - val child = URLClassLoader(arrayOf(URL("file:$jarFilePath")), this.javaClass.classLoader) + val child = URLClassLoader(arrayOf(URL("file:$jarFilePath")), this::class.java.classLoader) val classToLoad = Class.forName(className, true, child) val instance = classToLoad.newInstance() as HttpSource val result = instance.fetchPopularManga(1) @@ -75,19 +82,34 @@ class Main { @JvmStatic fun main(args: Array) { - val app = Javalin.create().start(4567) + // make sure data everything we need exists + File(Config.dataRoot).mkdirs() + makeDataBaseTables() - app.before() { ctx -> - ctx.header("Access-Control-Allow-Origin", "*") - } - app.get("/api/v1/extensions") { ctx -> - runBlocking { - val api = ExtensionGithubApi() - val sources = api.findExtensions() - ctx.json(sources) - } - } +// val app = Javalin.create().start(4567) +// +// app.before() { ctx -> +// ctx.header("Access-Control-Allow-Origin", "*") +// } +// +// app.get("/api/v1/extensions") { ctx -> +// runBlocking { +// val api = ExtensionGithubApi() +// val sources = api.findExtensions() +// ctx.json(sources) +// } +// } +// +// app.get("/api/v1/extensions/install/:extensionURL") { ctx -> +// ctx.pathParam("extensionURL") +// }) + + +// ExtensionTable.new { +// name = "khar" +// pkgName = "eu.khar" +// } } } } diff --git a/server/src/main/kotlin/ir/armor/tachidesk/database/DBMangaer.kt b/server/src/main/kotlin/ir/armor/tachidesk/database/DBMangaer.kt new file mode 100644 index 0000000..807490a --- /dev/null +++ b/server/src/main/kotlin/ir/armor/tachidesk/database/DBMangaer.kt @@ -0,0 +1,24 @@ +package ir.armor.tachidesk.database + +import ir.armor.tachidesk.Config +import ir.armor.tachidesk.database.model.ExtensionsTable +import ir.armor.tachidesk.database.model.SourcesTable +import org.jetbrains.exposed.sql.Database +import org.jetbrains.exposed.sql.SchemaUtils +import org.jetbrains.exposed.sql.transactions.transaction + +object DBMangaer { + val db by lazy { + Database.connect("jdbc:sqlite:${Config.dataRoot}/database.db", "org.sqlite.JDBC") + } +} + +fun makeDataBaseTables() { + // mention db object to connect + DBMangaer.db + + transaction { + SchemaUtils.create(ExtensionsTable) + SchemaUtils.create(SourcesTable) + } +} \ No newline at end of file diff --git a/server/src/main/kotlin/ir/armor/tachidesk/database/model/ExtensionTable.kt b/server/src/main/kotlin/ir/armor/tachidesk/database/model/ExtensionTable.kt new file mode 100644 index 0000000..646e078 --- /dev/null +++ b/server/src/main/kotlin/ir/armor/tachidesk/database/model/ExtensionTable.kt @@ -0,0 +1,30 @@ +package ir.armor.tachidesk.database.model + +import eu.kanade.tachiyomi.source.Source +import org.jetbrains.exposed.dao.IntEntity +import org.jetbrains.exposed.dao.IntEntityClass +import org.jetbrains.exposed.dao.id.EntityID +import org.jetbrains.exposed.dao.id.IntIdTable +import org.jetbrains.exposed.sql.Column +import org.jetbrains.exposed.sql.Table + + +object ExtensionsTable : IntIdTable() { + val name = varchar("name", 128) + val pkgName = varchar("pkg_name", 128) + val versionName = varchar("version_name", 16) + val versionCode = integer("version_code") + val lang = varchar("lang", 5) + val isNsfw = bool("is_nsfw") +} + +//class Extension(id: EntityID) : IntEntity(id) { +// companion object : IntEntityClass(ExtensionsTable) +// +// 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 +//} diff --git a/server/src/main/kotlin/ir/armor/tachidesk/database/model/SourcesTable.kt b/server/src/main/kotlin/ir/armor/tachidesk/database/model/SourcesTable.kt new file mode 100644 index 0000000..c83cbac --- /dev/null +++ b/server/src/main/kotlin/ir/armor/tachidesk/database/model/SourcesTable.kt @@ -0,0 +1,26 @@ +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.id.EntityID +import org.jetbrains.exposed.sql.Column +import org.jetbrains.exposed.sql.Table + +object SourcesTable : Table() { + val id: Column = long("id") + val name: Column = varchar("name", 128) + val extension = reference("extension", ExtensionsTable) + override val primaryKey = PrimaryKey(id) +} + +//class Source : Entity() { +// companion object : Entity(SourcesTable) +// +// 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 +//} \ No newline at end of file diff --git a/server/src/main/kotlin/ir/armor/tachidesk/extension/Extension.kt b/server/src/main/kotlin/ir/armor/tachidesk/extension/Extension.kt new file mode 100644 index 0000000..9d30482 --- /dev/null +++ b/server/src/main/kotlin/ir/armor/tachidesk/extension/Extension.kt @@ -0,0 +1,4 @@ +package ir.armor.tachidesk.extension + +class Extension { +} \ No newline at end of file