Remove isNsfw check (#4)

Usages were removed in 6a75de9261
This commit is contained in:
arkon 2021-10-09 15:43:35 -04:00 committed by GitHub
parent 3883b1d254
commit 2c7a6cb2b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 60 deletions

View File

@ -1,5 +0,0 @@
package eu.kanade.tachiyomi.annotations
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.CLASS)
annotation class Nsfw

View File

@ -7,11 +7,11 @@ package suwayomi.tachidesk
* 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
import suwayomi.tachidesk.manga.impl.extension.Extension.installAPK
import java.io.File
@ -47,16 +47,14 @@ object InspectorMain {
val name: String,
val lang: String,
val id: String,
val baseUrl: String,
val nsfw: Boolean
val baseUrl: String
) {
constructor(loadedSource: Extension.LoadedSource) :
constructor(source: HttpSource) :
this(
loadedSource.source.name,
loadedSource.source.lang,
loadedSource.source.id.toString(),
loadedSource.source.baseUrl,
loadedSource.isNsfw
source.name,
source.lang,
source.id.toString(),
source.baseUrl
)
}
}

View File

@ -7,7 +7,6 @@ package suwayomi.tachidesk.manga.impl.extension
* 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.annotations.Nsfw
import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.source.SourceFactory
import eu.kanade.tachiyomi.source.online.HttpSource
@ -24,22 +23,7 @@ import java.io.File
object Extension {
private val logger = KotlinLogging.logger {}
fun isNsfw(sourceInstance: Any): Boolean {
// Annotations are proxied, hence this janky way of checking for them
return sourceInstance.javaClass.annotations
.flatMap { it.javaClass.interfaces.map { it.simpleName } }
.firstOrNull { it == Nsfw::class.java.simpleName } != null
}
data class LoadedSource(
val source: HttpSource,
val isNsfw: Boolean
) {
constructor(source: HttpSource) :
this(source, isNsfw(source))
}
suspend fun installAPK(tmpDir: File, fetcher: suspend () -> File): Pair<String, List<LoadedSource>> {
suspend fun installAPK(tmpDir: File, fetcher: suspend () -> File): Pair<String, List<HttpSource>> {
val apkFile = fetcher()
val jarFile = File(tmpDir, "${apkFile.nameWithoutExtension}.jar")
@ -77,18 +61,7 @@ object Extension {
// collect sources from the extension
return packageInfo.packageName to when (val instance = loadExtensionSources(jarFile.absolutePath, className)) {
is Source -> listOf(instance).filterIsInstance<HttpSource>()
.map { LoadedSource(it) }
is SourceFactory -> {
val isNsfw = isNsfw(instance)
instance.createSources().filterIsInstance<HttpSource>()
.map {
if (isNsfw) {
LoadedSource(it, true)
} else {
LoadedSource(it)
}
}
}
is SourceFactory -> instance.createSources().filterIsInstance<HttpSource>()
else -> throw RuntimeException("Unknown source class type! ${instance.javaClass}")
}
}

View File

@ -13,7 +13,6 @@ import android.os.Bundle
import com.googlecode.d2j.dex.Dex2jar
import com.googlecode.d2j.reader.MultiDexFileReader
import com.googlecode.dex2jar.tools.BaksmaliBaseDexExceptionHandler
import eu.kanade.tachiyomi.util.lang.Hash
import mu.KotlinLogging
import net.dongliu.apk.parser.ApkFile
import net.dongliu.apk.parser.ApkParsers
@ -33,15 +32,9 @@ object PackageTools {
const val EXTENSION_FEATURE = "tachiyomi.extension"
const val METADATA_SOURCE_CLASS = "tachiyomi.extension.class"
const val METADATA_SOURCE_FACTORY = "tachiyomi.extension.factory"
const val METADATA_NSFW = "tachiyomi.extension.nsfw"
const val LIB_VERSION_MIN = 1.2
const val LIB_VERSION_MAX = 1.2
private const val officialSignature = "7ce04da7773d41b489f4693a366c36bcd0a11fc39b547168553c285bd7348e23" // inorichi's key
private const val unofficialSignature = "64feb21075ba97ebc9cc981243645b331595c111cef1b0d084236a0403b00581" // ArMor's key
var trustedSignatures = mutableSetOf<String>() + officialSignature + unofficialSignature
/**
* Convert dex to jar, a wrapper for the dex2jar library
*/
@ -120,15 +113,6 @@ object PackageTools {
}
}
fun getSignatureHash(pkgInfo: PackageInfo): String? {
val signatures = pkgInfo.signatures
return if (signatures != null && signatures.isNotEmpty()) {
Hash.sha256(signatures.first().toByteArray())
} else {
null
}
}
/**
* loads the extension main class called $className from the jar located at $jarPath
* It may return an instance of HttpSource or SourceFactory depending on the extension.