From 792468f33874dd87eb287cf46a33dc0a8fa262fc Mon Sep 17 00:00:00 2001 From: stevenyomi <95685115+stevenyomi@users.noreply.github.com> Date: Fri, 16 Dec 2022 09:37:27 +0800 Subject: [PATCH] 6Manhua: balance load by random mirror on setup (#14551) --- src/zh/sixmh/build.gradle | 2 +- .../src/eu/kanade/tachiyomi/extension/zh/sixmh/SixMH.kt | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/zh/sixmh/build.gradle b/src/zh/sixmh/build.gradle index 7bfd4e41f..b3e227089 100644 --- a/src/zh/sixmh/build.gradle +++ b/src/zh/sixmh/build.gradle @@ -6,7 +6,7 @@ ext { extName = '6Manhua / Qixi Manhua' pkgNameSuffix = 'zh.sixmh' extClass = '.SixMH' - extVersionCode = 5 + extVersionCode = 6 } apply from: "$rootDir/common.gradle" diff --git a/src/zh/sixmh/src/eu/kanade/tachiyomi/extension/zh/sixmh/SixMH.kt b/src/zh/sixmh/src/eu/kanade/tachiyomi/extension/zh/sixmh/SixMH.kt index 3425a867f..96d0e0d89 100644 --- a/src/zh/sixmh/src/eu/kanade/tachiyomi/extension/zh/sixmh/SixMH.kt +++ b/src/zh/sixmh/src/eu/kanade/tachiyomi/extension/zh/sixmh/SixMH.kt @@ -30,6 +30,7 @@ import uy.kohesive.injekt.api.get import uy.kohesive.injekt.injectLazy import java.text.SimpleDateFormat import java.util.Locale +import kotlin.random.Random class SixMH : HttpSource(), ConfigurableSource { override val name = "6漫画" @@ -43,7 +44,11 @@ class SixMH : HttpSource(), ConfigurableSource { init { val preferences = Injekt.get().getSharedPreferences("source_$id", 0x0000) 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] mirrorIndex = index