refactor, add todos for library and category

This commit is contained in:
Aria Moradi 2021-02-06 18:48:59 +03:30
parent 087b7554bf
commit c1659f1cf2
10 changed files with 103 additions and 43 deletions

View File

@ -144,6 +144,26 @@ class Main {
ctx.header("content-type", result.second) ctx.header("content-type", result.second)
} }
// adds the manga to library
app.get("api/v1/manga/:mangaId/library") { ctx ->
// TODO
}
// removes the manga from the library
app.delete("api/v1/manga/:mangaId/library") { ctx ->
// TODO
}
// adds the manga to category
app.get("api/v1/manga/:mangaId/category/:categoryId") { ctx ->
// TODO
}
// removes the manga from the category
app.delete("api/v1/manga/:mangaId/category/:categoryId") { ctx ->
// TODO
}
app.get("/api/v1/manga/:mangaId/chapters") { ctx -> app.get("/api/v1/manga/:mangaId/chapters") { ctx ->
val mangaId = ctx.pathParam("mangaId").toInt() val mangaId = ctx.pathParam("mangaId").toInt()
ctx.json(getChapterList(mangaId)) ctx.json(getChapterList(mangaId))
@ -184,6 +204,31 @@ class Main {
val sourceId = ctx.pathParam("sourceId").toLong() val sourceId = ctx.pathParam("sourceId").toLong()
ctx.json(sourceFilters(sourceId)) ctx.json(sourceFilters(sourceId))
} }
// lists all manga in the library, suitable if no categories are defined
app.get("/api/v1/library/") { ctx ->
// TODO
}
// category list
app.get("/api/v1/category/") { ctx ->
// TODO
}
// category create
app.post("/api/v1/category/") { ctx ->
// TODO
}
// category modification
app.patch("/api/v1/category/:categoryId") { ctx ->
// TODO
}
// returns the manga list associated with a category
app.get("/api/v1/category/:categoryId") { ctx ->
// TODO
}
} }
} }
} }

View File

@ -5,8 +5,9 @@ package ir.armor.tachidesk.database
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import ir.armor.tachidesk.Config import ir.armor.tachidesk.Config
import ir.armor.tachidesk.database.table.CategoryTable
import ir.armor.tachidesk.database.table.ChapterTable import ir.armor.tachidesk.database.table.ChapterTable
import ir.armor.tachidesk.database.table.ExtensionsTable import ir.armor.tachidesk.database.table.ExtensionTable
import ir.armor.tachidesk.database.table.MangaTable import ir.armor.tachidesk.database.table.MangaTable
import ir.armor.tachidesk.database.table.PageTable import ir.armor.tachidesk.database.table.PageTable
import ir.armor.tachidesk.database.table.SourceTable import ir.armor.tachidesk.database.table.SourceTable
@ -27,10 +28,11 @@ fun makeDataBaseTables() {
// db.useNestedTransactions = true // db.useNestedTransactions = true
transaction { transaction {
SchemaUtils.create(ExtensionsTable) SchemaUtils.create(ExtensionTable)
SchemaUtils.create(SourceTable) SchemaUtils.create(SourceTable)
SchemaUtils.create(MangaTable) SchemaUtils.create(MangaTable)
SchemaUtils.create(ChapterTable) SchemaUtils.create(ChapterTable)
SchemaUtils.create(PageTable) SchemaUtils.create(PageTable)
SchemaUtils.create(CategoryTable)
} }
} }

View File

