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"
"bytes"
"fmt"
"io/ioutil"
"net/http"
"path/filepath"
"regexp"
"runtime"
"strconv"
"strings"
"sync"
"time"
jsoniter "github.com/json-iterator/go"
"github.com/tickstep/aliyunpan/cmder/cmdliner"
"github.com/tickstep/aliyunpan/cmder/cmdutil"
@@ -27,19 +37,9 @@ import (
"github.com/tickstep/library-go/cachepool"
"github.com/tickstep/library-go/checkaccess"
"github.com/tickstep/library-go/converter"
"github.com/tickstep/library-go/getip"
"github.com/tickstep/library-go/jsonhelper"
"github.com/tickstep/library-go/logger"
"github.com/tickstep/library-go/requester"
"io/ioutil"
"net/http"
"path/filepath"
"regexp"
"runtime"
"strconv"
"strings"
"sync"
"time"
)
const (
@@ -58,16 +58,16 @@ type tsResp struct {
Msg string `json:"msg"`
}
func getReleaseFromTicstep(client *requester.HTTPClient, showPrompt bool) *ReleaseInfo {
func getReleaseFromTickstep(client *requester.HTTPClient, showPrompt bool) *ReleaseInfo {
tsReleaseInfo := &ReleaseInfo{}
tsRespObj := &tsResp{Data: tsReleaseInfo}
fullUrl := strings.Builder{}
ipAddr, err := getip.IPInfoFromTechainBaidu()
ipAddr, err := utils.GetPublicIP()
if err != nil {
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",
ipAddr, runtime.GOOS, runtime.GOARCH, global.AppVersion)
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)
//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)
if resp != nil {
defer resp.Body.Close()
@@ -136,10 +136,10 @@ func GetLatestReleaseInfo(showPrompt bool) *ReleaseInfo {
client.SetTimeout(time.Duration(0) * time.Second)
client.SetKeepAlive(true)
// check tickstep srv
var tsReleaseInfo *ReleaseInfo = getReleaseFromTicstep(client, showPrompt)
// tickstep server
var tsReleaseInfo = getReleaseFromTickstep(client, showPrompt)
// github
// github server
var ghReleaseInfo *ReleaseInfo = nil
for idx := 0; idx < 2; idx++ {
ghReleaseInfo = getReleaseFromGithub(client, showPrompt)
@@ -151,10 +151,11 @@ func GetLatestReleaseInfo(showPrompt bool) *ReleaseInfo {
var releaseInfo *ReleaseInfo = nil
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
} else {
releaseInfo = ghReleaseInfo
// 如果github的版本信息获取不到(例如网络不稳定),可以尝试使用tickstep服务进行升级
if ghReleaseInfo == nil || ghReleaseInfo.TagName == "" {
releaseInfo = tsReleaseInfo
}
+40 -4
View File
@@ -16,15 +16,13 @@ package utils
import (
"compress/gzip"
"crypto/md5"
"encoding/json"
"flag"
"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/ioutil"
"math"
"net/http"
"net/http/cookiejar"
"net/url"
"os"
@@ -34,6 +32,11 @@ import (
"strconv"
"strings"
"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 去除目录的前缀
@@ -347,3 +350,36 @@ func FormatSpeedFixedWidth(speed int64, totalWidth int) string {
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
}