Files
lnxgit/scripts/wsl_upload_release.sh
LnxGit f0fb316bd6 修正上传说明:git.xnhw.cc 已不再是 Cloudflare 反代
现在 DNS 解析到 64.49.47.22、响应头是 `via: 1.1 Caddy`,前置代理已经不是
Cloudflare,之前写的「免费版请求体上限 100 MB → 413」已经过时。

重新实测了两条路径:

* 公网(经 Caddy):小文件上传 201 正常;150 MB 的 APK 会在约 305 秒后
  返回 **502** —— 瓶颈在 Caddy 背后的 Gitea 处理大附件那一层,不是请求体限制。
* 内网直连 192.168.100.103:8080:151 MB 约 15 秒,稳定。

结论不变(APK 走内网直传),但原因和文案改了;README 与
scripts/wsl_upload_release.sh 的注释都同步更新。

另外记录一个踩坑:之前用 `curl --resolve` 把域名钉在旧的 Cloudflare 边缘 IP
上,在 DNS 已经切换之后就会表现为「接口返回 000 / 413」,让人误判成还在 CF。
现在直连即可,不需要 --resolve。
2026-09-23 07:55:35 +08:00

84 lines
2.9 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# 把 APK 传到 Gitea Release —— 走**内网直连**,单次整文件,不切片。
#
# 为什么不走公网域名:git.xnhw.cc 现在是 Caddy 反代(2026-09 起不再走
# Cloudflare),小文件没问题,但 150 MB 的 APK 会在约 5 分钟后返回 502 ——
# 瓶颈在 Caddy 背后的 Gitea 处理大附件那一层。内网地址
# 192.168.100.103:8080 是**同一个** Gitea 实例,没有这层问题:
# 实测 151 MB 约 15 秒。
#
# 也不要用切片上传:那会在 Release 里堆出几十个 xxx.apk.part001 同名附件。
#
# 令牌:上传/删除附件需要仓库管理员权限。管理员令牌从 scripts/push.cmd
# 里读取(那里本来就有,用于推送代码);只读令牌会返回 403。
#
# 用法:bash scripts/wsl_upload_release.sh <apk路径> [apk路径...]
set -uo pipefail
HERE="$(cd "$(dirname "$0")" && pwd)"
BASE="${GITEA_BASE:-http://192.168.100.103:8080}"
REPO="${GITEA_REPO:-l/lnxgit}"
RELEASE_ID="${RELEASE_ID:-1}"
TOKEN="${GITEA_TOKEN:-}"
if [ -z "$TOKEN" ] && [ -f "$HERE/push.cmd" ]; then
TOKEN="$(grep -oP 'set TOKEN=\K[0-9a-f]+' "$HERE/push.cmd" | head -1)"
fi
[ -n "$TOKEN" ] || { echo "没有可用令牌:设 GITEA_TOKEN 或确认 scripts/push.cmd 存在" >&2; exit 1; }
[ "$#" -ge 1 ] || { echo "用法: $0 <apk路径> [...]" >&2; exit 2; }
show_release() {
curl -s --max-time 30 -H "Authorization: token $TOKEN" \
"$BASE/api/v1/repos/$REPO/releases/$RELEASE_ID" \
| python3 -c "
import json, sys
d = json.load(sys.stdin)
assets = d.get('assets', [])
print(f\" tag={d['tag_name']} 附件 {len(assets)} 个,合计 \"
f\"{sum(a['size'] for a in assets)/1048576:.1f} MB\")
for a in assets:
print(f\" - {a['name']} ({a['size']/1048576:.1f} MB)\")
"
}
echo "=== 上传前 ==="
show_release
failed=0
for apk in "$@"; do
[ -f "$apk" ] || { echo " 跳过(不存在): $apk"; failed=$((failed+1)); continue; }
name="$(basename "$apk")"
size_mb="$(du -m "$apk" | cut -f1)"
echo
echo "=== 上传 $name(${size_mb} MB,单次整文件)==="
start=$(date +%s)
code=$(curl -s -o /tmp/lnxgit_upload.json -w '%{http_code}' \
--max-time 7200 --retry 2 --retry-delay 5 \
-X POST \
-H "Authorization: token $TOKEN" \
-F "attachment=@$apk" \
"$BASE/api/v1/repos/$REPO/releases/$RELEASE_ID/assets")
elapsed=$(( $(date +%s) - start ))
if [ "$code" = "201" ]; then
python3 -c "
import json
d = json.load(open('/tmp/lnxgit_upload.json', encoding='utf-8'))
print(f\" 完成: {d.get('name')} {d.get('size',0)/1048576:.1f} MB 用时 ${elapsed}s\")
print(f\" 下载: {d.get('browser_download_url')}\")
"
else
failed=$((failed+1))
echo " 失败 HTTP $code(用时 ${elapsed}s)"
head -c 300 /tmp/lnxgit_upload.json
echo
fi
done
echo
echo "=== 上传后 ==="
show_release
exit "$failed"