From 3f1137cba5ff1acadf5304024663ea6b12eb0db0 Mon Sep 17 00:00:00 2001 From: stevenyomi <95685115+stevenyomi@users.noreply.github.com> Date: Fri, 21 Apr 2023 20:27:24 +0800 Subject: [PATCH] Zerobyw: update domain URL source (#16119) --- src/zh/zerobyw/build.gradle | 3 +-- .../extension/zh/zerobyw/UpdateUrl.kt | 26 +++++-------------- .../tachiyomi/extension/zh/zerobyw/Zerobyw.kt | 1 + 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/src/zh/zerobyw/build.gradle b/src/zh/zerobyw/build.gradle index 1d5a3518a..325437edb 100644 --- a/src/zh/zerobyw/build.gradle +++ b/src/zh/zerobyw/build.gradle @@ -1,12 +1,11 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' -apply plugin: 'kotlinx-serialization' ext { extName = 'Zerobyw' pkgNameSuffix = 'zh.zerobyw' extClass = '.Zerobyw' - extVersionCode = 14 + extVersionCode = 15 } apply from: "$rootDir/common.gradle" diff --git a/src/zh/zerobyw/src/eu/kanade/tachiyomi/extension/zh/zerobyw/UpdateUrl.kt b/src/zh/zerobyw/src/eu/kanade/tachiyomi/extension/zh/zerobyw/UpdateUrl.kt index ef83f0e25..4fc438d99 100644 --- a/src/zh/zerobyw/src/eu/kanade/tachiyomi/extension/zh/zerobyw/UpdateUrl.kt +++ b/src/zh/zerobyw/src/eu/kanade/tachiyomi/extension/zh/zerobyw/UpdateUrl.kt @@ -5,8 +5,6 @@ import android.content.SharedPreferences import android.widget.Toast import androidx.preference.EditTextPreference import eu.kanade.tachiyomi.network.GET -import kotlinx.serialization.decodeFromString -import kotlinx.serialization.json.Json import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.Interceptor import okhttp3.OkHttpClient @@ -17,7 +15,7 @@ private const val DEFAULT_BASE_URL = "http://www.zerobyw4090.com" private const val BASE_URL_PREF = "ZEROBYW_BASEURL" private const val DEFAULT_BASE_URL_PREF = "defaultBaseUrl" -private const val JSON_URL = "https://cdn.jsdelivr.net/gh/zerozzz123456/1/url.json" +private const val LATEST_DOMAIN_URL = "https://stevenyomi.github.io/source-domains/zerobyw.txt" var SharedPreferences.baseUrl: String get() = getString(BASE_URL_PREF, DEFAULT_BASE_URL)!! @@ -36,7 +34,7 @@ fun getBaseUrlPreference(context: Context) = EditTextPreference(context).apply { key = BASE_URL_PREF title = "网址" summary = "正常情况下会自动更新。" + - "如果出现错误,请在 GitHub 上报告,并且可以在 $JSON_URL 找到最新网址手动填写。" + + "如果出现错误,请在 GitHub 上报告,并且可以在 GitHub 仓库 zerozzz123456/1 找到最新网址手动填写。" + "填写时按照 $DEFAULT_BASE_URL 格式。" setDefaultValue(DEFAULT_BASE_URL) @@ -52,25 +50,16 @@ fun getBaseUrlPreference(context: Context) = EditTextPreference(context).apply { } fun ciGetUrl(client: OkHttpClient): String { - println("[Zerobyw] CI detected, getting latest URL...") return try { - val response = client.newCall(GET(JSON_URL)).execute() - parseJson(response).also { println("[Zerobyw] Latest URL is $it") } + val response = client.newCall(GET(LATEST_DOMAIN_URL)).execute() + response.body.string() } catch (e: Throwable) { - println("[Zerobyw] Failed to fetch latest URL") + println("::error ::Zerobyw: Failed to fetch latest URL") e.printStackTrace() DEFAULT_BASE_URL } } -private fun parseJson(response: Response): String { - val string = response.body.string() - val json: HashMap = Json.decodeFromString(string) - val newUrl = json["url"]!!.trim() - checkBaseUrl(newUrl) - return newUrl -} - private fun checkBaseUrl(url: String) { require(url == url.trim() && !url.endsWith('/')) val pathSegments = url.toHttpUrl().pathSegments @@ -97,11 +86,10 @@ class UpdateUrlInterceptor( } val newUrl = try { - val response = chain.proceed(GET(JSON_URL)) - val newUrl = parseJson(response) + val newUrl = chain.proceed(GET(LATEST_DOMAIN_URL)).body.string() require(newUrl != baseUrl) newUrl - } catch (e: Throwable) { + } catch (_: Throwable) { return failedResult.getOrThrow() } diff --git a/src/zh/zerobyw/src/eu/kanade/tachiyomi/extension/zh/zerobyw/Zerobyw.kt b/src/zh/zerobyw/src/eu/kanade/tachiyomi/extension/zh/zerobyw/Zerobyw.kt index 5b832d6ab..d9b41c6f4 100644 --- a/src/zh/zerobyw/src/eu/kanade/tachiyomi/extension/zh/zerobyw/Zerobyw.kt +++ b/src/zh/zerobyw/src/eu/kanade/tachiyomi/extension/zh/zerobyw/Zerobyw.kt @@ -25,6 +25,7 @@ class Zerobyw : ParsedHttpSource(), ConfigurableSource { override val supportsLatest: Boolean get() = false private val preferences: SharedPreferences = Injekt.get().getSharedPreferences("source_$id", 0x0000) + .clearOldBaseUrl() override val client = network.cloudflareClient.newBuilder() .addInterceptor(UpdateUrlInterceptor(preferences))