mirror of
https://github.com/ayflying/p2p.git
synced 2026-03-05 01:39:23 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f90cf8b855 | |||
| a0f367efeb |
@@ -1,8 +1,11 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/ayflying/p2p/internal/service"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gcron"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
)
|
||||
|
||||
@@ -17,6 +20,14 @@ func init() {
|
||||
|
||||
getDev, _ := g.Cfg().GetWithEnv(gctx.New(), "dev")
|
||||
if !getDev.Bool() {
|
||||
// 每天0点检查更新
|
||||
gcron.Add(gctx.New(), "0 0 0 * * *", func(ctx context.Context) {
|
||||
err := service.System().CheckUpdate()
|
||||
if err != nil {
|
||||
g.Log().Errorf(ctx, "检查更新失败:%v", err)
|
||||
}
|
||||
})
|
||||
|
||||
err := service.System().CheckUpdate()
|
||||
if err != nil {
|
||||
g.Log().Errorf(gctx.New(), "检查更新失败:%v", err)
|
||||
|
||||
@@ -24,6 +24,8 @@ import (
|
||||
)
|
||||
|
||||
// 本地版本号(建议从编译参数注入,如 -ldflags "-X main.version=v0.1.3")
|
||||
const versionFile = "version.txt"
|
||||
|
||||
var localVersion = "v0.0.0"
|
||||
|
||||
// 对应 GitHub API 响应的核心字段(按需精简)
|
||||
@@ -59,6 +61,8 @@ func (s *sSystem) Update(ctx context.Context, gzFile string) (err error) {
|
||||
if gzFile == "" {
|
||||
gzFile = path.Join("download", platform+".gz")
|
||||
}
|
||||
//结束后删除压缩包
|
||||
defer gfile.RemoveFile(gzFile)
|
||||
|
||||
ext := gfile.Ext(gzFile)
|
||||
if ext == ".zip" {
|
||||
@@ -198,7 +202,7 @@ func (s *sSystem) CheckUpdate() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
localVersion = gfile.GetContents("download/version.txt")
|
||||
localVersion = gfile.GetContents(versionFile)
|
||||
|
||||
if s.isNewVersion(localVersion, latestVersion) {
|
||||
g.Log().Printf(ctx, "发现新版本:%s(当前版本:%s)", latestVersion, localVersion)
|
||||
@@ -223,7 +227,7 @@ func (s *sSystem) CheckUpdate() (err error) {
|
||||
return
|
||||
}
|
||||
// 保存最新版本号到文件
|
||||
gfile.PutContents("download/version.txt", latestVersion)
|
||||
gfile.PutContents(versionFile, latestVersion)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user