Allow disabling GitHub download mirrors (#320)

This commit is contained in:
Arvin
2026-09-24 15:19:32 +08:00
parent a83d1325d1
commit 0ed44117e6
5 changed files with 80 additions and 7 deletions
+11 -7
View File
@@ -3657,18 +3657,17 @@ doctor_dependencies() {
doctor_download_mirrors() {
doctor_print_title "下载加速配置"
local custom_prefix pool_source
local custom_prefix
custom_prefix="$(github_proxy_prefix 2>/dev/null || true)"
if [ -n "${custom_prefix:-}" ]; then
if ! github_mirror_enabled; then
doctor_ok "GitHub 镜像已禁用,直接访问 GitHub 原站"
elif [ -n "${custom_prefix:-}" ]; then
doctor_ok "自定义镜像(CLASH_GH_PROXY):${custom_prefix}"
pool_source="custom"
elif [ -n "${CLASH_GH_PROXY_POOL:-}" ]; then
doctor_ok "自定义镜像池(CLASH_GH_PROXY_POOL)已配置"
pool_source="custom-pool"
else
doctor_ok "使用内置默认镜像池(gh-proxy.org / ghfast.top / ghproxy.net / kkgithub.com)"
pool_source="default"
fi
# Show mirror history from state file
@@ -3681,8 +3680,13 @@ doctor_download_mirrors() {
[ -n "${last_fail:-}" ] && doctor_warn "上次失败镜像:${last_fail}"
fi
doctor_ok "配置提示:在 .env 中设置 CLASH_GH_PROXY=https://your-mirror.com 可指定自定义加速前缀"
doctor_ok "可用镜像列表参考:https://ghproxy.link/"
if github_mirror_enabled; then
doctor_ok "配置提示:设置 CLASH_GH_PROXY_ENABLED=false 可关闭镜像并直连 GitHub 原站"
doctor_ok "配置提示:设置 CLASH_GH_PROXY=https://your-mirror.com 可指定自定义加速前缀"
doctor_ok "可用镜像列表参考:https://ghproxy.link/"
else
doctor_ok "配置提示:设置 CLASH_GH_PROXY_ENABLED=true 可重新启用 GitHub 镜像"
fi
}
doctor_config() {
+12
View File
@@ -410,6 +410,13 @@ github_proxy_prefix() {
echo "$prefix"
}
github_mirror_enabled() {
case "${CLASH_GH_PROXY_ENABLED:-true}" in
false|0|no|off) return 1 ;;
*) return 0 ;;
esac
}
bundled_asset_enabled() {
case "${CLASH_BUNDLED_ASSET_ENABLED:-true}" in
true|1|yes|on) return 0 ;;
@@ -760,6 +767,11 @@ github_mirror_candidate_entries() {
return 0
}
if ! github_mirror_enabled; then
echo "origin||origin"
return 0
fi
if [ -n "$(github_proxy_prefix)" ]; then
entry="custom|$(github_proxy_prefix)|full"
normalized="$(normalize_github_mirror_entry "$entry" 2>/dev/null || true)"
@@ -16,6 +16,7 @@ mkdir -p "$RUNTIME_DIR"
unset CLASH_GH_PROXY
unset URL_GH_PROXY
unset CLASH_GH_PROXY_POOL
unset CLASH_GH_PROXY_ENABLED
url="https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/country.mmdb"
ordered_entries="$(
@@ -40,3 +41,43 @@ if [ "$last_label" != "origin" ]; then
fi
echo "ok - default GitHub downloads prefer mirrors before origin"
CLASH_GH_PROXY="https://mirror.example.com"
CLASH_GH_PROXY_POOL="custom|https://pool.example.com|full"
CLASH_GH_PROXY_ENABLED="false"
ordered_entries="$(
github_mirror_candidate_entries_ordered "$url" \
| sort -t'|' -k1,1nr \
| cut -d'|' -f2-
)"
if [ "$ordered_entries" != "origin||origin" ]; then
echo "not ok - disabled GitHub mirrors: expected only origin" >&2
printf '%s\n' "$ordered_entries" >&2
exit 1
fi
origin_url="$(build_github_mirror_url "$ordered_entries" "$url")"
if [ "$origin_url" != "$url" ]; then
echo "not ok - disabled GitHub mirrors: origin URL changed to $origin_url" >&2
exit 1
fi
echo "ok - disabled GitHub mirrors use only origin"
CLASH_GH_PROXY_ENABLED="true"
unset CLASH_GH_PROXY_POOL
ordered_entries="$(
github_mirror_candidate_entries_ordered "$url" \
| sort -t'|' -k1,1nr \
| cut -d'|' -f2-
)"
first_entry="$(printf '%s\n' "$ordered_entries" | head -n 1)"
if [ "$first_entry" != "custom|https://mirror.example.com|full" ]; then
echo "not ok - enabled custom GitHub mirror was not preferred" >&2
printf '%s\n' "$ordered_entries" >&2
exit 1
fi
echo "ok - enabled custom GitHub mirror remains preferred"