MangaDex: Block Uploaders (#10433)

* Add uploader block to Dex extension

* Sort the list to aid Varnish Caching

"For sake of caching, sort User configurable input query params.
Varnish caching cannot know that it's a list that's safe to re-sort etc.
Use like alphabetical UUID sorting"

* Bump MangaDex.extVersionCode
This commit is contained in:
nicki 2022-01-12 23:32:04 +05:30 committed by GitHub
parent 0ce1eee2d5
commit b38bcd4f0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 3 deletions

View File

@ -6,7 +6,7 @@ ext {
extName = 'MangaDex'
pkgNameSuffix = 'all.mangadex'
extClass = '.MangaDexFactory'
extVersionCode = 150
extVersionCode = 151
isNsfw = true
}

View File

@ -90,4 +90,9 @@ object MDConstants {
fun getBlockedGroupsPrefKey(dexLang: String): String {
return "${blockedGroupsPref}_$dexLang"
}
private const val blockedUploaderPref = "blockedUploader"
fun getBlockedUploaderPrefKey(dexLang: String): String {
return "${blockedUploaderPref}_$dexLang"
}
}

View File

@ -177,7 +177,11 @@ abstract class MangaDex(override val lang: String, val dexLang: String) :
preferences.getString(
MDConstants.getBlockedGroupsPrefKey(dexLang),
MDConstants.blockedGroupsPrefDefaults
)?.split(",")?.forEach { if (it.isNotEmpty()) addQueryParameter("excludedGroups[]", it.trim()) }
)?.split(",")?.sorted()?.forEach { if (it.isNotEmpty()) addQueryParameter("excludedGroups[]", it.trim()) }
preferences.getString(
MDConstants.getBlockedUploaderPrefKey(dexLang),
""
)?.split(", ")?.sorted()?.forEach { if (it.isNotEmpty()) addQueryParameter("excludedUploaders[]", it.trim()) }
}.build().toString()
return GET(url, headers, CacheControl.FORCE_NETWORK)
}
@ -333,7 +337,11 @@ abstract class MangaDex(override val lang: String, val dexLang: String) :
preferences.getString(
MDConstants.getBlockedGroupsPrefKey(dexLang),
MDConstants.blockedGroupsPrefDefaults
)?.split(",")?.forEach { if (it.isNotEmpty()) addQueryParameter("excludedGroups[]", it.trim()) }
)?.split(",")?.sorted()?.forEach { if (it.isNotEmpty()) addQueryParameter("excludedGroups[]", it.trim()) }
preferences.getString(
MDConstants.getBlockedUploaderPrefKey(dexLang),
""
)?.split(",")?.sorted()?.forEach { if (it.isNotEmpty()) addQueryParameter("excludedUploaders[]", it.trim()) }
}.build().toString()
return GET(url, headers = headers, cache = CacheControl.FORCE_NETWORK)
}
@ -529,12 +537,31 @@ abstract class MangaDex(override val lang: String, val dexLang: String) :
}
}
val blockedUploaderPref = EditTextPreference(screen.context).apply {
key = MDConstants.getBlockedUploaderPrefKey(dexLang)
title = "Block Uploader by UUID"
summary = "Chapters from blocked users will not show up in Latest or Manga feed.\n" +
"Enter as a Comma-separated list of uploader UUIDs"
setOnPreferenceChangeListener { _, newValue ->
val uploaderBlocked = newValue.toString()
.split(",")
.map { it.trim() }
.filter { helper.containsUuid(it) }
.joinToString(separator = ", ")
preferences.edit()
.putString(MDConstants.getBlockedUploaderPrefKey(dexLang), uploaderBlocked)
.commit()
}
}
screen.addPreference(coverQualityPref)
screen.addPreference(dataSaverPref)
screen.addPreference(standardHttpsPortPref)
screen.addPreference(contentRatingPref)
screen.addPreference(originalLanguagePref)
screen.addPreference(blockedGroupsPref)
screen.addPreference(blockedUploaderPref)
}
override fun getFilterList(): FilterList =