6Manhua: balance load by random mirror on setup (#14551)
This commit is contained in:
parent
62d5ec3721
commit
792468f338
|
@ -6,7 +6,7 @@ ext {
|
||||||
extName = '6Manhua / Qixi Manhua'
|
extName = '6Manhua / Qixi Manhua'
|
||||||
pkgNameSuffix = 'zh.sixmh'
|
pkgNameSuffix = 'zh.sixmh'
|
||||||
extClass = '.SixMH'
|
extClass = '.SixMH'
|
||||||
extVersionCode = 5
|
extVersionCode = 6
|
||||||
}
|
}
|
||||||
|
|
||||||
apply from: "$rootDir/common.gradle"
|
apply from: "$rootDir/common.gradle"
|
||||||
|
|
|
@ -30,6 +30,7 @@ import uy.kohesive.injekt.api.get
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
import kotlin.random.Random
|
||||||
|
|
||||||
class SixMH : HttpSource(), ConfigurableSource {
|
class SixMH : HttpSource(), ConfigurableSource {
|
||||||
override val name = "6漫画"
|
override val name = "6漫画"
|
||||||
|
@ -43,7 +44,11 @@ class SixMH : HttpSource(), ConfigurableSource {
|
||||||
init {
|
init {
|
||||||
val preferences = Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
val preferences = Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
||||||
val mirrors = MIRRORS
|
val mirrors = MIRRORS
|
||||||
val index = preferences.getString(MIRROR_PREF, "0")!!.toInt().coerceAtMost(mirrors.size - 1)
|
var index = preferences.getString(MIRROR_PREF, "-1")!!.toInt()
|
||||||
|
if (index !in mirrors.indices) {
|
||||||
|
index = Random.nextInt(0, mirrors.size)
|
||||||
|
preferences.edit().putString(MIRROR_PREF, index.toString()).apply()
|
||||||
|
}
|
||||||
val domain = mirrors[index]
|
val domain = mirrors[index]
|
||||||
|
|
||||||
mirrorIndex = index
|
mirrorIndex = index
|
||||||
|
|
Loading…
Reference in New Issue