feat(update): 发行 tag 查询支持 XUI_RELEASE_LATEST_URL 覆盖(镜像/沙箱冒充发行源)
This commit is contained in:
@@ -53,12 +53,24 @@ func AssetName(goarch string) (string, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LatestReleaseURLEnv overrides the release-lookup endpoint as a whole
|
||||||
|
// (mirrors, tests), analogous to BaseURLEnv.
|
||||||
|
const LatestReleaseURLEnv = "XUI_RELEASE_LATEST_URL"
|
||||||
|
|
||||||
|
// LatestReleaseURL returns the effective release-lookup endpoint.
|
||||||
|
func LatestReleaseURL() string {
|
||||||
|
if v := strings.TrimSpace(os.Getenv(LatestReleaseURLEnv)); v != "" {
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
return LatestReleaseAPI
|
||||||
|
}
|
||||||
|
|
||||||
// FetchLatestReleaseTag returns the tag_name of the newest release.
|
// FetchLatestReleaseTag returns the tag_name of the newest release.
|
||||||
func FetchLatestReleaseTag(ctx context.Context, client *http.Client) (string, error) {
|
func FetchLatestReleaseTag(ctx context.Context, client *http.Client) (string, error) {
|
||||||
if client == nil {
|
if client == nil {
|
||||||
client = http.DefaultClient
|
client = http.DefaultClient
|
||||||
}
|
}
|
||||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, LatestReleaseAPI, nil)
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, LatestReleaseURL(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -601,7 +601,10 @@ func (s *PanelService) runNativeUpdate(runID int64) {
|
|||||||
releaseUpdateSlot()
|
releaseUpdateSlot()
|
||||||
}
|
}
|
||||||
|
|
||||||
tag, err := fetchLatestPanelVersion()
|
client := (&service.SettingService{}).NewProxiedHTTPClient(10 * time.Minute)
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||||
|
defer cancel()
|
||||||
|
tag, err := selfupdate.FetchLatestReleaseTag(ctx, client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fail("fetch latest release: %v", err)
|
fail("fetch latest release: %v", err)
|
||||||
return
|
return
|
||||||
@@ -622,9 +625,6 @@ func (s *PanelService) runNativeUpdate(runID int64) {
|
|||||||
}
|
}
|
||||||
tmp := filepath.Join(filepath.Dir(exePath), fmt.Sprintf(".x-ui-update-%d", runID))
|
tmp := filepath.Join(filepath.Dir(exePath), fmt.Sprintf(".x-ui-update-%d", runID))
|
||||||
base := selfupdate.BaseURL() + tag + "/"
|
base := selfupdate.BaseURL() + tag + "/"
|
||||||
client := (&service.SettingService{}).NewProxiedHTTPClient(10 * time.Minute)
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
|
||||||
defer cancel()
|
|
||||||
logger.Infof("panel self-update: downloading %s (%s)", tag, asset)
|
logger.Infof("panel self-update: downloading %s (%s)", tag, asset)
|
||||||
if err := selfupdate.DownloadVerified(ctx, client, base+asset, base+asset+".sha256", tmp); err != nil {
|
if err := selfupdate.DownloadVerified(ctx, client, base+asset, base+asset+".sha256", tmp); err != nil {
|
||||||
_ = os.Remove(tmp)
|
_ = os.Remove(tmp)
|
||||||
|
|||||||
Reference in New Issue
Block a user