diff --git a/server/src/main/kotlin/suwayomi/tachidesk/InspectorMain.kt b/server/src/main/kotlin/suwayomi/tachidesk/InspectorMain.kt deleted file mode 100644 index 9ff633f..0000000 --- a/server/src/main/kotlin/suwayomi/tachidesk/InspectorMain.kt +++ /dev/null @@ -1,64 +0,0 @@ -package suwayomi.tachidesk - -/* - * 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 eu.kanade.tachiyomi.source.online.HttpSource -import kotlinx.serialization.Serializable -import kotlinx.serialization.encodeToString -import kotlinx.serialization.json.Json -import mu.KotlinLogging -import suwayomi.tachidesk.manga.impl.extension.Extension.installAPK -import java.io.File -import java.nio.file.Files -import java.nio.file.Paths -import kotlin.io.path.extension -import kotlin.streams.toList - -object InspectorMain { - - private val logger = KotlinLogging.logger {} - - suspend fun inspectorMain(args: Array) { - if (args.size < 3) { - throw RuntimeException("Inspector must be given the path of apks directory, output json, and a tmp dir") - } - - val apksPath = args[0] - val outputPath = args[1] - val tmpDirPath = args[2] - - val tmpDir = File(tmpDirPath, "tmp").also { it.mkdir() } - val extensions = Files.find(Paths.get(apksPath), 2, { _, fileAttributes -> fileAttributes.isRegularFile }) - .filter { it.extension == "apk" } - .toList() - .map { - logger.info("Installing $it") - val (pkgName, sources) = installAPK(tmpDir) { it.toFile() } - pkgName to sources.map { source -> SourceJson(source) } - } - .toMap() - - File(outputPath).writeText(Json.encodeToString(extensions)) - } - - @Serializable - data class SourceJson( - val name: String, - val lang: String, - val id: String, - val baseUrl: String - ) { - constructor(source: HttpSource) : - this( - source.name, - source.lang, - source.id.toString(), - source.baseUrl - ) - } -} diff --git a/server/src/main/kotlin/suwayomi/tachidesk/Main.kt b/server/src/main/kotlin/suwayomi/tachidesk/Main.kt index 16f8295..5c537d7 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/Main.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/Main.kt @@ -2,15 +2,66 @@ package suwayomi.tachidesk /* * 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/. */ + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ -import suwayomi.tachidesk.InspectorMain.inspectorMain +import eu.kanade.tachiyomi.source.online.HttpSource +import kotlinx.serialization.Serializable +import kotlinx.serialization.encodeToString +import kotlinx.serialization.json.Json +import mu.KotlinLogging +import suwayomi.tachidesk.manga.impl.extension.Extension import suwayomi.tachidesk.server.applicationSetup +import java.io.File +import java.nio.file.Files +import java.nio.file.Paths +import kotlin.io.path.extension +import kotlin.streams.toList + +private val logger = KotlinLogging.logger {} suspend fun main(args: Array) { + if (args.size < 3) { + throw RuntimeException("Inspector must be given the path of apks directory, output json, and a tmp dir") + } + applicationSetup() - inspectorMain(args) + + val (apksPath, outputPath, tmpDirPath) = args + + val tmpDir = File(tmpDirPath, "tmp").also { it.mkdir() } + val extensions = Files.find(Paths.get(apksPath), 2, { _, fileAttributes -> fileAttributes.isRegularFile }) + .filter { it.extension == "apk" } + .toList() + + logger.info("Found ${extensions.size} extensions") + + val extensionsInfo = extensions + .map { + logger.debug("Installing $it") + val (pkgName, sources) = Extension.installAPK(tmpDir) { it.toFile() } + pkgName to sources.map { source -> SourceJson(source) } + } + .toMap() + + File(outputPath).writeText(Json.encodeToString(extensionsInfo)) +} + +@Serializable +data class SourceJson( + val name: String, + val lang: String, + val id: String, + val baseUrl: String +) { + constructor(source: HttpSource) : + this( + source.name, + source.lang, + source.id.toString(), + source.baseUrl + ) } diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/extension/Extension.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/extension/Extension.kt index b4ab321..106a62d 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/extension/Extension.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/extension/Extension.kt @@ -43,15 +43,6 @@ object Extension { ) } - /*val signatureHash = getSignatureHash(packageInfo) - - if (signatureHash == null) { - throw Exception("Package $pkgName isn't signed") - } else if (signatureHash !in trustedSignatures) { - // TODO: allow trusting keys - throw Exception("This apk is not a signed with the official tachiyomi signature") - }*/ - val className = packageInfo.packageName + packageInfo.applicationInfo.metaData.getString(METADATA_SOURCE_CLASS) logger.trace("Main class for extension is $className") diff --git a/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt b/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt index 94ba921..12a05c4 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt @@ -5,7 +5,8 @@ package suwayomi.tachidesk.server * * 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/. */ + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ import eu.kanade.tachiyomi.App import mu.KotlinLogging