fix update issue

This commit is contained in:
tickstep studio team
2026-02-10 14:52:34 +08:00
parent 8b5eb14eb6
commit 1916dda8f8
2 changed files with 59 additions and 22 deletions
+19 -18
View File
@@ -17,6 +17,16 @@ import (
"archive/zip" "archive/zip"
"bytes" "bytes"
"fmt" "fmt"
"io/ioutil"
"net/http"
"path/filepath"
"regexp"
"runtime"
"strconv"
"strings"
"sync"
"time"
jsoniter "github.com/json-iterator/go" jsoniter "github.com/json-iterator/go"
"github.com/tickstep/aliyunpan/cmder/cmdliner" "github.com/tickstep/aliyunpan/cmder/cmdliner"
"github.com/tickstep/aliyunpan/cmder/cmdutil" "github.com/tickstep/aliyunpan/cmder/cmdutil"
@@ -27,19 +37,9 @@ import (
"github.com/tickstep/library-go/cachepool" "github.com/tickstep/library-go/cachepool"
"github.com/tickstep/library-go/checkaccess" "github.com/tickstep/library-go/checkaccess"
"github.com/tickstep/library-go/converter" "github.com/tickstep/library-go/converter"
"github.com/tickstep/library-go/getip"
"github.com/tickstep/library-go/jsonhelper" "github.com/tickstep/library-go/jsonhelper"
"github.com/tickstep/library-go/logger" "github.com/tickstep/library-go/logger"
"github.com/tickstep/library-go/requester" "github.com/tickstep/library-go/requester"
"io/ioutil"
"net/http"
"path/filepath"
"regexp"
"runtime"
"strconv"
"strings"
"sync"
"time"
) )
const ( const (
@@ -58,16 +58,16 @@ type tsResp struct {
Msg string `json:"msg"` Msg string `json:"msg"`
} }
func getReleaseFromTicstep(client *requester.HTTPClient, showPrompt bool) *ReleaseInfo { func getReleaseFromTickstep(client *requester.HTTPClient, showPrompt bool) *ReleaseInfo {
tsReleaseInfo := &ReleaseInfo{} tsReleaseInfo := &ReleaseInfo{}
tsRespObj := &tsResp{Data: tsReleaseInfo} tsRespObj := &tsResp{Data: tsReleaseInfo}
fullUrl := strings.Builder{} fullUrl := strings.Builder{}
ipAddr, err := getip.IPInfoFromTechainBaidu() ipAddr, err := utils.GetPublicIP()
if err != nil { if err != nil {
ipAddr = "127.0.0.1" ipAddr = "127.0.0.1"
} }
fmt.Fprintf(&fullUrl, "http://api.tickstep.com/update/tickstep/aliyunpan/releases/latest?ip=%s&os=%s&arch=%s&version=%s", fmt.Fprintf(&fullUrl, "http://api.tickstep.com/update/tickstep/aliyunpan/releases/latest?ip=%s&os=%s&arch=%s&version=%s", ipAddr, runtime.GOOS, runtime.GOARCH, global.AppVersion)
ipAddr, runtime.GOOS, runtime.GOARCH, global.AppVersion) //fmt.Fprintf(&fullUrl, "http://localhost:8997/update/tickstep/aliyunpan/releases/latest?ip=%s&os=%s&arch=%s&version=%s", ipAddr, runtime.GOOS, runtime.GOARCH, global.AppVersion)
resp, err := client.Req(http.MethodGet, fullUrl.String(), nil, nil) resp, err := client.Req(http.MethodGet, fullUrl.String(), nil, nil)
if resp != nil { if resp != nil {
defer resp.Body.Close() defer resp.Body.Close()
@@ -136,10 +136,10 @@ func GetLatestReleaseInfo(showPrompt bool) *ReleaseInfo {
client.SetTimeout(time.Duration(0) * time.Second) client.SetTimeout(time.Duration(0) * time.Second)
client.SetKeepAlive(true) client.SetKeepAlive(true)
// check tickstep srv // tickstep server
var tsReleaseInfo *ReleaseInfo = getReleaseFromTicstep(client, showPrompt) var tsReleaseInfo = getReleaseFromTickstep(client, showPrompt)
// github // github server
var ghReleaseInfo *ReleaseInfo = nil var ghReleaseInfo *ReleaseInfo = nil
for idx := 0; idx < 2; idx++ { for idx := 0; idx < 2; idx++ {
ghReleaseInfo = getReleaseFromGithub(client, showPrompt) ghReleaseInfo = getReleaseFromGithub(client, showPrompt)
@@ -151,10 +151,11 @@ func GetLatestReleaseInfo(showPrompt bool) *ReleaseInfo {
var releaseInfo *ReleaseInfo = nil var releaseInfo *ReleaseInfo = nil
if config.Config.UpdateCheckInfo.PreferUpdateSrv == "tickstep" { if config.Config.UpdateCheckInfo.PreferUpdateSrv == "tickstep" {
// theoretically, tickstep server will be faster at mainland // theoretically, tickstep server will be faster in China mainland
releaseInfo = tsReleaseInfo releaseInfo = tsReleaseInfo
} else { } else {
releaseInfo = ghReleaseInfo releaseInfo = ghReleaseInfo
// 如果github的版本信息获取不到(例如网络不稳定),可以尝试使用tickstep服务进行升级
if ghReleaseInfo == nil || ghReleaseInfo.TagName == "" { if ghReleaseInfo == nil || ghReleaseInfo.TagName == "" {
releaseInfo = tsReleaseInfo releaseInfo = tsReleaseInfo
} }
+40 -4
View File
@@ -16,15 +16,13 @@ package utils
import ( import (
"compress/gzip" "compress/gzip"
"crypto/md5" "crypto/md5"
"encoding/json"
"flag" "flag"
"fmt" "fmt"
jsoniter "github.com/json-iterator/go"
uuid "github.com/satori/go.uuid"
"github.com/tickstep/aliyunpan-api/aliyunpan"
"github.com/tickstep/library-go/ids"
"io" "io"
"io/ioutil" "io/ioutil"
"math" "math"
"net/http"
"net/http/cookiejar" "net/http/cookiejar"
"net/url" "net/url"
"os" "os"
@@ -34,6 +32,11 @@ import (
"strconv" "strconv"
"strings" "strings"
"time" "time"
jsoniter "github.com/json-iterator/go"
uuid "github.com/satori/go.uuid"
"github.com/tickstep/aliyunpan-api/aliyunpan"
"github.com/tickstep/library-go/ids"
) )
// TrimPathPrefix 去除目录的前缀 // TrimPathPrefix 去除目录的前缀
@@ -347,3 +350,36 @@ func FormatSpeedFixedWidth(speed int64, totalWidth int) string {
return formatted return formatted
} }
func GetPublicIP() (string, error) {
type IPResponse struct {
Origin string `json:"origin"`
}
resp, err := http.Get("https://httpbin.org/ip")
if err != nil {
return "", fmt.Errorf("请求失败: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("HTTP 状态码异常: %d", resp.StatusCode)
}
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", fmt.Errorf("读取响应体失败: %w", err)
}
var ipResp IPResponse
if err := json.Unmarshal(body, &ipResp); err != nil {
return "", fmt.Errorf("解析 JSON 失败: %w", err)
}
if ipResp.Origin == "" {
return "", fmt.Errorf("响应中无 IP 信息")
}
// 取第一个 IP(处理代理/X-Forwarded-For 情况)
ip := strings.TrimSpace(strings.Split(ipResp.Origin, ",")[0])
return ip, nil
}