mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-01 01:44:34 -05:00
add isNsfw to SourceDataClass
This commit is contained in:
@@ -12,6 +12,7 @@ import android.content.Context
|
|||||||
import androidx.preference.PreferenceScreen
|
import androidx.preference.PreferenceScreen
|
||||||
import eu.kanade.tachiyomi.source.ConfigurableSource
|
import eu.kanade.tachiyomi.source.ConfigurableSource
|
||||||
import eu.kanade.tachiyomi.source.getPreferenceKey
|
import eu.kanade.tachiyomi.source.getPreferenceKey
|
||||||
|
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||||
import mu.KotlinLogging
|
import mu.KotlinLogging
|
||||||
import org.jetbrains.exposed.sql.select
|
import org.jetbrains.exposed.sql.select
|
||||||
import org.jetbrains.exposed.sql.selectAll
|
import org.jetbrains.exposed.sql.selectAll
|
||||||
@@ -32,16 +33,25 @@ import xyz.nulldev.androidcompat.androidimpl.CustomContext
|
|||||||
object Source {
|
object Source {
|
||||||
private val logger = KotlinLogging.logger {}
|
private val logger = KotlinLogging.logger {}
|
||||||
|
|
||||||
|
val HttpSource.isNsfw: Boolean
|
||||||
|
get() = this::class.annotations.any { it.toString() == "@eu.kanade.tachiyomi.annotations.Nsfw()" }
|
||||||
|
|
||||||
fun getSourceList(): List<SourceDataClass> {
|
fun getSourceList(): List<SourceDataClass> {
|
||||||
return transaction {
|
return transaction {
|
||||||
SourceTable.selectAll().map {
|
SourceTable.selectAll().map {
|
||||||
|
val httpSource = getHttpSource(it[SourceTable.id].value)
|
||||||
|
|
||||||
SourceDataClass(
|
SourceDataClass(
|
||||||
it[SourceTable.id].value.toString(),
|
it[SourceTable.id].value.toString(),
|
||||||
it[SourceTable.name],
|
it[SourceTable.name],
|
||||||
it[SourceTable.lang],
|
it[SourceTable.lang],
|
||||||
getExtensionIconUrl(ExtensionTable.select { ExtensionTable.id eq it[SourceTable.extension] }.first()[ExtensionTable.apkName]),
|
getExtensionIconUrl(
|
||||||
getHttpSource(it[SourceTable.id].value).supportsLatest,
|
ExtensionTable.select { ExtensionTable.id eq it[SourceTable.extension] }
|
||||||
getHttpSource(it[SourceTable.id].value) is ConfigurableSource
|
.first()[ExtensionTable.apkName]
|
||||||
|
),
|
||||||
|
httpSource.supportsLatest,
|
||||||
|
httpSource is ConfigurableSource,
|
||||||
|
httpSource.isNsfw
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -50,14 +60,21 @@ object Source {
|
|||||||
fun getSource(sourceId: Long): SourceDataClass {
|
fun getSource(sourceId: Long): SourceDataClass {
|
||||||
return transaction {
|
return transaction {
|
||||||
val source = SourceTable.select { SourceTable.id eq sourceId }.firstOrNull()
|
val source = SourceTable.select { SourceTable.id eq sourceId }.firstOrNull()
|
||||||
|
val httpSource = source?.let { getHttpSource(sourceId) }
|
||||||
|
|
||||||
SourceDataClass(
|
SourceDataClass(
|
||||||
sourceId.toString(),
|
sourceId.toString(),
|
||||||
source?.get(SourceTable.name),
|
source?.get(SourceTable.name),
|
||||||
source?.get(SourceTable.lang),
|
source?.get(SourceTable.lang),
|
||||||
source?.let { getExtensionIconUrl(ExtensionTable.select { ExtensionTable.id eq source[SourceTable.extension] }.first()[ExtensionTable.apkName]) },
|
source?.let {
|
||||||
source?.let { getHttpSource(sourceId).supportsLatest },
|
getExtensionIconUrl(
|
||||||
source?.let { getHttpSource(sourceId) is ConfigurableSource },
|
ExtensionTable.select { ExtensionTable.id eq source[SourceTable.extension] }
|
||||||
|
.first()[ExtensionTable.apkName]
|
||||||
|
)
|
||||||
|
},
|
||||||
|
httpSource?.supportsLatest,
|
||||||
|
httpSource?.let { it is ConfigurableSource },
|
||||||
|
httpSource?.isNsfw
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -85,7 +102,8 @@ object Source {
|
|||||||
val source = getHttpSource(sourceId)
|
val source = getHttpSource(sourceId)
|
||||||
|
|
||||||
if (source is ConfigurableSource) {
|
if (source is ConfigurableSource) {
|
||||||
val sourceShardPreferences = Injekt.get<Application>().getSharedPreferences(source.getPreferenceKey(), Context.MODE_PRIVATE)
|
val sourceShardPreferences =
|
||||||
|
Injekt.get<Application>().getSharedPreferences(source.getPreferenceKey(), Context.MODE_PRIVATE)
|
||||||
|
|
||||||
val screen = PreferenceScreen(context)
|
val screen = PreferenceScreen(context)
|
||||||
screen.sharedPreferences = sourceShardPreferences
|
screen.sharedPreferences = sourceShardPreferences
|
||||||
|
|||||||
@@ -13,5 +13,6 @@ data class SourceDataClass(
|
|||||||
val lang: String?,
|
val lang: String?,
|
||||||
val iconUrl: String?,
|
val iconUrl: String?,
|
||||||
val supportsLatest: Boolean?,
|
val supportsLatest: Boolean?,
|
||||||
val isConfigurable: Boolean?
|
val isConfigurable: Boolean?,
|
||||||
|
val isNSFW: Boolean?,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user