feat(widget): 优化访客在线轨迹、GeoIP与多站点渠道
CI / Frontend (typecheck + lint + build) (push) Successful in 2m5s
CI / Backend (go vet + test) (push) Failing after 5m20s

This commit is contained in:
yml2213
2026-11-06 18:21:30 +08:00
parent 24fac1bcf1
commit 38d6fc1684
37 changed files with 1071 additions and 123 deletions
+30
View File
@@ -97,6 +97,35 @@ check_http_port() {
fi
}
ensure_geoip() {
local db_file="${GEOIP_DB_FILE:-deploy/geoip/GeoLite2-City.mmdb}"
local db_url="${GEOIP_DB_URL:-https://raw.githubusercontent.com/P3TERX/GeoLite.mmdb/download/GeoLite2-City.mmdb}"
local refresh=0
if [[ ! -s "$db_file" ]] || [[ "$(wc -c < "$db_file" | tr -d ' ')" -lt 1000000 ]] \
|| ! tail -c 131072 "$db_file" | grep -aq 'MaxMind.com'; then
refresh=1
elif find "$db_file" -mtime +30 -print -quit 2>/dev/null | grep -q .; then
refresh=1
fi
[[ "$refresh" -eq 0 ]] && return 0
need_cmd curl
mkdir -p "$(dirname "$db_file")"
local tmp="${db_file}.download.$$"
log "下载 GeoIP 城市库: $db_url"
rm -f "$tmp"
if curl -fL --retry 3 --connect-timeout 15 --max-time 300 -o "$tmp" "$db_url" \
&& [[ "$(wc -c < "$tmp" | tr -d ' ')" -gt 1000000 ]] \
&& tail -c 131072 "$tmp" | grep -aq 'MaxMind.com'; then
mv "$tmp" "$db_file"
log "GeoIP 数据库已更新: $db_file"
else
rm -f "$tmp"
warn "GeoIP 自动下载失败,服务将降级为 CDN 国家头/未知地区"
fi
}
ensure_env() {
if [[ ! -f "$ENV_FILE" ]]; then
if [[ ! -f "$ENV_EXAMPLE" ]]; then
@@ -227,6 +256,7 @@ cmd_up() {
fi
ensure_env
ensure_geoip
log "拉取基础镜像…"
compose pull postgres minio minio-init || true