最新版查询改走 API:这台 Gitea 没有 latest/download 路由

/releases/latest/download/<asset> 实测 404,只有带具体 tag 的
下载路径可用。版本号从 /api/v1/.../releases/latest 拿,
version.txt 因此不再需要单独作为 asset 上传。
This commit is contained in:
2026-08-12 15:57:45 +08:00
parent fbb2a824dc
commit 5c924db235
2 changed files with 15 additions and 20 deletions
+12 -12
View File
@@ -21,6 +21,7 @@ set -Eeuo pipefail
SELF_VERSION="1.0.0"
REPO_URL="https://git.im0o.top/im0o/mihomo-patchbay"
API_URL="https://git.im0o.top/api/v1/repos/im0o/mihomo-patchbay"
# bun 版本钉死,避免运行时行为漂移;和 .gitea/workflows/release.yml 的构建版本一起改
BUN_VERSION="${PATCHBAY_BUN_VERSION:-1.3.14}"
@@ -108,12 +109,10 @@ gh_url() { # gh_url "owner/repo/releases/..." -> 完整
printf '%s' "$u"
}
release_url() { # release_url <asset> -> Gitea Release 下载地址
if [[ -n "$WANT_VERSION" ]]; then
printf '%s/releases/download/%s/%s' "$REPO_URL" "$WANT_VERSION" "$1"
else
printf '%s/releases/latest/download/%s' "$REPO_URL" "$1"
fi
# 这台 Gitea 的网页路由没有 /releases/latest/download/<asset> 这种别名(实测 404),
# 所以下载地址必须带具体版本号,「最新」由 latest_version 先问 API
release_url() { # release_url <版本> <asset> -> 下载地址
printf '%s/releases/download/%s/%s' "$REPO_URL" "$1" "$2"
}
# 读 config.yaml 顶层的简单键(形如 `secret: "xxx"`),套路取自 mihomo-up.sh 的 cfg_get
@@ -129,11 +128,12 @@ installed_version() {
}
latest_version() {
local v
v="$(curl -fsSL --retry 2 --connect-timeout 5 --max-time 15 "$(release_url version.txt)" \
| tr -d '[:space:]')" \
|| die "拉取版本号失败: $(release_url version.txt)(仓库还没发布过 Release?网络不通?)"
[[ "$v" =~ ^v[0-9]+\.[0-9]+ ]] || die "拿到的版本号格式不对: $v"
local resp v
resp="$(curl -fsSL --retry 2 --connect-timeout 5 --max-time 15 "$API_URL/releases/latest")" \
|| die "查询最新 Release 失败: $API_URL/releases/latest(还没发布过 Release?网络不通?)"
# 响应里 tag_name 只出现一次(release 对象自己的),不装 jq 也能取
v="$(printf '%s' "$resp" | grep -o '"tag_name":"[^"]*"' | head -n1 | cut -d'"' -f4)"
[[ "$v" =~ ^v[0-9]+\.[0-9]+ ]] || die "拿到的版本号格式不对: ${v:-空}"
printf '%s' "$v"
}
@@ -181,7 +181,7 @@ install_bun() {
# ───────────────────────── 应用本体 ─────────────────────────
install_app() { # $1 = 目标版本
local target="$1" url
url="$(release_url patchbay.tar.gz)"
url="$(release_url "$target" patchbay.tar.gz)"
info "下载 patchbay.tar.gz"
curl -fL -# --retry 3 --connect-timeout 15 --max-time 300 -o "$TMPDIR_/app.tar.gz" "$url" \