x
This commit is contained in:
+33
-11
@@ -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,22 +77,31 @@ 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 err != nil {
|
if version != "" {
|
||||||
console.Error("获取版本号错误:%s", err)
|
latest_version = version
|
||||||
// return &storage.Final{
|
} else {
|
||||||
// Error: fmt.Errorf("貌似网络不太行啊:%s", err),
|
req, _ = http.NewRequest("GET", qurl, strings.NewReader(""))
|
||||||
// }
|
resp, err = client.Do(req)
|
||||||
goto PROXY
|
if err != nil {
|
||||||
|
console.Error("获取版本号错误:%s", err)
|
||||||
|
// return &storage.Final{
|
||||||
|
// Error: fmt.Errorf("貌似网络不太行啊:%s", err),
|
||||||
|
// }
|
||||||
|
goto PROXY
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
data, _ = ioutil.ReadAll(resp.Body)
|
||||||
|
latest_version = regexp.MustCompile(`\d{13}`).FindString(string(data))
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
|
||||||
data, _ = ioutil.ReadAll(resp.Body)
|
|
||||||
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{
|
||||||
|
|||||||
Reference in New Issue
Block a user