mirror of
https://github.com/ayflying/p2p.git
synced 2026-03-05 01:39:23 +00:00
自动上传服务端版本
This commit is contained in:
@@ -1,14 +1,20 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"path"
|
||||
"runtime"
|
||||
|
||||
"github.com/ayflying/p2p/internal/service"
|
||||
"github.com/gogf/gf/v2/crypto/gsha1"
|
||||
"github.com/gogf/gf/v2/encoding/gcompress"
|
||||
"github.com/gogf/gf/v2/encoding/gjson"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gcfg"
|
||||
"github.com/gogf/gf/v2/os/gcmd"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -21,8 +27,8 @@ var (
|
||||
//加载编辑配置文件
|
||||
g.Cfg("hack").GetAdapter().(*gcfg.AdapterFile).SetFileName("hack/config.yaml")
|
||||
//获取文件名
|
||||
getFileName, err := g.Cfg("hack").Get(ctx, "gfcli.build.name")
|
||||
filename := getFileName.String()
|
||||
getName, err := g.Cfg("hack").Get(ctx, "gfcli.build.name")
|
||||
name := getName.String()
|
||||
|
||||
getPath, err := g.Cfg("hack").Get(ctx, "gfcli.build.path")
|
||||
pathMain := getPath.String()
|
||||
@@ -34,7 +40,40 @@ var (
|
||||
// 拼接操作系统和架构(格式:OS_ARCH)
|
||||
platform := fmt.Sprintf("%s_%s", runtime.GOOS, runtime.GOARCH)
|
||||
|
||||
var filePath = path.Join(pathMain, version, platform, filename)
|
||||
var versionFile = make(map[string]string)
|
||||
|
||||
var filePath = path.Join(pathMain, version, platform, name)
|
||||
dirList, _ := gfile.ScanDir(path.Join(pathMain, version), "*", false)
|
||||
for _, v := range dirList {
|
||||
updateFilename := gfile.Name(v)
|
||||
updateFilePath := path.Join("server_update", name, version, updateFilename)
|
||||
|
||||
var obj bytes.Buffer
|
||||
g.Log().Debugf(ctx, "读取目录成功:%v", v)
|
||||
fileMian := path.Join(v, name)
|
||||
g.Log().Debugf(ctx, "判断当前文件是否存在:%v", fileMian)
|
||||
if gfile.IsFile(fileMian) {
|
||||
// 写入文件哈希
|
||||
versionFile[updateFilePath+".gz"] = gsha1.MustEncryptFile(fileMian)
|
||||
err = gcompress.GzipPathWriter(fileMian, &obj)
|
||||
service.S3().PutObject(ctx, &obj, updateFilePath+".gz")
|
||||
g.Log().Debugf(ctx, "成功上传文件到:%v", updateFilePath+".gz")
|
||||
}
|
||||
if gfile.IsFile(fileMian + ".exe") {
|
||||
// 写入文件哈希
|
||||
versionFile[updateFilePath+".gz"] = gsha1.MustEncryptFile(fileMian + ".exe")
|
||||
err = gcompress.GzipPathWriter(fileMian+".exe", &obj)
|
||||
service.S3().PutObject(ctx, &obj, updateFilePath+".gz")
|
||||
g.Log().Debugf(ctx, "成功上传文件到:%v", updateFilePath+".gz")
|
||||
}
|
||||
|
||||
// 写入文件版本文件
|
||||
fileByte := gjson.MustEncode(versionFile)
|
||||
service.S3().PutObject(ctx, bytes.NewReader(fileByte), path.Join("server_update", name, version, "version.json"))
|
||||
if err != nil {
|
||||
g.Log().Error(ctx, err)
|
||||
}
|
||||
}
|
||||
|
||||
g.Log().Debugf(ctx, "当前获取到的地址为:%v", filePath)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user