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"
|
applicationId = "com.a2i.forwarder"
|
||||||
minSdk = 34
|
minSdk = 34
|
||||||
targetSdk = 36
|
targetSdk = 36
|
||||||
versionCode = 17
|
versionCode = 18
|
||||||
versionName = "1.8.0"
|
versionName = "1.8.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
signingConfigs {
|
signingConfigs {
|
||||||
|
|||||||
@@ -68,9 +68,14 @@ class UpdateChecker(private val context: Context) {
|
|||||||
val now = System.currentTimeMillis()
|
val now = System.currentTimeMillis()
|
||||||
if (throttle && now - settings.lastUpdateCheckTime.value < CHECK_INTERVAL_MS) return@runCatching updateInfo.value
|
if (throttle && now - settings.lastUpdateCheckTime.value < CHECK_INTERVAL_MS) return@runCatching updateInfo.value
|
||||||
|
|
||||||
// 双源查询(Gitea 国内优先 + GitHub 备用),任一不通跳过,取最高版本
|
// 先查 GitHub(公开默认源),从其 release notes 动态发现额外源(如自建 Gitea),取最高版本
|
||||||
val infos = RELEASES_APIS.mapNotNull { api ->
|
val infos = mutableListOf<UpdateInfo>()
|
||||||
runCatching { fetchRelease(api) }.getOrNull()
|
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)
|
settings.setLastUpdateCheck(now)
|
||||||
if (infos.isEmpty()) {
|
if (infos.isEmpty()) {
|
||||||
@@ -245,12 +250,12 @@ class UpdateChecker(private val context: Context) {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 从 release notes 的 HTML 注释里解析额外更新源(如自建 Gitea)。 */
|
||||||
|
private fun parseUpdateSource(body: String): String? =
|
||||||
|
Regex("""update-source:\s*(\S+)""").find(body)?.groupValues?.getOrNull(1)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
// 双源:Gitea(国内优先)+ GitHub(备用),任一不通跳过,取最高版本
|
const val GITHUB_API = "https://api.github.com/repos/lsxf/a2i/releases/latest"
|
||||||
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 CHECK_INTERVAL_MS = 24L * 60 * 60 * 1000
|
const val CHECK_INTERVAL_MS = 24L * 60 * 60 * 1000
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user