From 077bbc3c387a84e3b28415b7d5dedc2bb7b0ad11 Mon Sep 17 00:00:00 2001 From: Aria Moradi Date: Mon, 29 Mar 2021 00:35:21 +0430 Subject: [PATCH] refactor & support for extension update: Backend --- .../extension/api/ExtensionGithubApi.kt | 9 +- .../extension/api/ExtensionGithubService.kt | 5 +- .../database/entity/ExtensionEntity.kt | 28 ---- .../tachidesk/database/entity/MangaEntity.kt | 30 ---- .../tachidesk/database/entity/SourceEntity.kt | 24 --- .../ir/armor/tachidesk/impl/Category.kt | 8 +- .../ir/armor/tachidesk/impl/CategoryManga.kt | 12 +- .../kotlin/ir/armor/tachidesk/impl/Chapter.kt | 8 +- .../ir/armor/tachidesk/impl/Extension.kt | 42 +++-- .../ir/armor/tachidesk/impl/ExtensionsList.kt | 156 +++++++++++------- .../kotlin/ir/armor/tachidesk/impl/Library.kt | 8 +- .../kotlin/ir/armor/tachidesk/impl/Manga.kt | 6 +- .../ir/armor/tachidesk/impl/MangaList.kt | 8 +- .../kotlin/ir/armor/tachidesk/impl/Page.kt | 8 +- .../kotlin/ir/armor/tachidesk/impl/Search.kt | 2 +- .../ir/armor/tachidesk/impl/SourceList.kt | 29 ++-- .../database}/CategoryMangaTable.kt | 2 +- .../table => model/database}/CategoryTable.kt | 4 +- .../table => model/database}/ChapterTable.kt | 2 +- .../database}/ExtensionTable.kt | 6 +- .../table => model/database}/MangaTable.kt | 4 +- .../table => model/database}/PageTable.kt | 2 +- .../table => model/database}/SourceTable.kt | 2 +- .../dataclass/CategoryDataClass.kt | 2 +- .../dataclass/ChapterDataClass.kt | 2 +- .../dataclass}/DBMangaer.kt | 16 +- .../dataclass/ExtensionDataClass.kt | 7 +- .../dataclass/MangaDataClass.kt | 4 +- .../dataclass/PageDataClass.kt | 2 +- .../dataclass/SourceDataClass.kt | 2 +- .../ir/armor/tachidesk/server/JavalinSetup.kt | 23 ++- .../ir/armor/tachidesk/server/ServerSetup.kt | 13 +- webUI/react/src/components/ExtensionCard.tsx | 6 +- webUI/react/src/typings.d.ts | 14 +- 34 files changed, 244 insertions(+), 252 deletions(-) delete mode 100644 server/src/main/kotlin/ir/armor/tachidesk/database/entity/ExtensionEntity.kt delete mode 100644 server/src/main/kotlin/ir/armor/tachidesk/database/entity/MangaEntity.kt delete mode 100644 server/src/main/kotlin/ir/armor/tachidesk/database/entity/SourceEntity.kt rename server/src/main/kotlin/ir/armor/tachidesk/{database/table => model/database}/CategoryMangaTable.kt (91%) rename server/src/main/kotlin/ir/armor/tachidesk/{database/table => model/database}/CategoryTable.kt (88%) rename server/src/main/kotlin/ir/armor/tachidesk/{database/table => model/database}/ChapterTable.kt (94%) rename server/src/main/kotlin/ir/armor/tachidesk/{database/table => model/database}/ExtensionTable.kt (78%) rename server/src/main/kotlin/ir/armor/tachidesk/{database/table => model/database}/MangaTable.kt (95%) rename server/src/main/kotlin/ir/armor/tachidesk/{database/table => model/database}/PageTable.kt (92%) rename server/src/main/kotlin/ir/armor/tachidesk/{database/table => model/database}/SourceTable.kt (94%) rename server/src/main/kotlin/ir/armor/tachidesk/{database => model}/dataclass/CategoryDataClass.kt (89%) rename server/src/main/kotlin/ir/armor/tachidesk/{database => model}/dataclass/ChapterDataClass.kt (92%) rename server/src/main/kotlin/ir/armor/tachidesk/{database => model/dataclass}/DBMangaer.kt (70%) rename server/src/main/kotlin/ir/armor/tachidesk/{database => model}/dataclass/ExtensionDataClass.kt (79%) rename server/src/main/kotlin/ir/armor/tachidesk/{database => model}/dataclass/MangaDataClass.kt (89%) rename server/src/main/kotlin/ir/armor/tachidesk/{database => model}/dataclass/PageDataClass.kt (88%) rename server/src/main/kotlin/ir/armor/tachidesk/{database => model}/dataclass/SourceDataClass.kt (90%) diff --git a/server/src/main/kotlin/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt b/server/src/main/kotlin/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt index f96e9ac..9d0cfad 100644 --- a/server/src/main/kotlin/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt +++ b/server/src/main/kotlin/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt @@ -11,13 +11,14 @@ package eu.kanade.tachiyomi.extension.api // import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.extension.model.Extension import eu.kanade.tachiyomi.extension.util.ExtensionLoader -import ir.armor.tachidesk.database.dataclass.ExtensionDataClass +import ir.armor.tachidesk.model.dataclass.ExtensionDataClass // import kotlinx.coroutines.Dispatchers // import kotlinx.coroutines.withContext import kotlinx.serialization.json.JsonArray import kotlinx.serialization.json.int import kotlinx.serialization.json.jsonObject import kotlinx.serialization.json.jsonPrimitive + // import uy.kohesive.injekt.injectLazy internal class ExtensionGithubApi { @@ -84,7 +85,9 @@ internal class ExtensionGithubApi { } companion object { - const val BASE_URL = "https://raw.githubusercontent.com/" - const val REPO_URL_PREFIX = "${BASE_URL}inorichi/tachiyomi-extensions/repo" +// const val BASE_URL = "https://raw.githubusercontent.com" +// const val REPO_URL_PREFIX = "${BASE_URL}/tachiyomiorg/tachiyomi-extensions/repo" + const val BASE_URL = "http://127.0.0.1:8000" + const val REPO_URL_PREFIX = "$BASE_URL/repo" } } diff --git a/server/src/main/kotlin/eu/kanade/tachiyomi/extension/api/ExtensionGithubService.kt b/server/src/main/kotlin/eu/kanade/tachiyomi/extension/api/ExtensionGithubService.kt index 73769c7..067177c 100644 --- a/server/src/main/kotlin/eu/kanade/tachiyomi/extension/api/ExtensionGithubService.kt +++ b/server/src/main/kotlin/eu/kanade/tachiyomi/extension/api/ExtensionGithubService.kt @@ -23,7 +23,7 @@ interface ExtensionGithubService { .addNetworkInterceptor { chain -> val originalResponse = chain.proceed(chain.request()) originalResponse.newBuilder() - .header("Content-Encoding", "gzip") +// .header("Content-Encoding", "gzip") .header("Content-Type", "application/json") .build() } @@ -41,6 +41,7 @@ interface ExtensionGithubService { } } - @GET("${ExtensionGithubApi.REPO_URL_PREFIX}/index.json.gz") +// @GET("${ExtensionGithubApi.REPO_URL_PREFIX}/index.json.gz") + @GET("${ExtensionGithubApi.REPO_URL_PREFIX}/index.json") suspend fun getRepo(): JsonArray } diff --git a/server/src/main/kotlin/ir/armor/tachidesk/database/entity/ExtensionEntity.kt b/server/src/main/kotlin/ir/armor/tachidesk/database/entity/ExtensionEntity.kt deleted file mode 100644 index 06a5f8d..0000000 --- a/server/src/main/kotlin/ir/armor/tachidesk/database/entity/ExtensionEntity.kt +++ /dev/null @@ -1,28 +0,0 @@ -package ir.armor.tachidesk.database.entity - -/* - * Copyright (C) Contributors to the Suwayomi project - * - * 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 ir.armor.tachidesk.database.table.ExtensionTable -import org.jetbrains.exposed.dao.IntEntity -import org.jetbrains.exposed.dao.IntEntityClass -import org.jetbrains.exposed.dao.id.EntityID - -class ExtensionEntity(id: EntityID) : IntEntity(id) { - companion object : IntEntityClass(ExtensionTable) - - var name by ExtensionTable.name - var pkgName by ExtensionTable.pkgName - var versionName by ExtensionTable.versionName - var versionCode by ExtensionTable.versionCode - var lang by ExtensionTable.lang - var isNsfw by ExtensionTable.isNsfw - var apkName by ExtensionTable.apkName - var iconUrl by ExtensionTable.iconUrl - var installed by ExtensionTable.installed - var classFQName by ExtensionTable.classFQName -} diff --git a/server/src/main/kotlin/ir/armor/tachidesk/database/entity/MangaEntity.kt b/server/src/main/kotlin/ir/armor/tachidesk/database/entity/MangaEntity.kt deleted file mode 100644 index 7890c6d..0000000 --- a/server/src/main/kotlin/ir/armor/tachidesk/database/entity/MangaEntity.kt +++ /dev/null @@ -1,30 +0,0 @@ -package ir.armor.tachidesk.database.entity - -/* - * Copyright (C) Contributors to the Suwayomi project - * - * 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 ir.armor.tachidesk.database.table.MangaTable -import org.jetbrains.exposed.dao.IntEntity -import org.jetbrains.exposed.dao.IntEntityClass -import org.jetbrains.exposed.dao.id.EntityID - -class MangaEntity(id: EntityID) : IntEntity(id) { - companion object : IntEntityClass(MangaTable) - - var url by MangaTable.url - var title by MangaTable.title - var initialized by MangaTable.initialized - - var artist by MangaTable.artist - var author by MangaTable.author - var description by MangaTable.description - var genre by MangaTable.genre - var status by MangaTable.status - var thumbnail_url by MangaTable.thumbnail_url - - var sourceReference by MangaEntity referencedOn MangaTable.sourceReference -} diff --git a/server/src/main/kotlin/ir/armor/tachidesk/database/entity/SourceEntity.kt b/server/src/main/kotlin/ir/armor/tachidesk/database/entity/SourceEntity.kt deleted file mode 100644 index b516ed1..0000000 --- a/server/src/main/kotlin/ir/armor/tachidesk/database/entity/SourceEntity.kt +++ /dev/null @@ -1,24 +0,0 @@ -package ir.armor.tachidesk.database.entity - -/* - * Copyright (C) Contributors to the Suwayomi project - * - * 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 ir.armor.tachidesk.database.table.SourceTable -import org.jetbrains.exposed.dao.EntityClass -import org.jetbrains.exposed.dao.LongEntity -import org.jetbrains.exposed.dao.id.EntityID - -class SourceEntity(id: EntityID) : LongEntity(id) { - companion object : EntityClass(SourceTable, null) - - var sourceId by SourceTable.id - var name by SourceTable.name - var lang by SourceTable.lang - var extension by ExtensionEntity referencedOn SourceTable.extension - var partOfFactorySource by SourceTable.partOfFactorySource - var positionInFactorySource by SourceTable.positionInFactorySource -} diff --git a/server/src/main/kotlin/ir/armor/tachidesk/impl/Category.kt b/server/src/main/kotlin/ir/armor/tachidesk/impl/Category.kt index 62af7df..2624837 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/impl/Category.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/impl/Category.kt @@ -7,10 +7,10 @@ package ir.armor.tachidesk.impl * 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 ir.armor.tachidesk.database.dataclass.CategoryDataClass -import ir.armor.tachidesk.database.table.CategoryMangaTable -import ir.armor.tachidesk.database.table.CategoryTable -import ir.armor.tachidesk.database.table.toDataClass +import ir.armor.tachidesk.model.database.CategoryMangaTable +import ir.armor.tachidesk.model.database.CategoryTable +import ir.armor.tachidesk.model.database.toDataClass +import ir.armor.tachidesk.model.dataclass.CategoryDataClass import org.jetbrains.exposed.sql.SortOrder import org.jetbrains.exposed.sql.deleteWhere import org.jetbrains.exposed.sql.insert diff --git a/server/src/main/kotlin/ir/armor/tachidesk/impl/CategoryManga.kt b/server/src/main/kotlin/ir/armor/tachidesk/impl/CategoryManga.kt index a3fa70f..40adaab 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/impl/CategoryManga.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/impl/CategoryManga.kt @@ -7,12 +7,12 @@ package ir.armor.tachidesk.impl * 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 ir.armor.tachidesk.database.dataclass.CategoryDataClass -import ir.armor.tachidesk.database.dataclass.MangaDataClass -import ir.armor.tachidesk.database.table.CategoryMangaTable -import ir.armor.tachidesk.database.table.CategoryTable -import ir.armor.tachidesk.database.table.MangaTable -import ir.armor.tachidesk.database.table.toDataClass +import ir.armor.tachidesk.model.database.CategoryMangaTable +import ir.armor.tachidesk.model.database.CategoryTable +import ir.armor.tachidesk.model.database.MangaTable +import ir.armor.tachidesk.model.database.toDataClass +import ir.armor.tachidesk.model.dataclass.CategoryDataClass +import ir.armor.tachidesk.model.dataclass.MangaDataClass import org.jetbrains.exposed.sql.SortOrder import org.jetbrains.exposed.sql.and import org.jetbrains.exposed.sql.deleteWhere diff --git a/server/src/main/kotlin/ir/armor/tachidesk/impl/Chapter.kt b/server/src/main/kotlin/ir/armor/tachidesk/impl/Chapter.kt index cfdfd6d..09894f5 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/impl/Chapter.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/impl/Chapter.kt @@ -9,10 +9,10 @@ package ir.armor.tachidesk.impl import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga -import ir.armor.tachidesk.database.dataclass.ChapterDataClass -import ir.armor.tachidesk.database.table.ChapterTable -import ir.armor.tachidesk.database.table.MangaTable -import ir.armor.tachidesk.database.table.PageTable +import ir.armor.tachidesk.model.database.ChapterTable +import ir.armor.tachidesk.model.database.MangaTable +import ir.armor.tachidesk.model.database.PageTable +import ir.armor.tachidesk.model.dataclass.ChapterDataClass import org.jetbrains.exposed.sql.and import org.jetbrains.exposed.sql.insert import org.jetbrains.exposed.sql.insertAndGetId diff --git a/server/src/main/kotlin/ir/armor/tachidesk/impl/Extension.kt b/server/src/main/kotlin/ir/armor/tachidesk/impl/Extension.kt index 8392993..ed5ab89 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/impl/Extension.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/impl/Extension.kt @@ -15,9 +15,9 @@ import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.NetworkHelper import eu.kanade.tachiyomi.source.SourceFactory import eu.kanade.tachiyomi.source.online.HttpSource -import ir.armor.tachidesk.database.table.ExtensionTable -import ir.armor.tachidesk.database.table.SourceTable import ir.armor.tachidesk.impl.util.APKExtractor +import ir.armor.tachidesk.model.database.ExtensionTable +import ir.armor.tachidesk.model.database.SourceTable import ir.armor.tachidesk.server.applicationDirs import kotlinx.coroutines.runBlocking import mu.KotlinLogging @@ -71,10 +71,10 @@ private fun dex2jar(dexFile: String, jarFile: String, fileNameWithoutType: Strin } } -fun installAPK(apkName: String): Int { - logger.debug("Installing $apkName") - val extensionRecord = getExtensionList(true).first { it.apkName == apkName } - val fileNameWithoutType = apkName.substringBefore(".apk") +fun installExtension(pkgName: String): Int { + logger.debug("Installing $pkgName") + val extensionRecord = extensionTableAsDataClass().first { it.pkgName == pkgName } + val fileNameWithoutType = extensionRecord.apkName.substringBefore(".apk") val dirPathWithoutType = "${applicationDirs.extensionsRoot}/$fileNameWithoutType" // check if we don't have the dex file already downloaded @@ -145,7 +145,7 @@ fun installAPK(apkName: String): Int { // update extension info transaction { ExtensionTable.update({ ExtensionTable.name eq extensionRecord.name }) { - it[installed] = true + it[isInstalled] = true it[classFQName] = className } } @@ -168,18 +168,18 @@ private fun downloadAPKFile(url: String, apkPath: String) { sink.close() } -fun removeExtension(apkName: String) { - logger.debug("Uninstalling $apkName") +fun removeExtension(pkgName: String) { + logger.debug("Uninstalling $pkgName") - val extensionRecord = getExtensionList(true).first { it.apkName == apkName } - val fileNameWithoutType = apkName.substringBefore(".apk") + val extensionRecord = extensionTableAsDataClass().first { it.pkgName == pkgName } + val fileNameWithoutType = extensionRecord.apkName.substringBefore(".apk") val jarPath = "${applicationDirs.extensionsRoot}/$fileNameWithoutType.jar" transaction { val extensionId = ExtensionTable.select { ExtensionTable.name eq extensionRecord.name }.first()[ExtensionTable.id] SourceTable.deleteWhere { SourceTable.extension eq extensionId } ExtensionTable.update({ ExtensionTable.name eq extensionRecord.name }) { - it[ExtensionTable.installed] = false + it[isInstalled] = false } } @@ -188,6 +188,24 @@ fun removeExtension(apkName: String) { } } +fun updateExtension(pkgName: String): Int { + val targetExtension = ExtensionListData.updateMap.remove(pkgName)!! + removeExtension(pkgName) + transaction { + ExtensionTable.update({ ExtensionTable.pkgName eq pkgName }) { + it[name] = targetExtension.name + it[versionName] = targetExtension.versionName + it[versionCode] = targetExtension.versionCode + it[lang] = targetExtension.lang + it[isNsfw] = targetExtension.isNsfw + it[apkName] = targetExtension.apkName + it[iconUrl] = targetExtension.iconUrl + it[hasUpdate] = false + } + } + return installExtension(pkgName) +} + val network: NetworkHelper by injectLazy() fun getExtensionIcon(apkName: String): Pair { diff --git a/server/src/main/kotlin/ir/armor/tachidesk/impl/ExtensionsList.kt b/server/src/main/kotlin/ir/armor/tachidesk/impl/ExtensionsList.kt index 1fdc668..7ea4491 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/impl/ExtensionsList.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/impl/ExtensionsList.kt @@ -9,86 +9,122 @@ package ir.armor.tachidesk.impl import eu.kanade.tachiyomi.extension.api.ExtensionGithubApi import eu.kanade.tachiyomi.extension.model.Extension -import ir.armor.tachidesk.database.dataclass.ExtensionDataClass -import ir.armor.tachidesk.database.table.ExtensionTable +import ir.armor.tachidesk.model.database.ExtensionTable +import ir.armor.tachidesk.model.dataclass.ExtensionDataClass import kotlinx.coroutines.runBlocking import mu.KotlinLogging +import org.jetbrains.exposed.sql.deleteWhere import org.jetbrains.exposed.sql.insert import org.jetbrains.exposed.sql.select import org.jetbrains.exposed.sql.selectAll import org.jetbrains.exposed.sql.transactions.transaction import org.jetbrains.exposed.sql.update +import java.util.concurrent.ConcurrentHashMap private val logger = KotlinLogging.logger {} -private object Data { - var lastExtensionCheck: Long = 0 +object ExtensionListData { + var lastUpdateCheck: Long = 0 + var updateMap = ConcurrentHashMap() } -private fun extensionDatabaseIsEmtpy(): Boolean { - return transaction { - return@transaction ExtensionTable.selectAll().count() == 0L - } -} - -fun getExtensionList(offline: Boolean = false): List { +fun getExtensionList(): List { // update if 60 seconds has passed or requested offline and database is empty - if (Data.lastExtensionCheck + 60 * 1000 < System.currentTimeMillis() || (offline && extensionDatabaseIsEmtpy())) { + if (ExtensionListData.lastUpdateCheck + 60 * 1000 < System.currentTimeMillis()) { logger.debug("Getting extensions list from the internet") - Data.lastExtensionCheck = System.currentTimeMillis() - var foundExtensions: List + ExtensionListData.lastUpdateCheck = System.currentTimeMillis() runBlocking { - val api = ExtensionGithubApi() - foundExtensions = api.findExtensions() - transaction { - foundExtensions.forEach { foundExtension -> - val extensionRecord = ExtensionTable.select { ExtensionTable.name eq foundExtension.name }.firstOrNull() - if (extensionRecord != null) { - // update the record - ExtensionTable.update({ ExtensionTable.name eq foundExtension.name }) { - it[name] = foundExtension.name - it[pkgName] = foundExtension.pkgName - it[versionName] = foundExtension.versionName - it[versionCode] = foundExtension.versionCode - it[lang] = foundExtension.lang - it[isNsfw] = foundExtension.isNsfw - it[apkName] = foundExtension.apkName - it[iconUrl] = foundExtension.iconUrl - } - } else { - // insert new record - ExtensionTable.insert { - it[name] = foundExtension.name - it[pkgName] = foundExtension.pkgName - it[versionName] = foundExtension.versionName - it[versionCode] = foundExtension.versionCode - it[lang] = foundExtension.lang - it[isNsfw] = foundExtension.isNsfw - it[apkName] = foundExtension.apkName - it[iconUrl] = foundExtension.iconUrl - } - } - } - } + val foundExtensions = ExtensionGithubApi().findExtensions() + updateExtensionDatabase(foundExtensions) } } else { logger.debug("used cached extension list") } - return transaction { - return@transaction ExtensionTable.selectAll().map { - ExtensionDataClass( - it[ExtensionTable.name], - it[ExtensionTable.pkgName], - it[ExtensionTable.versionName], - it[ExtensionTable.versionCode], - it[ExtensionTable.lang], - it[ExtensionTable.isNsfw], - it[ExtensionTable.apkName], - getExtensionIconUrl(it[ExtensionTable.apkName]), - it[ExtensionTable.installed], - it[ExtensionTable.classFQName] - ) + return extensionTableAsDataClass() +} + +fun extensionTableAsDataClass() = transaction { + return@transaction ExtensionTable.selectAll().map { + ExtensionDataClass( + it[ExtensionTable.name], + it[ExtensionTable.pkgName], + it[ExtensionTable.versionName], + it[ExtensionTable.versionCode], + it[ExtensionTable.lang], + it[ExtensionTable.isNsfw], + it[ExtensionTable.apkName], + getExtensionIconUrl(it[ExtensionTable.apkName]), + it[ExtensionTable.isInstalled], + it[ExtensionTable.hasUpdate], + it[ExtensionTable.isObsolete], + ) + } +} + +private fun updateExtensionDatabase(foundExtensions: List) { + transaction { + foundExtensions.forEach { foundExtension -> + val extensionRecord = ExtensionTable.select { ExtensionTable.pkgName eq foundExtension.pkgName }.firstOrNull() + if (extensionRecord != null) { + if (extensionRecord[ExtensionTable.isInstalled]) { + if (foundExtension.versionCode > extensionRecord[ExtensionTable.versionCode]) { + // there is an update + ExtensionTable.update({ ExtensionTable.pkgName eq foundExtension.pkgName }) { + it[hasUpdate] = true + } + ExtensionListData.updateMap.putIfAbsent(foundExtension.pkgName, foundExtension) + } else if (foundExtension.versionCode < extensionRecord[ExtensionTable.versionCode]) { + // some how the user installed an invalid version + ExtensionTable.update({ ExtensionTable.pkgName eq foundExtension.pkgName }) { + it[isObsolete] = true + } + } else { + // the two are equal + // NOOP + } + } else { + // extension is not installed so we can overwrite the data without a care + ExtensionTable.update({ ExtensionTable.pkgName eq foundExtension.pkgName }) { + it[name] = foundExtension.name + it[versionName] = foundExtension.versionName + it[versionCode] = foundExtension.versionCode + it[lang] = foundExtension.lang + it[isNsfw] = foundExtension.isNsfw + it[apkName] = foundExtension.apkName + it[iconUrl] = foundExtension.iconUrl + } + } + } else { + // insert new record + ExtensionTable.insert { + it[name] = foundExtension.name + it[pkgName] = foundExtension.pkgName + it[versionName] = foundExtension.versionName + it[versionCode] = foundExtension.versionCode + it[lang] = foundExtension.lang + it[isNsfw] = foundExtension.isNsfw + it[apkName] = foundExtension.apkName + it[iconUrl] = foundExtension.iconUrl + } + } + } + + // deal with obsolete extensions + ExtensionTable.selectAll().forEach { extensionRecord -> + val foundExtension = foundExtensions.find { it.pkgName == extensionRecord[ExtensionTable.pkgName] } + if (foundExtension == null) { + // this extensions is obsolete + if (extensionRecord[ExtensionTable.isInstalled]) { + // is installed so we should mark it as obsolete + ExtensionTable.update({ ExtensionTable.pkgName eq extensionRecord[ExtensionTable.pkgName] }) { + it[isObsolete] = true + } + } else { + // is not installed so we can remove the record without a care + ExtensionTable.deleteWhere { ExtensionTable.pkgName eq extensionRecord[ExtensionTable.pkgName] } + } + } } } } diff --git a/server/src/main/kotlin/ir/armor/tachidesk/impl/Library.kt b/server/src/main/kotlin/ir/armor/tachidesk/impl/Library.kt index 28307ec..354ef52 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/impl/Library.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/impl/Library.kt @@ -7,10 +7,10 @@ package ir.armor.tachidesk.impl * 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 ir.armor.tachidesk.database.dataclass.MangaDataClass -import ir.armor.tachidesk.database.table.CategoryMangaTable -import ir.armor.tachidesk.database.table.MangaTable -import ir.armor.tachidesk.database.table.toDataClass +import ir.armor.tachidesk.model.database.CategoryMangaTable +import ir.armor.tachidesk.model.database.MangaTable +import ir.armor.tachidesk.model.database.toDataClass +import ir.armor.tachidesk.model.dataclass.MangaDataClass import org.jetbrains.exposed.sql.and import org.jetbrains.exposed.sql.deleteWhere import org.jetbrains.exposed.sql.select diff --git a/server/src/main/kotlin/ir/armor/tachidesk/impl/Manga.kt b/server/src/main/kotlin/ir/armor/tachidesk/impl/Manga.kt index 4644951..bf02e91 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/impl/Manga.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/impl/Manga.kt @@ -9,9 +9,9 @@ package ir.armor.tachidesk.impl import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.source.model.SManga -import ir.armor.tachidesk.database.dataclass.MangaDataClass -import ir.armor.tachidesk.database.table.MangaStatus -import ir.armor.tachidesk.database.table.MangaTable +import ir.armor.tachidesk.model.database.MangaStatus +import ir.armor.tachidesk.model.database.MangaTable +import ir.armor.tachidesk.model.dataclass.MangaDataClass import ir.armor.tachidesk.server.applicationDirs import org.jetbrains.exposed.sql.select import org.jetbrains.exposed.sql.transactions.transaction diff --git a/server/src/main/kotlin/ir/armor/tachidesk/impl/MangaList.kt b/server/src/main/kotlin/ir/armor/tachidesk/impl/MangaList.kt index e60085d..7b3ee1e 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/impl/MangaList.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/impl/MangaList.kt @@ -8,10 +8,10 @@ package ir.armor.tachidesk.impl * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ import eu.kanade.tachiyomi.source.model.MangasPage -import ir.armor.tachidesk.database.dataclass.MangaDataClass -import ir.armor.tachidesk.database.dataclass.PagedMangaListDataClass -import ir.armor.tachidesk.database.table.MangaStatus -import ir.armor.tachidesk.database.table.MangaTable +import ir.armor.tachidesk.model.database.MangaStatus +import ir.armor.tachidesk.model.database.MangaTable +import ir.armor.tachidesk.model.dataclass.MangaDataClass +import ir.armor.tachidesk.model.dataclass.PagedMangaListDataClass import org.jetbrains.exposed.sql.insertAndGetId import org.jetbrains.exposed.sql.select import org.jetbrains.exposed.sql.transactions.transaction diff --git a/server/src/main/kotlin/ir/armor/tachidesk/impl/Page.kt b/server/src/main/kotlin/ir/armor/tachidesk/impl/Page.kt index 62bd9d3..7b4d1d9 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/impl/Page.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/impl/Page.kt @@ -9,10 +9,10 @@ package ir.armor.tachidesk.impl import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.online.HttpSource -import ir.armor.tachidesk.database.table.ChapterTable -import ir.armor.tachidesk.database.table.MangaTable -import ir.armor.tachidesk.database.table.PageTable -import ir.armor.tachidesk.database.table.SourceTable +import ir.armor.tachidesk.model.database.ChapterTable +import ir.armor.tachidesk.model.database.MangaTable +import ir.armor.tachidesk.model.database.PageTable +import ir.armor.tachidesk.model.database.SourceTable import ir.armor.tachidesk.server.applicationDirs import org.jetbrains.exposed.sql.and import org.jetbrains.exposed.sql.select diff --git a/server/src/main/kotlin/ir/armor/tachidesk/impl/Search.kt b/server/src/main/kotlin/ir/armor/tachidesk/impl/Search.kt index 6dd8984..a8b84cb 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/impl/Search.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/impl/Search.kt @@ -7,7 +7,7 @@ package ir.armor.tachidesk.impl * 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 ir.armor.tachidesk.database.dataclass.PagedMangaListDataClass +import ir.armor.tachidesk.model.dataclass.PagedMangaListDataClass fun sourceFilters(sourceId: Long) { val source = getHttpSource(sourceId) diff --git a/server/src/main/kotlin/ir/armor/tachidesk/impl/SourceList.kt b/server/src/main/kotlin/ir/armor/tachidesk/impl/SourceList.kt index a528bd6..b81bcbb 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/impl/SourceList.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/impl/SourceList.kt @@ -9,17 +9,14 @@ package ir.armor.tachidesk.impl import eu.kanade.tachiyomi.source.SourceFactory import eu.kanade.tachiyomi.source.online.HttpSource -import ir.armor.tachidesk.database.dataclass.SourceDataClass -import ir.armor.tachidesk.database.entity.ExtensionEntity -import ir.armor.tachidesk.database.entity.SourceEntity -import ir.armor.tachidesk.database.table.ExtensionTable -import ir.armor.tachidesk.database.table.SourceTable +import ir.armor.tachidesk.model.database.ExtensionTable +import ir.armor.tachidesk.model.database.SourceTable +import ir.armor.tachidesk.model.dataclass.SourceDataClass import ir.armor.tachidesk.server.applicationDirs import mu.KotlinLogging import org.jetbrains.exposed.sql.select import org.jetbrains.exposed.sql.selectAll import org.jetbrains.exposed.sql.transactions.transaction -import java.lang.NullPointerException import java.net.URL import java.net.URLClassLoader @@ -30,8 +27,8 @@ private val extensionCache = mutableListOf>() fun getHttpSource(sourceId: Long): HttpSource { val sourceRecord = transaction { - SourceEntity.findById(sourceId) - } ?: throw NullPointerException("Source with id $sourceId is not installed") + SourceTable.select { SourceTable.id eq sourceId }.firstOrNull()!! + } val cachedResult: Pair? = sourceCache.firstOrNull { it.first == sourceId } if (cachedResult != null) { @@ -40,10 +37,10 @@ fun getHttpSource(sourceId: Long): HttpSource { } val result: HttpSource = transaction { - val extensionId = sourceRecord.extension.id.value - val extensionRecord = ExtensionEntity.findById(extensionId)!! - val apkName = extensionRecord.apkName - val className = extensionRecord.classFQName + val extensionId = sourceRecord[SourceTable.extension] + val extensionRecord = ExtensionTable.select { ExtensionTable.id eq extensionId }.firstOrNull()!! + val apkName = extensionRecord[ExtensionTable.apkName] + val className = extensionRecord[ExtensionTable.classFQName] val jarName = apkName.substringBefore(".apk") + ".jar" val jarPath = "${applicationDirs.extensionsRoot}/$jarName" @@ -60,13 +57,15 @@ fun getHttpSource(sourceId: Long): HttpSource { val classToLoad = Class.forName(className, true, child) classToLoad.newInstance() } - if (sourceRecord.partOfFactorySource) { + if (sourceRecord[SourceTable.partOfFactorySource]) { + val positionInFactorySource = sourceRecord[SourceTable.positionInFactorySource]!! return@transaction if (usedCached) { - (instance as List)[sourceRecord.positionInFactorySource!!] + @Suppress("UNCHECKED_CAST") + (instance as List)[positionInFactorySource] } else { val list = (instance as SourceFactory).createSources() extensionCache.add(Pair(jarPath, list)) - list[sourceRecord.positionInFactorySource!!] as HttpSource + list[positionInFactorySource] as HttpSource } } else { if (!usedCached) diff --git a/server/src/main/kotlin/ir/armor/tachidesk/database/table/CategoryMangaTable.kt b/server/src/main/kotlin/ir/armor/tachidesk/model/database/CategoryMangaTable.kt similarity index 91% rename from server/src/main/kotlin/ir/armor/tachidesk/database/table/CategoryMangaTable.kt rename to server/src/main/kotlin/ir/armor/tachidesk/model/database/CategoryMangaTable.kt index 07c23a3..000e65e 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/database/table/CategoryMangaTable.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/model/database/CategoryMangaTable.kt @@ -1,4 +1,4 @@ -package ir.armor.tachidesk.database.table +package ir.armor.tachidesk.model.database /* * Copyright (C) Contributors to the Suwayomi project diff --git a/server/src/main/kotlin/ir/armor/tachidesk/database/table/CategoryTable.kt b/server/src/main/kotlin/ir/armor/tachidesk/model/database/CategoryTable.kt similarity index 88% rename from server/src/main/kotlin/ir/armor/tachidesk/database/table/CategoryTable.kt rename to server/src/main/kotlin/ir/armor/tachidesk/model/database/CategoryTable.kt index 6f9c1c6..2eda677 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/database/table/CategoryTable.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/model/database/CategoryTable.kt @@ -1,4 +1,4 @@ -package ir.armor.tachidesk.database.table +package ir.armor.tachidesk.model.database /* * Copyright (C) Contributors to the Suwayomi project @@ -7,7 +7,7 @@ package ir.armor.tachidesk.database.table * 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 ir.armor.tachidesk.database.dataclass.CategoryDataClass +import ir.armor.tachidesk.model.dataclass.CategoryDataClass import org.jetbrains.exposed.dao.id.IntIdTable import org.jetbrains.exposed.sql.ResultRow diff --git a/server/src/main/kotlin/ir/armor/tachidesk/database/table/ChapterTable.kt b/server/src/main/kotlin/ir/armor/tachidesk/model/database/ChapterTable.kt similarity index 94% rename from server/src/main/kotlin/ir/armor/tachidesk/database/table/ChapterTable.kt rename to server/src/main/kotlin/ir/armor/tachidesk/model/database/ChapterTable.kt index 8ecf6ae..40d7d28 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/database/table/ChapterTable.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/model/database/ChapterTable.kt @@ -1,4 +1,4 @@ -package ir.armor.tachidesk.database.table +package ir.armor.tachidesk.model.database /* * Copyright (C) Contributors to the Suwayomi project diff --git a/server/src/main/kotlin/ir/armor/tachidesk/database/table/ExtensionTable.kt b/server/src/main/kotlin/ir/armor/tachidesk/model/database/ExtensionTable.kt similarity index 78% rename from server/src/main/kotlin/ir/armor/tachidesk/database/table/ExtensionTable.kt rename to server/src/main/kotlin/ir/armor/tachidesk/model/database/ExtensionTable.kt index b9b7351..f5da6d6 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/database/table/ExtensionTable.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/model/database/ExtensionTable.kt @@ -1,4 +1,4 @@ -package ir.armor.tachidesk.database.table +package ir.armor.tachidesk.model.database /* * Copyright (C) Contributors to the Suwayomi project @@ -19,6 +19,8 @@ object ExtensionTable : IntIdTable() { val apkName = varchar("apk_name", 1024) val iconUrl = varchar("icon_url", 2048) - val installed = bool("installed").default(false) + val isInstalled = bool("is_installed").default(false) + val hasUpdate = bool("has_update").default(false) + val isObsolete = bool("is_obsolete").default(false) val classFQName = varchar("class_name", 256).default("") // fully qualified name } diff --git a/server/src/main/kotlin/ir/armor/tachidesk/database/table/MangaTable.kt b/server/src/main/kotlin/ir/armor/tachidesk/model/database/MangaTable.kt similarity index 95% rename from server/src/main/kotlin/ir/armor/tachidesk/database/table/MangaTable.kt rename to server/src/main/kotlin/ir/armor/tachidesk/model/database/MangaTable.kt index 22316c4..58faa41 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/database/table/MangaTable.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/model/database/MangaTable.kt @@ -1,4 +1,4 @@ -package ir.armor.tachidesk.database.table +package ir.armor.tachidesk.model.database /* * Copyright (C) Contributors to the Suwayomi project @@ -8,8 +8,8 @@ package ir.armor.tachidesk.database.table * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ import eu.kanade.tachiyomi.source.model.SManga -import ir.armor.tachidesk.database.dataclass.MangaDataClass import ir.armor.tachidesk.impl.proxyThumbnailUrl +import ir.armor.tachidesk.model.dataclass.MangaDataClass import org.jetbrains.exposed.dao.id.IntIdTable import org.jetbrains.exposed.sql.ResultRow diff --git a/server/src/main/kotlin/ir/armor/tachidesk/database/table/PageTable.kt b/server/src/main/kotlin/ir/armor/tachidesk/model/database/PageTable.kt similarity index 92% rename from server/src/main/kotlin/ir/armor/tachidesk/database/table/PageTable.kt rename to server/src/main/kotlin/ir/armor/tachidesk/model/database/PageTable.kt index c56816b..4cf79b6 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/database/table/PageTable.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/model/database/PageTable.kt @@ -1,4 +1,4 @@ -package ir.armor.tachidesk.database.table +package ir.armor.tachidesk.model.database /* * Copyright (C) Contributors to the Suwayomi project diff --git a/server/src/main/kotlin/ir/armor/tachidesk/database/table/SourceTable.kt b/server/src/main/kotlin/ir/armor/tachidesk/model/database/SourceTable.kt similarity index 94% rename from server/src/main/kotlin/ir/armor/tachidesk/database/table/SourceTable.kt rename to server/src/main/kotlin/ir/armor/tachidesk/model/database/SourceTable.kt index 4af6cc5..f117a57 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/database/table/SourceTable.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/model/database/SourceTable.kt @@ -1,4 +1,4 @@ -package ir.armor.tachidesk.database.table +package ir.armor.tachidesk.model.database /* * Copyright (C) Contributors to the Suwayomi project diff --git a/server/src/main/kotlin/ir/armor/tachidesk/database/dataclass/CategoryDataClass.kt b/server/src/main/kotlin/ir/armor/tachidesk/model/dataclass/CategoryDataClass.kt similarity index 89% rename from server/src/main/kotlin/ir/armor/tachidesk/database/dataclass/CategoryDataClass.kt rename to server/src/main/kotlin/ir/armor/tachidesk/model/dataclass/CategoryDataClass.kt index 250d013..c18faff 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/database/dataclass/CategoryDataClass.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/model/dataclass/CategoryDataClass.kt @@ -1,4 +1,4 @@ -package ir.armor.tachidesk.database.dataclass +package ir.armor.tachidesk.model.dataclass /* * Copyright (C) Contributors to the Suwayomi project diff --git a/server/src/main/kotlin/ir/armor/tachidesk/database/dataclass/ChapterDataClass.kt b/server/src/main/kotlin/ir/armor/tachidesk/model/dataclass/ChapterDataClass.kt similarity index 92% rename from server/src/main/kotlin/ir/armor/tachidesk/database/dataclass/ChapterDataClass.kt rename to server/src/main/kotlin/ir/armor/tachidesk/model/dataclass/ChapterDataClass.kt index d0fdf9d..0249a0d 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/database/dataclass/ChapterDataClass.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/model/dataclass/ChapterDataClass.kt @@ -1,4 +1,4 @@ -package ir.armor.tachidesk.database.dataclass +package ir.armor.tachidesk.model.dataclass /* * Copyright (C) Contributors to the Suwayomi project diff --git a/server/src/main/kotlin/ir/armor/tachidesk/database/DBMangaer.kt b/server/src/main/kotlin/ir/armor/tachidesk/model/dataclass/DBMangaer.kt similarity index 70% rename from server/src/main/kotlin/ir/armor/tachidesk/database/DBMangaer.kt rename to server/src/main/kotlin/ir/armor/tachidesk/model/dataclass/DBMangaer.kt index 0d1c0de..155ca21 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/database/DBMangaer.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/model/dataclass/DBMangaer.kt @@ -1,4 +1,4 @@ -package ir.armor.tachidesk.database +package ir.armor.tachidesk.model.dataclass /* * Copyright (C) Contributors to the Suwayomi project @@ -7,13 +7,13 @@ package ir.armor.tachidesk.database * 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 ir.armor.tachidesk.database.table.CategoryMangaTable -import ir.armor.tachidesk.database.table.CategoryTable -import ir.armor.tachidesk.database.table.ChapterTable -import ir.armor.tachidesk.database.table.ExtensionTable -import ir.armor.tachidesk.database.table.MangaTable -import ir.armor.tachidesk.database.table.PageTable -import ir.armor.tachidesk.database.table.SourceTable +import ir.armor.tachidesk.model.database.CategoryMangaTable +import ir.armor.tachidesk.model.database.CategoryTable +import ir.armor.tachidesk.model.database.ChapterTable +import ir.armor.tachidesk.model.database.ExtensionTable +import ir.armor.tachidesk.model.database.MangaTable +import ir.armor.tachidesk.model.database.PageTable +import ir.armor.tachidesk.model.database.SourceTable import ir.armor.tachidesk.server.applicationDirs import org.jetbrains.exposed.sql.Database import org.jetbrains.exposed.sql.SchemaUtils diff --git a/server/src/main/kotlin/ir/armor/tachidesk/database/dataclass/ExtensionDataClass.kt b/server/src/main/kotlin/ir/armor/tachidesk/model/dataclass/ExtensionDataClass.kt similarity index 79% rename from server/src/main/kotlin/ir/armor/tachidesk/database/dataclass/ExtensionDataClass.kt rename to server/src/main/kotlin/ir/armor/tachidesk/model/dataclass/ExtensionDataClass.kt index 8df7f76..de0eb6c 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/database/dataclass/ExtensionDataClass.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/model/dataclass/ExtensionDataClass.kt @@ -1,4 +1,4 @@ -package ir.armor.tachidesk.database.dataclass +package ir.armor.tachidesk.model.dataclass /* * Copyright (C) Contributors to the Suwayomi project @@ -16,6 +16,7 @@ data class ExtensionDataClass( val isNsfw: Boolean, val apkName: String, val iconUrl: String, - val installed: Boolean, - val classFQName: String, + val isInstalled: Boolean, + val hasUpdate: Boolean, + val isObsolete: Boolean, ) diff --git a/server/src/main/kotlin/ir/armor/tachidesk/database/dataclass/MangaDataClass.kt b/server/src/main/kotlin/ir/armor/tachidesk/model/dataclass/MangaDataClass.kt similarity index 89% rename from server/src/main/kotlin/ir/armor/tachidesk/database/dataclass/MangaDataClass.kt rename to server/src/main/kotlin/ir/armor/tachidesk/model/dataclass/MangaDataClass.kt index dffe8ee..d11a080 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/database/dataclass/MangaDataClass.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/model/dataclass/MangaDataClass.kt @@ -1,4 +1,4 @@ -package ir.armor.tachidesk.database.dataclass +package ir.armor.tachidesk.model.dataclass /* * Copyright (C) Contributors to the Suwayomi project @@ -7,7 +7,7 @@ package ir.armor.tachidesk.database.dataclass * 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 ir.armor.tachidesk.database.table.MangaStatus +import ir.armor.tachidesk.model.database.MangaStatus data class MangaDataClass( val id: Int, diff --git a/server/src/main/kotlin/ir/armor/tachidesk/database/dataclass/PageDataClass.kt b/server/src/main/kotlin/ir/armor/tachidesk/model/dataclass/PageDataClass.kt similarity index 88% rename from server/src/main/kotlin/ir/armor/tachidesk/database/dataclass/PageDataClass.kt rename to server/src/main/kotlin/ir/armor/tachidesk/model/dataclass/PageDataClass.kt index 0d58d5d..ef326a2 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/database/dataclass/PageDataClass.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/model/dataclass/PageDataClass.kt @@ -1,4 +1,4 @@ -package ir.armor.tachidesk.database.dataclass +package ir.armor.tachidesk.model.dataclass /* * Copyright (C) Contributors to the Suwayomi project diff --git a/server/src/main/kotlin/ir/armor/tachidesk/database/dataclass/SourceDataClass.kt b/server/src/main/kotlin/ir/armor/tachidesk/model/dataclass/SourceDataClass.kt similarity index 90% rename from server/src/main/kotlin/ir/armor/tachidesk/database/dataclass/SourceDataClass.kt rename to server/src/main/kotlin/ir/armor/tachidesk/model/dataclass/SourceDataClass.kt index 2d6990a..6e22584 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/database/dataclass/SourceDataClass.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/model/dataclass/SourceDataClass.kt @@ -1,4 +1,4 @@ -package ir.armor.tachidesk.database.dataclass +package ir.armor.tachidesk.model.dataclass /* * Copyright (C) Contributors to the Suwayomi project diff --git a/server/src/main/kotlin/ir/armor/tachidesk/server/JavalinSetup.kt b/server/src/main/kotlin/ir/armor/tachidesk/server/JavalinSetup.kt index 3036195..0e77ad2 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/server/JavalinSetup.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/server/JavalinSetup.kt @@ -19,7 +19,7 @@ import ir.armor.tachidesk.impl.getPageImage import ir.armor.tachidesk.impl.getSource import ir.armor.tachidesk.impl.getSourceList import ir.armor.tachidesk.impl.getThumbnail -import ir.armor.tachidesk.impl.installAPK +import ir.armor.tachidesk.impl.installExtension import ir.armor.tachidesk.impl.removeCategory import ir.armor.tachidesk.impl.removeExtension import ir.armor.tachidesk.impl.removeMangaFromCategory @@ -29,6 +29,7 @@ import ir.armor.tachidesk.impl.sourceFilters import ir.armor.tachidesk.impl.sourceGlobalSearch import ir.armor.tachidesk.impl.sourceSearch import ir.armor.tachidesk.impl.updateCategory +import ir.armor.tachidesk.impl.updateExtension import ir.armor.tachidesk.server.util.openInBrowser import mu.KotlinLogging @@ -69,18 +70,26 @@ fun javalinSetup() { ctx.json(getExtensionList()) } - app.get("/api/v1/extension/install/:apkName") { ctx -> - val apkName = ctx.pathParam("apkName") + app.get("/api/v1/extension/install/:pkgName") { ctx -> + val pkgName = ctx.pathParam("pkgName") ctx.status( - installAPK(apkName) + installExtension(pkgName) ) } - app.get("/api/v1/extension/uninstall/:apkName") { ctx -> - val apkName = ctx.pathParam("apkName") + app.get("/api/v1/extension/update/:pkgName") { ctx -> + val pkgName = ctx.pathParam("pkgName") - removeExtension(apkName) + ctx.status( + updateExtension(pkgName) + ) + } + + app.get("/api/v1/extension/uninstall/:pkgName") { ctx -> + val pkgName = ctx.pathParam("pkgName") + + removeExtension(pkgName) ctx.status(200) } diff --git a/server/src/main/kotlin/ir/armor/tachidesk/server/ServerSetup.kt b/server/src/main/kotlin/ir/armor/tachidesk/server/ServerSetup.kt index 59dab32..8cf173c 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/server/ServerSetup.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/server/ServerSetup.kt @@ -10,7 +10,7 @@ package ir.armor.tachidesk.server import ch.qos.logback.classic.Level import eu.kanade.tachiyomi.App import ir.armor.tachidesk.Main -import ir.armor.tachidesk.database.makeDataBaseTables +import ir.armor.tachidesk.model.dataclass.makeDataBaseTables import ir.armor.tachidesk.server.util.systemTray import mu.KotlinLogging import net.harawata.appdirs.AppDirsFactory @@ -40,7 +40,7 @@ val androidCompat by lazy { AndroidCompat() } fun applicationSetup() { // register server config GlobalConfigManager.registerModule( - ServerConfig.register(GlobalConfigManager.config) + ServerConfig.register(GlobalConfigManager.config) ) // set application wide logging level @@ -50,10 +50,10 @@ fun applicationSetup() { // make dirs we need listOf( - applicationDirs.dataRoot, - applicationDirs.extensionsRoot, - "${applicationDirs.extensionsRoot}/icon", - applicationDirs.thumbnailsRoot + applicationDirs.dataRoot, + applicationDirs.extensionsRoot, + "${applicationDirs.extensionsRoot}/icon", + applicationDirs.thumbnailsRoot ).forEach { File(it).mkdirs() } @@ -99,5 +99,6 @@ fun applicationSetup() { System.getProperties()["proxySet"] = "true" System.getProperties()["socksProxyHost"] = serverConfig.socksProxyHost System.getProperties()["socksProxyPort"] = serverConfig.socksProxyPort + logger.info("Socks Proxy is enabled to ${serverConfig.socksProxyHost}:${serverConfig.socksProxyPort}") } } diff --git a/webUI/react/src/components/ExtensionCard.tsx b/webUI/react/src/components/ExtensionCard.tsx index e44afa0..5ff5b4c 100644 --- a/webUI/react/src/components/ExtensionCard.tsx +++ b/webUI/react/src/components/ExtensionCard.tsx @@ -49,7 +49,7 @@ interface IProps { export default function ExtensionCard(props: IProps) { const { extension: { - name, lang, versionName, installed, apkName, iconUrl, + name, lang, versionName, installed, pkgName, iconUrl, }, notifyInstall, } = props; @@ -62,7 +62,7 @@ export default function ExtensionCard(props: IProps) { function install() { setInstalledState('installing'); - client.get(`/api/v1/extension/install/${apkName}`) + client.get(`/api/v1/extension/install/${pkgName}`) .then(() => { setInstalledState('uninstall'); notifyInstall(); @@ -71,7 +71,7 @@ export default function ExtensionCard(props: IProps) { function uninstall() { setInstalledState('uninstalling'); - client.get(`/api/v1/extension/uninstall/${apkName}`) + client.get(`/api/v1/extension/uninstall/${pkgName}`) .then(() => { // setInstalledState('install'); notifyInstall(); diff --git a/webUI/react/src/typings.d.ts b/webUI/react/src/typings.d.ts index 018165c..80725e8 100644 --- a/webUI/react/src/typings.d.ts +++ b/webUI/react/src/typings.d.ts @@ -7,12 +7,16 @@ interface IExtension { name: string - lang: string - versionName: string - iconUrl: string - installed: boolean - apkName: string pkgName: string + versionName: string + versionCode: number + lang: string + isNsfw: boolean + apkName: string + iconUrl: string + isInstalled: boolean + hasUpdate: boolean + isObsolete: boolean } interface ISource {