From abecd7d9f1b50fc5a01ea826d9b3154c2e842a88 Mon Sep 17 00:00:00 2001 From: Meow <197331664+Meo597@users.noreply.github.com> Date: Fri, 6 Nov 2026 11:08:09 +0800 Subject: [PATCH] Geodata: Download `.dat.gz` when the URL belongs to XTLS/Xray-rules-dat (#7334) https://github.com/XTLS/Xray-core/pull/7185#issuecomment-6633801536 https://github.com/XTLS/Xray-core/pull/7334#issuecomment-6643558279 https://github.com/XTLS/Xray-core/pull/4809#issuecomment-6510221797 --------- Co-authored-by: RPRX <63339210+RPRX@users.noreply.github.com> --- .github/docker/Dockerfile | 4 ++-- .github/docker/Dockerfile.usa | 4 ++-- infra/conf/geodata.go | 12 +++++++++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.github/docker/Dockerfile b/.github/docker/Dockerfile index 781bc9ce6..eca57c58f 100644 --- a/.github/docker/Dockerfile +++ b/.github/docker/Dockerfile @@ -9,8 +9,8 @@ ARG TARGETARCH RUN GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 go build -o xray -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags "-s -w -buildid=" ./main # Download geodat into a staging directory -ADD https://raw.githubusercontent.com/XTLS/Xray-rules-dat/release/geoip/geoip-full.dat /tmp/geodat/geoip.dat -ADD https://raw.githubusercontent.com/XTLS/Xray-rules-dat/release/geosite/geosite-expand.dat /tmp/geodat/geosite.dat +ADD https://github.com/XTLS/Xray-rules-dat/releases/latest/download/geoip-full.dat /tmp/geodat/geoip.dat +ADD https://github.com/XTLS/Xray-rules-dat/releases/latest/download/geosite-expand.dat /tmp/geodat/geosite.dat RUN mkdir -p /tmp/empty diff --git a/.github/docker/Dockerfile.usa b/.github/docker/Dockerfile.usa index 05ed0cbab..31fe813bd 100644 --- a/.github/docker/Dockerfile.usa +++ b/.github/docker/Dockerfile.usa @@ -9,8 +9,8 @@ ARG TARGETARCH RUN GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 go build -o xray -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags "-s -w -buildid=" ./main # Download geodat into a staging directory -ADD https://raw.githubusercontent.com/XTLS/Xray-rules-dat/release/geoip/geoip-full.dat /tmp/geodat/geoip.dat -ADD https://raw.githubusercontent.com/XTLS/Xray-rules-dat/release/geosite/geosite-expand.dat /tmp/geodat/geosite.dat +ADD https://github.com/XTLS/Xray-rules-dat/releases/latest/download/geoip-full.dat /tmp/geodat/geoip.dat +ADD https://github.com/XTLS/Xray-rules-dat/releases/latest/download/geosite-expand.dat /tmp/geodat/geosite.dat RUN mkdir -p /tmp/empty diff --git a/infra/conf/geodata.go b/infra/conf/geodata.go index 20e7520a2..7cd2a5e0f 100644 --- a/infra/conf/geodata.go +++ b/infra/conf/geodata.go @@ -2,6 +2,7 @@ package conf import ( "net/url" + "strings" "github.com/robfig/cron/v3" "github.com/xtls/xray-core/app/geodata" @@ -19,11 +20,20 @@ func (c *GeodataAssetConfig) Build() (*geodata.Asset, error) { return nil, errors.New("invalid geodata asset url: ", c.URL).Base(err) } return &geodata.Asset{ - Url: c.URL, + Url: migrateGeodataURL(c.URL), File: c.File, }, nil } +func migrateGeodataURL(assetURL string) string { + if strings.HasSuffix(strings.ToLower(assetURL), ".dat") && (strings.HasPrefix(strings.ToLower(assetURL), "https://github.com/xtls/xray-rules-dat/") || + strings.HasPrefix(strings.ToLower(assetURL), "https://raw.githubusercontent.com/xtls/xray-rules-dat/")) { + errors.PrintDeprecatedFeatureWarning(assetURL, assetURL+".gz") + return assetURL + ".gz" + } + return assetURL +} + func validateHTTPS(s string) error { u, err := url.ParseRequestURI(s) if err != nil {