Minor cleanup

This commit is contained in:
arkon 2021-11-28 18:55:52 -05:00
parent 20895f2ef6
commit 52641de2b7
4 changed files with 57 additions and 78 deletions

View File

@ -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<String>) {
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
)
}
}

View File

@ -2,15 +2,66 @@ package suwayomi.tachidesk
/* /*
* Copyright (C) Contributors to the Suwayomi project * Copyright (C) Contributors to the Suwayomi project
* *
* This Source Code Form is subject to the terms of the Mozilla Public * 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 * 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 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<String>) { suspend fun main(args: Array<String>) {
if (args.size < 3) {
throw RuntimeException("Inspector must be given the path of apks directory, output json, and a tmp dir")
}
applicationSetup() 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
)
} }

View File

@ -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) val className = packageInfo.packageName + packageInfo.applicationInfo.metaData.getString(METADATA_SOURCE_CLASS)
logger.trace("Main class for extension is $className") logger.trace("Main class for extension is $className")

View File

@ -5,7 +5,8 @@ package suwayomi.tachidesk.server
* *
* This Source Code Form is subject to the terms of the Mozilla Public * 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 * 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 eu.kanade.tachiyomi.App
import mu.KotlinLogging import mu.KotlinLogging