fix: discover Gitea update source from release notes (no hardcode)
Gitea URL removed from source code. UpdateChecker now only hardcodes GitHub API; the Gitea mirror URL is embedded in release notes as an HTML comment (<!-- update-source: ... -->) and discovered at runtime. Keeps self-hosted server address out of the public codebase. version 1.8.0 -> 1.8.1 (code 17 -> 18) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -13,8 +13,8 @@ android {
|
||||
applicationId = "com.a2i.forwarder"
|
||||
minSdk = 34
|
||||
targetSdk = 36
|
||||
versionCode = 17
|
||||
versionName = "1.8.0"
|
||||
versionCode = 18
|
||||
versionName = "1.8.1"
|
||||
}
|
||||
|
||||
signingConfigs {
|
||||
|
||||
@@ -68,9 +68,14 @@ class UpdateChecker(private val context: Context) {
|
||||
val now = System.currentTimeMillis()
|
||||
if (throttle && now - settings.lastUpdateCheckTime.value < CHECK_INTERVAL_MS) return@runCatching updateInfo.value
|
||||
|
||||
// 双源查询(Gitea 国内优先 + GitHub 备用),任一不通跳过,取最高版本
|
||||
val infos = RELEASES_APIS.mapNotNull { api ->
|
||||
runCatching { fetchRelease(api) }.getOrNull()
|
||||
// 先查 GitHub(公开默认源),从其 release notes 动态发现额外源(如自建 Gitea),取最高版本
|
||||
val infos = mutableListOf<UpdateInfo>()
|
||||
val gh = runCatching { fetchRelease(GITHUB_API) }.getOrNull()
|
||||
if (gh != null) {
|
||||
infos.add(gh)
|
||||
parseUpdateSource(gh.releaseNotes)?.let { src ->
|
||||
runCatching { fetchRelease(src) }.getOrNull()?.let { infos.add(it) }
|
||||
}
|
||||
}
|
||||
settings.setLastUpdateCheck(now)
|
||||
if (infos.isEmpty()) {
|
||||
@@ -245,12 +250,12 @@ class UpdateChecker(private val context: Context) {
|
||||
return false
|
||||
}
|
||||
|
||||
/** 从 release notes 的 HTML 注释里解析额外更新源(如自建 Gitea)。 */
|
||||
private fun parseUpdateSource(body: String): String? =
|
||||
Regex("""update-source:\s*(\S+)""").find(body)?.groupValues?.getOrNull(1)
|
||||
|
||||
companion object {
|
||||
// 双源:Gitea(国内优先)+ GitHub(备用),任一不通跳过,取最高版本
|
||||
val RELEASES_APIS = listOf(
|
||||
"https://UPDATE_SOURCE_HIDDEN/api/v1/repos/song/a2i/releases/latest",
|
||||
"https://api.github.com/repos/lsxf/a2i/releases/latest",
|
||||
)
|
||||
const val GITHUB_API = "https://api.github.com/repos/lsxf/a2i/releases/latest"
|
||||
const val CHECK_INTERVAL_MS = 24L * 60 * 60 * 1000
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user