@ -4,22 +4,22 @@ package ir.armor.tachidesk.database.entity
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import ir.armor.tachidesk.database.table.ExtensionsTable import ir.armor.tachidesk.database.table.ExtensionTable
import org.jetbrains.exposed.dao.IntEntity import org.jetbrains.exposed.dao.IntEntity
import org.jetbrains.exposed.dao.IntEntityClass import org.jetbrains.exposed.dao.IntEntityClass
import org.jetbrains.exposed.dao.id.EntityID import org.jetbrains.exposed.dao.id.EntityID
class ExtensionEntity(id: EntityID<Int>) : IntEntity(id) { class ExtensionEntity(id: EntityID<Int>) : IntEntity(id) {
companion object : IntEntityClass<ExtensionEntity>(ExtensionsTable) companion object : IntEntityClass<ExtensionEntity>(ExtensionTable)
var name by ExtensionsTable.name var name by ExtensionTable.name
var pkgName by ExtensionsTable.pkgName var pkgName by ExtensionTable.pkgName
var versionName by ExtensionsTable.versionName var versionName by ExtensionTable.versionName
var versionCode by ExtensionsTable.versionCode var versionCode by ExtensionTable.versionCode
var lang by ExtensionsTable.lang var lang by ExtensionTable.lang
var isNsfw by ExtensionsTable.isNsfw var isNsfw by ExtensionTable.isNsfw
var apkName by ExtensionsTable.apkName var apkName by ExtensionTable.apkName
var iconUrl by ExtensionsTable.iconUrl var iconUrl by ExtensionTable.iconUrl
var installed by ExtensionsTable.installed var installed by ExtensionTable.installed
var classFQName by ExtensionsTable.classFQName var classFQName by ExtensionTable.classFQName
} }

View File

@ -0,0 +1,12 @@
package ir.armor.tachidesk.database.table
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import org.jetbrains.exposed.dao.id.IntIdTable
object CategoryTable : IntIdTable() {
val name = varchar("name", 64)
val isLanding = bool("is_landing").default(false)
}

View File

@ -6,7 +6,7 @@ package ir.armor.tachidesk.database.table
import org.jetbrains.exposed.dao.id.IntIdTable import org.jetbrains.exposed.dao.id.IntIdTable
object ExtensionsTable : IntIdTable() { object ExtensionTable : IntIdTable() {
val name = varchar("name", 128) val name = varchar("name", 128)
val pkgName = varchar("pkg_name", 128) val pkgName = varchar("pkg_name", 128)
val versionName = varchar("version_name", 16) val versionName = varchar("version_name", 16)

View File

@ -21,6 +21,8 @@ object MangaTable : IntIdTable() {
val status = integer("status").default(SManga.UNKNOWN) val status = integer("status").default(SManga.UNKNOWN)
val thumbnail_url = varchar("thumbnail_url", 2048).nullable() val thumbnail_url = varchar("thumbnail_url", 2048).nullable()
val inLibrary = bool("in_library").default(false)
// source is used by some ancestor of IntIdTable // source is used by some ancestor of IntIdTable
val sourceReference = reference("source", SourceTable) val sourceReference = reference("source", SourceTable)
} }

View File

@ -10,7 +10,7 @@ object SourceTable : IdTable<Long>() {
override val id = long("id").entityId() override val id = long("id").entityId()
val name = varchar("name", 128) val name = varchar("name", 128)
val lang = varchar("lang", 10) val lang = varchar("lang", 10)
val extension = reference("extension", ExtensionsTable) val extension = reference("extension", ExtensionTable)
val partOfFactorySource = bool("part_of_factory_source").default(false) val partOfFactorySource = bool("part_of_factory_source").default(false)
val positionInFactorySource = integer("position_in_factory_source").nullable() val positionInFactorySource = integer("position_in_factory_source").nullable()
} }

View File

