This commit is contained in:
cdle
2023-07-07 14:49:31 +08:00
parent fb96a5afc3
commit 8c4e93d614
2 changed files with 34 additions and 11 deletions
+24 -2
View File
@@ -1,6 +1,7 @@
package core package core
import ( import (
"errors"
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
@@ -19,6 +20,18 @@ import (
var DataHome = utils.GetDataHome() var DataHome = utils.GetDataHome()
func GetVersion() (string, error) {
v, e := httplib.Get("http://172.96.255.172:8765/api/version").String()
if len(v) == 13 {
sillyGirl.Set("version", v)
if v != compiled_at {
console.Log("发现到更新,版本号:", v)
}
return v, e
}
return v, errors.New("版本获取失败")
}
func Init() { func Init() {
initLoc() initLoc()
sillyGirl = MakeBucket("sillyGirl") sillyGirl = MakeBucket("sillyGirl")
@@ -64,12 +77,19 @@ func Init() {
var body io.Reader var body io.Reader
var data []byte var data []byte
var latest_version = "" var latest_version = ""
var resp *http.Response
var req *http.Request
console.Debug("正在从 cdle/binary 获取版本号...") console.Debug("正在从 cdle/binary 获取版本号...")
proxy := false proxy := false
qurl := "https://raw.githubusercontent.com/cdle/binary/main/compile_time.go" qurl := "https://raw.githubusercontent.com/cdle/binary/main/compile_time.go"
req, _ := http.NewRequest("GET", qurl, strings.NewReader(""))
resp, err := client.Do(req) version, _ := GetVersion()
if version != "" {
latest_version = version
} else {
req, _ = http.NewRequest("GET", qurl, strings.NewReader(""))
resp, err = client.Do(req)
if err != nil { if err != nil {
console.Error("获取版本号错误:%s", err) console.Error("获取版本号错误:%s", err)
// return &storage.Final{ // return &storage.Final{
@@ -80,6 +100,8 @@ func Init() {
defer resp.Body.Close() defer resp.Body.Close()
data, _ = ioutil.ReadAll(resp.Body) data, _ = ioutil.ReadAll(resp.Body)
latest_version = regexp.MustCompile(`\d{13}`).FindString(string(data)) latest_version = regexp.MustCompile(`\d{13}`).FindString(string(data))
}
if latest_version <= compiled_at { if latest_version <= compiled_at {
console.Debug("当前版本 %s 已是最新,无需升级", compiled_at) console.Debug("当前版本 %s 已是最新,无需升级", compiled_at)
return &storage.Final{ return &storage.Final{
+1
View File
@@ -23,6 +23,7 @@ func main() {
if err == nil { if err == nil {
app.Set("ip", ip) app.Set("ip", ip)
} }
core.GetVersion()
}() }()
core.Init() core.Init()
if app.GetBool("anti_kasi") { if app.GetBool("anti_kasi") {