mirror of
https://github.com/tachiyomiorg/tachiyomi-extensions-inspector.git
synced 2025-01-12 08:49:08 +01:00
Code cleanup (#85)
* GC Unused or only used once objects * Move things around a bit * Revert some changes * Fix imports * Revert about change * Put back logger * Private logger * Revert systemtray * Move import
This commit is contained in:
parent
7450b16742
commit
104c5a8d83
@ -83,7 +83,7 @@ dependencies {
|
|||||||
testImplementation(kotlin("test-junit5"))
|
testImplementation(kotlin("test-junit5"))
|
||||||
}
|
}
|
||||||
|
|
||||||
val MainClass = "ir.armor.tachidesk.Main"
|
val MainClass = "ir.armor.tachidesk.MainKt"
|
||||||
application {
|
application {
|
||||||
mainClass.set(MainClass)
|
mainClass.set(MainClass)
|
||||||
}
|
}
|
||||||
|
@ -10,13 +10,7 @@ package ir.armor.tachidesk
|
|||||||
import ir.armor.tachidesk.server.JavalinSetup.javalinSetup
|
import ir.armor.tachidesk.server.JavalinSetup.javalinSetup
|
||||||
import ir.armor.tachidesk.server.applicationSetup
|
import ir.armor.tachidesk.server.applicationSetup
|
||||||
|
|
||||||
class Main {
|
fun main() {
|
||||||
companion object {
|
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun main(args: Array<String>) {
|
|
||||||
applicationSetup()
|
applicationSetup()
|
||||||
javalinSetup()
|
javalinSetup()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -15,7 +15,7 @@ import org.kodein.di.DI
|
|||||||
import org.kodein.di.conf.global
|
import org.kodein.di.conf.global
|
||||||
import org.kodein.di.instance
|
import org.kodein.di.instance
|
||||||
|
|
||||||
object DBMangaer {
|
object DBManager {
|
||||||
val db by lazy {
|
val db by lazy {
|
||||||
val applicationDirs by DI.global.instance<ApplicationDirs>()
|
val applicationDirs by DI.global.instance<ApplicationDirs>()
|
||||||
Database.connect("jdbc:h2:${applicationDirs.dataRoot}/database", "org.h2.Driver")
|
Database.connect("jdbc:h2:${applicationDirs.dataRoot}/database", "org.h2.Driver")
|
||||||
@ -24,7 +24,7 @@ object DBMangaer {
|
|||||||
|
|
||||||
fun databaseUp() {
|
fun databaseUp() {
|
||||||
// must mention db object so the lazy block executes
|
// must mention db object so the lazy block executes
|
||||||
val db = DBMangaer.db
|
val db = DBManager.db
|
||||||
db.useNestedTransactions = true
|
db.useNestedTransactions = true
|
||||||
|
|
||||||
val migrations = loadMigrationsFrom("ir.armor.tachidesk.model.database.migration")
|
val migrations = loadMigrationsFrom("ir.armor.tachidesk.model.database.migration")
|
@ -14,104 +14,121 @@ import org.jetbrains.exposed.dao.id.IntIdTable
|
|||||||
import org.jetbrains.exposed.sql.SchemaUtils
|
import org.jetbrains.exposed.sql.SchemaUtils
|
||||||
import org.jetbrains.exposed.sql.transactions.transaction
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
|
|
||||||
|
@Suppress("ClassName", "unused")
|
||||||
class M0001_Initial : Migration() {
|
class M0001_Initial : Migration() {
|
||||||
private object ExtensionTable : IntIdTable() {
|
private class ExtensionTable : IntIdTable() {
|
||||||
val apkName = varchar("apk_name", 1024)
|
init {
|
||||||
|
varchar("apk_name", 1024)
|
||||||
// default is the local source icon from tachiyomi
|
// default is the local source icon from tachiyomi
|
||||||
val iconUrl = varchar("icon_url", 2048)
|
varchar("icon_url", 2048)
|
||||||
.default("https://raw.githubusercontent.com/tachiyomiorg/tachiyomi/64ba127e7d43b1d7e6d58a6f5c9b2bd5fe0543f7/app/src/main/res/mipmap-xxxhdpi/ic_local_source.webp")
|
.default("https://raw.githubusercontent.com/tachiyomiorg/tachiyomi/64ba127e7d43b1d7e6d58a6f5c9b2bd5fe0543f7/app/src/main/res/mipmap-xxxhdpi/ic_local_source.webp")
|
||||||
|
varchar("name", 128)
|
||||||
|
varchar("pkg_name", 128)
|
||||||
|
varchar("version_name", 16)
|
||||||
|
integer("version_code")
|
||||||
|
varchar("lang", 10)
|
||||||
|
bool("is_nsfw")
|
||||||
|
|
||||||
val name = varchar("name", 128)
|
bool("is_installed").default(false)
|
||||||
val pkgName = varchar("pkg_name", 128)
|
bool("has_update").default(false)
|
||||||
val versionName = varchar("version_name", 16)
|
bool("is_obsolete").default(false)
|
||||||
val versionCode = integer("version_code")
|
|
||||||
val lang = varchar("lang", 10)
|
|
||||||
val isNsfw = bool("is_nsfw")
|
|
||||||
|
|
||||||
val isInstalled = bool("is_installed").default(false)
|
varchar("class_name", 1024).default("") // fully qualified name
|
||||||
val hasUpdate = bool("has_update").default(false)
|
}
|
||||||
val isObsolete = bool("is_obsolete").default(false)
|
|
||||||
|
|
||||||
val classFQName = varchar("class_name", 1024).default("") // fully qualified name
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private object SourceTable : IdTable<Long>() {
|
private class SourceTable(extensionTable: ExtensionTable) : IdTable<Long>() {
|
||||||
override val id = long("id").entityId()
|
override val id = long("id").entityId()
|
||||||
val name = varchar("name", 128)
|
init {
|
||||||
val lang = varchar("lang", 10)
|
varchar("name", 128)
|
||||||
val extension = reference("extension", ExtensionTable)
|
varchar("lang", 10)
|
||||||
val partOfFactorySource = bool("part_of_factory_source").default(false)
|
reference("extension", extensionTable)
|
||||||
|
bool("part_of_factory_source").default(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private object MangaTable : IntIdTable() {
|
private class MangaTable : IntIdTable() {
|
||||||
val url = varchar("url", 2048)
|
init {
|
||||||
val title = varchar("title", 512)
|
varchar("url", 2048)
|
||||||
val initialized = bool("initialized").default(false)
|
varchar("title", 512)
|
||||||
|
bool("initialized").default(false)
|
||||||
|
|
||||||
val artist = varchar("artist", 64).nullable()
|
varchar("artist", 64).nullable()
|
||||||
val author = varchar("author", 64).nullable()
|
varchar("author", 64).nullable()
|
||||||
val description = varchar("description", 4096).nullable()
|
varchar("description", 4096).nullable()
|
||||||
val genre = varchar("genre", 1024).nullable()
|
varchar("genre", 1024).nullable()
|
||||||
|
|
||||||
// val status = enumeration("status", MangaStatus::class).default(MangaStatus.UNKNOWN)
|
// val status = enumeration("status", MangaStatus::class).default(MangaStatus.UNKNOWN)
|
||||||
val status = integer("status").default(SManga.UNKNOWN)
|
integer("status").default(SManga.UNKNOWN)
|
||||||
val thumbnail_url = varchar("thumbnail_url", 2048).nullable()
|
varchar("thumbnail_url", 2048).nullable()
|
||||||
|
|
||||||
val inLibrary = bool("in_library").default(false)
|
bool("in_library").default(false)
|
||||||
val defaultCategory = bool("default_category").default(true)
|
bool("default_category").default(true)
|
||||||
|
|
||||||
// source is used by some ancestor of IntIdTable
|
// source is used by some ancestor of IntIdTable
|
||||||
val sourceReference = long("source")
|
long("source")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private object ChapterTable : IntIdTable() {
|
private class ChapterTable(mangaTable: MangaTable) : IntIdTable() {
|
||||||
val url = varchar("url", 2048)
|
init {
|
||||||
val name = varchar("name", 512)
|
varchar("url", 2048)
|
||||||
val date_upload = long("date_upload").default(0)
|
varchar("name", 512)
|
||||||
val chapter_number = float("chapter_number").default(-1f)
|
long("date_upload").default(0)
|
||||||
val scanlator = varchar("scanlator", 128).nullable()
|
float("chapter_number").default(-1f)
|
||||||
|
varchar("scanlator", 128).nullable()
|
||||||
|
|
||||||
val isRead = bool("read").default(false)
|
bool("read").default(false)
|
||||||
val isBookmarked = bool("bookmark").default(false)
|
bool("bookmark").default(false)
|
||||||
val lastPageRead = integer("last_page_read").default(0)
|
integer("last_page_read").default(0)
|
||||||
|
|
||||||
val chapterIndex = integer("number_in_list")
|
integer("number_in_list")
|
||||||
|
reference("manga", mangaTable)
|
||||||
val manga = reference("manga", MangaTable)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private object PageTable : IntIdTable() {
|
private class PageTable(chapterTable: ChapterTable) : IntIdTable() {
|
||||||
val index = integer("index")
|
init {
|
||||||
val url = varchar("url", 2048)
|
integer("index")
|
||||||
val imageUrl = varchar("imageUrl", 2048).nullable()
|
varchar("url", 2048)
|
||||||
|
varchar("imageUrl", 2048).nullable()
|
||||||
val chapter = reference("chapter", ChapterTable)
|
reference("chapter", chapterTable)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private object CategoryTable : IntIdTable() {
|
private class CategoryTable : IntIdTable() {
|
||||||
val name = varchar("name", 64)
|
init {
|
||||||
val isLanding = bool("is_landing").default(false)
|
varchar("name", 64)
|
||||||
val order = integer("order").default(0)
|
bool("is_landing").default(false)
|
||||||
|
integer("order").default(0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private object CategoryMangaTable : IntIdTable() {
|
private class CategoryMangaTable : IntIdTable() {
|
||||||
val category = reference("category", ir.armor.tachidesk.model.database.table.CategoryTable)
|
init {
|
||||||
val manga = reference("manga", ir.armor.tachidesk.model.database.table.MangaTable)
|
reference("category", ir.armor.tachidesk.model.database.table.CategoryTable)
|
||||||
|
reference("manga", ir.armor.tachidesk.model.database.table.MangaTable)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** initial migration, create all tables */
|
/** initial migration, create all tables */
|
||||||
override fun run() {
|
override fun run() {
|
||||||
transaction {
|
transaction {
|
||||||
|
val extensionTable = ExtensionTable()
|
||||||
|
val sourceTable = SourceTable(extensionTable)
|
||||||
|
val mangaTable = MangaTable()
|
||||||
|
val chapterTable = ChapterTable(mangaTable)
|
||||||
|
val pageTable = PageTable(chapterTable)
|
||||||
|
val categoryTable = CategoryTable()
|
||||||
|
val categoryMangaTable = CategoryMangaTable()
|
||||||
SchemaUtils.create(
|
SchemaUtils.create(
|
||||||
ExtensionTable,
|
extensionTable,
|
||||||
ExtensionTable,
|
sourceTable,
|
||||||
SourceTable,
|
mangaTable,
|
||||||
MangaTable,
|
chapterTable,
|
||||||
ChapterTable,
|
pageTable,
|
||||||
PageTable,
|
categoryTable,
|
||||||
CategoryTable,
|
categoryMangaTable,
|
||||||
CategoryMangaTable,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import ir.armor.tachidesk.model.database.migration.lib.Migration
|
|||||||
import org.jetbrains.exposed.sql.transactions.TransactionManager
|
import org.jetbrains.exposed.sql.transactions.TransactionManager
|
||||||
import org.jetbrains.exposed.sql.vendors.currentDialect
|
import org.jetbrains.exposed.sql.vendors.currentDialect
|
||||||
|
|
||||||
|
@Suppress("ClassName", "unused")
|
||||||
class M0002_ChapterTableIndexRename : Migration() {
|
class M0002_ChapterTableIndexRename : Migration() {
|
||||||
/** this migration renamed ChapterTable.NUMBER_IN_LIST to ChapterTable.INDEX */
|
/** this migration renamed ChapterTable.NUMBER_IN_LIST to ChapterTable.INDEX */
|
||||||
override fun run() {
|
override fun run() {
|
||||||
|
@ -54,6 +54,7 @@ fun runMigrations(migrations: List<Migration>, database: Database = TransactionM
|
|||||||
logger.info { "Migrations finished successfully" }
|
logger.info { "Migrations finished successfully" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("UnstableApiUsage")
|
||||||
fun loadMigrationsFrom(classPath: String): List<Migration> {
|
fun loadMigrationsFrom(classPath: String): List<Migration> {
|
||||||
return ClassPath.from(Thread.currentThread().contextClassLoader)
|
return ClassPath.from(Thread.currentThread().contextClassLoader)
|
||||||
.getTopLevelClasses(classPath)
|
.getTopLevelClasses(classPath)
|
||||||
|
@ -18,8 +18,8 @@ object CategoryTable : IntIdTable() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun CategoryTable.toDataClass(categoryEntry: ResultRow) = CategoryDataClass(
|
fun CategoryTable.toDataClass(categoryEntry: ResultRow) = CategoryDataClass(
|
||||||
categoryEntry[CategoryTable.id].value,
|
categoryEntry[this.id].value,
|
||||||
categoryEntry[CategoryTable.order],
|
categoryEntry[this.order],
|
||||||
categoryEntry[CategoryTable.name],
|
categoryEntry[this.name],
|
||||||
categoryEntry[CategoryTable.isLanding],
|
categoryEntry[this.isLanding],
|
||||||
)
|
)
|
||||||
|
@ -30,14 +30,14 @@ object ChapterTable : IntIdTable() {
|
|||||||
|
|
||||||
fun ChapterTable.toDataClass(chapterEntry: ResultRow) =
|
fun ChapterTable.toDataClass(chapterEntry: ResultRow) =
|
||||||
ChapterDataClass(
|
ChapterDataClass(
|
||||||
chapterEntry[ChapterTable.url],
|
chapterEntry[this.url],
|
||||||
chapterEntry[ChapterTable.name],
|
chapterEntry[this.name],
|
||||||
chapterEntry[ChapterTable.date_upload],
|
chapterEntry[this.date_upload],
|
||||||
chapterEntry[ChapterTable.chapter_number],
|
chapterEntry[this.chapter_number],
|
||||||
chapterEntry[ChapterTable.scanlator],
|
chapterEntry[this.scanlator],
|
||||||
chapterEntry[ChapterTable.manga].value,
|
chapterEntry[this.manga].value,
|
||||||
chapterEntry[ChapterTable.isRead],
|
chapterEntry[this.isRead],
|
||||||
chapterEntry[ChapterTable.isBookmarked],
|
chapterEntry[this.isBookmarked],
|
||||||
chapterEntry[ChapterTable.lastPageRead],
|
chapterEntry[this.lastPageRead],
|
||||||
chapterEntry[ChapterTable.chapterIndex],
|
chapterEntry[this.chapterIndex],
|
||||||
)
|
)
|
||||||
|
@ -36,21 +36,21 @@ object MangaTable : IntIdTable() {
|
|||||||
|
|
||||||
fun MangaTable.toDataClass(mangaEntry: ResultRow) =
|
fun MangaTable.toDataClass(mangaEntry: ResultRow) =
|
||||||
MangaDataClass(
|
MangaDataClass(
|
||||||
mangaEntry[MangaTable.id].value,
|
mangaEntry[this.id].value,
|
||||||
mangaEntry[MangaTable.sourceReference].toString(),
|
mangaEntry[this.sourceReference].toString(),
|
||||||
|
|
||||||
mangaEntry[MangaTable.url],
|
mangaEntry[this.url],
|
||||||
mangaEntry[MangaTable.title],
|
mangaEntry[this.title],
|
||||||
proxyThumbnailUrl(mangaEntry[MangaTable.id].value),
|
proxyThumbnailUrl(mangaEntry[this.id].value),
|
||||||
|
|
||||||
mangaEntry[MangaTable.initialized],
|
mangaEntry[this.initialized],
|
||||||
|
|
||||||
mangaEntry[MangaTable.artist],
|
mangaEntry[this.artist],
|
||||||
mangaEntry[MangaTable.author],
|
mangaEntry[this.author],
|
||||||
mangaEntry[MangaTable.description],
|
mangaEntry[this.description],
|
||||||
mangaEntry[MangaTable.genre],
|
mangaEntry[this.genre],
|
||||||
MangaStatus.valueOf(mangaEntry[MangaTable.status]).name,
|
MangaStatus.valueOf(mangaEntry[this.status]).name,
|
||||||
mangaEntry[MangaTable.inLibrary]
|
mangaEntry[this.inLibrary]
|
||||||
)
|
)
|
||||||
|
|
||||||
enum class MangaStatus(val status: Int) {
|
enum class MangaStatus(val status: Int) {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package ir.armor.tachidesk.server
|
package ir.armor.tachidesk.server
|
||||||
|
|
||||||
import io.javalin.Javalin
|
import io.javalin.Javalin
|
||||||
import ir.armor.tachidesk.Main
|
|
||||||
import ir.armor.tachidesk.impl.Category.createCategory
|
import ir.armor.tachidesk.impl.Category.createCategory
|
||||||
import ir.armor.tachidesk.impl.Category.getCategoryList
|
import ir.armor.tachidesk.impl.Category.getCategoryList
|
||||||
import ir.armor.tachidesk.impl.Category.removeCategory
|
import ir.armor.tachidesk.impl.Category.removeCategory
|
||||||
@ -68,7 +67,7 @@ object JavalinSetup {
|
|||||||
val app = Javalin.create { config ->
|
val app = Javalin.create { config ->
|
||||||
try {
|
try {
|
||||||
// if the bellow line throws an exception then webUI is not bundled
|
// if the bellow line throws an exception then webUI is not bundled
|
||||||
Main::class.java.getResource("/react/index.html")
|
this::class.java.getResource("/react/index.html")
|
||||||
|
|
||||||
// no exception so we can tell javalin to serve webUI
|
// no exception so we can tell javalin to serve webUI
|
||||||
hasWebUiBundled = true
|
hasWebUiBundled = true
|
||||||
|
@ -9,7 +9,6 @@ package ir.armor.tachidesk.server
|
|||||||
|
|
||||||
import ch.qos.logback.classic.Level
|
import ch.qos.logback.classic.Level
|
||||||
import eu.kanade.tachiyomi.App
|
import eu.kanade.tachiyomi.App
|
||||||
import ir.armor.tachidesk.Main
|
|
||||||
import ir.armor.tachidesk.model.database.databaseUp
|
import ir.armor.tachidesk.model.database.databaseUp
|
||||||
import ir.armor.tachidesk.server.util.systemTray
|
import ir.armor.tachidesk.server.util.systemTray
|
||||||
import mu.KotlinLogging
|
import mu.KotlinLogging
|
||||||
@ -81,7 +80,7 @@ fun applicationSetup() {
|
|||||||
try {
|
try {
|
||||||
val dataConfFile = File("${applicationDirs.dataRoot}/server.conf")
|
val dataConfFile = File("${applicationDirs.dataRoot}/server.conf")
|
||||||
if (!dataConfFile.exists()) {
|
if (!dataConfFile.exists()) {
|
||||||
Main::class.java.getResourceAsStream("/server-reference.conf").use { input ->
|
JavalinSetup::class.java.getResourceAsStream("/server-reference.conf").use { input ->
|
||||||
dataConfFile.outputStream().use { output ->
|
dataConfFile.outputStream().use { output ->
|
||||||
input.copyTo(output)
|
input.copyTo(output)
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,8 @@ import dorkbox.systemTray.SystemTray
|
|||||||
import dorkbox.systemTray.SystemTray.TrayType
|
import dorkbox.systemTray.SystemTray.TrayType
|
||||||
import dorkbox.util.CacheUtil
|
import dorkbox.util.CacheUtil
|
||||||
import dorkbox.util.Desktop
|
import dorkbox.util.Desktop
|
||||||
import ir.armor.tachidesk.Main
|
|
||||||
import ir.armor.tachidesk.server.BuildConfig
|
import ir.armor.tachidesk.server.BuildConfig
|
||||||
|
import ir.armor.tachidesk.server.ServerConfig
|
||||||
import ir.armor.tachidesk.server.serverConfig
|
import ir.armor.tachidesk.server.serverConfig
|
||||||
import kotlin.system.exitProcess
|
import kotlin.system.exitProcess
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ fun systemTray(): SystemTray? {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
val icon = Main::class.java.getResource("/icon/faviconlogo.png")
|
val icon = ServerConfig::class.java.getResource("/icon/faviconlogo.png")
|
||||||
|
|
||||||
// systemTray.setTooltip("Tachidesk")
|
// systemTray.setTooltip("Tachidesk")
|
||||||
systemTray.setImage(icon)
|
systemTray.setImage(icon)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user