@ -12,7 +12,7 @@ import eu.kanade.tachiyomi.source.SourceFactory
import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.source.online.HttpSource
import ir.armor.tachidesk.APKExtractor import ir.armor.tachidesk.APKExtractor
import ir.armor.tachidesk.Config import ir.armor.tachidesk.Config
import ir.armor.tachidesk.database.table.ExtensionsTable import ir.armor.tachidesk.database.table.ExtensionTable
import ir.armor.tachidesk.database.table.SourceTable import ir.armor.tachidesk.database.table.SourceTable
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import okhttp3.Request import okhttp3.Request
@ -63,7 +63,7 @@ fun installAPK(apkName: String): Int {
val instance = classToLoad.newInstance() val instance = classToLoad.newInstance()
val extensionId = transaction { val extensionId = transaction {
return@transaction ExtensionsTable.select { ExtensionsTable.name eq extensionRecord.name }.first()[ExtensionsTable.id] return@transaction ExtensionTable.select { ExtensionTable.name eq extensionRecord.name }.first()[ExtensionTable.id]
} }
if (instance is HttpSource) { // single source if (instance is HttpSource) { // single source
@ -110,7 +110,7 @@ fun installAPK(apkName: String): Int {
// update extension info // update extension info
transaction { transaction {
ExtensionsTable.update({ ExtensionsTable.name eq extensionRecord.name }) { ExtensionTable.update({ ExtensionTable.name eq extensionRecord.name }) {
it[installed] = true it[installed] = true
it[classFQName] = className it[classFQName] = className
} }
@ -139,11 +139,11 @@ fun removeExtension(pkgName: String) {
val fileNameWithoutType = pkgName.substringBefore(".apk") val fileNameWithoutType = pkgName.substringBefore(".apk")
val jarPath = "${Config.extensionsRoot}/$fileNameWithoutType.jar" val jarPath = "${Config.extensionsRoot}/$fileNameWithoutType.jar"
transaction { transaction {
val extensionId = ExtensionsTable.select { ExtensionsTable.name eq extensionRecord.name }.first()[ExtensionsTable.id] val extensionId = ExtensionTable.select { ExtensionTable.name eq extensionRecord.name }.first()[ExtensionTable.id]
SourceTable.deleteWhere { SourceTable.extension eq extensionId } SourceTable.deleteWhere { SourceTable.extension eq extensionId }
ExtensionsTable.update({ ExtensionsTable.name eq extensionRecord.name }) { ExtensionTable.update({ ExtensionTable.name eq extensionRecord.name }) {
it[ExtensionsTable.installed] = false it[ExtensionTable.installed] = false
} }
} }
@ -155,7 +155,7 @@ fun removeExtension(pkgName: String) {
val network: NetworkHelper by injectLazy() val network: NetworkHelper by injectLazy()
fun getExtensionIcon(apkName: String): Pair<InputStream, String> { fun getExtensionIcon(apkName: String): Pair<InputStream, String> {
val iconUrl = transaction { ExtensionsTable.select { ExtensionsTable.apkName eq apkName }.firstOrNull()!! }[ExtensionsTable.iconUrl] val iconUrl = transaction { ExtensionTable.select { ExtensionTable.apkName eq apkName }.firstOrNull()!! }[ExtensionTable.iconUrl]
val saveDir = "${Config.extensionsRoot}/icon" val saveDir = "${Config.extensionsRoot}/icon"
val fileName = apkName val fileName = apkName

View File

@ -7,9 +7,8 @@ package ir.armor.tachidesk.util
import eu.kanade.tachiyomi.extension.api.ExtensionGithubApi import eu.kanade.tachiyomi.extension.api.ExtensionGithubApi
import eu.kanade.tachiyomi.extension.model.Extension import eu.kanade.tachiyomi.extension.model.Extension
import ir.armor.tachidesk.database.dataclass.ExtensionDataClass import ir.armor.tachidesk.database.dataclass.ExtensionDataClass
import ir.armor.tachidesk.database.table.ExtensionsTable import ir.armor.tachidesk.database.table.ExtensionTable
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.insert import org.jetbrains.exposed.sql.insert
import org.jetbrains.exposed.sql.select import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll import org.jetbrains.exposed.sql.selectAll
@ -22,7 +21,7 @@ private object Data {
private fun extensionDatabaseIsEmtpy(): Boolean { private fun extensionDatabaseIsEmtpy(): Boolean {
return transaction { return transaction {
return@transaction ExtensionsTable.selectAll().count() == 0L return@transaction ExtensionTable.selectAll().count() == 0L
} }
} }
@ -37,10 +36,10 @@ fun getExtensionList(offline: Boolean = false): List<ExtensionDataClass> {
foundExtensions = api.findExtensions() foundExtensions = api.findExtensions()
transaction { transaction {
foundExtensions.forEach { foundExtension -> foundExtensions.forEach { foundExtension ->
val extensionRecord = ExtensionsTable.select { ExtensionsTable.name eq foundExtension.name }.firstOrNull() val extensionRecord = ExtensionTable.select { ExtensionTable.name eq foundExtension.name }.firstOrNull()
if (extensionRecord != null) { if (extensionRecord != null) {
// update the record // update the record
ExtensionsTable.update({ ExtensionsTable.name eq foundExtension.name }) { ExtensionTable.update({ ExtensionTable.name eq foundExtension.name }) {
it[name] = foundExtension.name it[name] = foundExtension.name
it[pkgName] = foundExtension.pkgName it[pkgName] = foundExtension.pkgName
it[versionName] = foundExtension.versionName it[versionName] = foundExtension.versionName
@ -52,7 +51,7 @@ fun getExtensionList(offline: Boolean = false): List<ExtensionDataClass> {
} }
} else { } else {
// insert new record // insert new record
ExtensionsTable.insert { ExtensionTable.insert {
it[name] = foundExtension.name it[name] = foundExtension.name
it[pkgName] = foundExtension.pkgName it[pkgName] = foundExtension.pkgName
it[versionName] = foundExtension.versionName it[versionName] = foundExtension.versionName
@ -71,18 +70,18 @@ fun getExtensionList(offline: Boolean = false): List<ExtensionDataClass> {
} }
return transaction { return transaction {
return@transaction ExtensionsTable.selectAll().map { return@transaction ExtensionTable.selectAll().map {
ExtensionDataClass( ExtensionDataClass(
it[ExtensionsTable.name], it[ExtensionTable.name],
it[ExtensionsTable.pkgName], it[ExtensionTable.pkgName],
it[ExtensionsTable.versionName], it[ExtensionTable.versionName],
it[ExtensionsTable.versionCode], it[ExtensionTable.versionCode],
it[ExtensionsTable.lang], it[ExtensionTable.lang],
it[ExtensionsTable.isNsfw], it[ExtensionTable.isNsfw],
it[ExtensionsTable.apkName], it[ExtensionTable.apkName],
getExtensionIconUrl(it[ExtensionsTable.apkName]), getExtensionIconUrl(it[ExtensionTable.apkName]),
it[ExtensionsTable.installed], it[ExtensionTable.installed],
it[ExtensionsTable.classFQName] it[ExtensionTable.classFQName]
) )
} }
} }

View File

@ -10,7 +10,7 @@ import ir.armor.tachidesk.Config
import ir.armor.tachidesk.database.dataclass.SourceDataClass import ir.armor.tachidesk.database.dataclass.SourceDataClass
import ir.armor.tachidesk.database.entity.ExtensionEntity import ir.armor.tachidesk.database.entity.ExtensionEntity
import ir.armor.tachidesk.database.entity.SourceEntity import ir.armor.tachidesk.database.entity.SourceEntity
import ir.armor.tachidesk.database.table.ExtensionsTable import ir.armor.tachidesk.database.table.ExtensionTable
import ir.armor.tachidesk.database.table.SourceTable import ir.armor.tachidesk.database.table.SourceTable
import org.jetbrains.exposed.sql.select import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll import org.jetbrains.exposed.sql.selectAll
@ -78,7 +78,7 @@ fun getSourceList(): List<SourceDataClass> {
it[SourceTable.id].value.toString(), it[SourceTable.id].value.toString(),
it[SourceTable.name], it[SourceTable.name],
Locale(it[SourceTable.lang]).getDisplayLanguage(Locale(it[SourceTable.lang])), Locale(it[SourceTable.lang]).getDisplayLanguage(Locale(it[SourceTable.lang])),
getExtensionIconUrl(ExtensionsTable.select { ExtensionsTable.id eq it[SourceTable.extension] }.first()[ExtensionsTable.apkName]), getExtensionIconUrl(ExtensionTable.select { ExtensionTable.id eq it[SourceTable.extension] }.first()[ExtensionTable.apkName]),
getHttpSource(it[SourceTable.id].value).supportsLatest getHttpSource(it[SourceTable.id].value).supportsLatest
) )
} }
@ -93,7 +93,7 @@ fun getSource(sourceId: Long): SourceDataClass {
source[SourceTable.id].value.toString(), source[SourceTable.id].value.toString(),
source[SourceTable.name], source[SourceTable.name],
Locale(source[SourceTable.lang]).getDisplayLanguage(Locale(source[SourceTable.lang])), Locale(source[SourceTable.lang]).getDisplayLanguage(Locale(source[SourceTable.lang])),
ExtensionsTable.select { ExtensionsTable.id eq source[SourceTable.extension] }.first()[ExtensionsTable.iconUrl], ExtensionTable.select { ExtensionTable.id eq source[SourceTable.extension] }.first()[ExtensionTable.iconUrl],
getHttpSource(source[SourceTable.id].value).supportsLatest getHttpSource(source[SourceTable.id].value).supportsLatest
) )
} }