feat: 新增linux文件上传成功后websocket通知

This commit is contained in:
meilin.huang
2021-11-11 15:56:02 +08:00
parent f6fb732911
commit 78d6c3d1a4
26 changed files with 379 additions and 150 deletions

View File

@@ -1,14 +1,17 @@
package application
import (
"fmt"
"io"
"io/fs"
"io/ioutil"
"mayfly-go/base/biz"
"mayfly-go/base/model"
"mayfly-go/base/ws"
"mayfly-go/server/devops/domain/entity"
"mayfly-go/server/devops/domain/repository"
"mayfly-go/server/devops/infrastructure/persistence"
sysApplication "mayfly-go/server/sys/application"
"os"
"strings"
@@ -41,7 +44,7 @@ type MachineFile interface {
WriteFileContent(fileId uint64, path string, content []byte)
// 文件上传
UploadFile(fileId uint64, path, filename string, content []byte)
UploadFile(la *model.LoginAccount, fileId uint64, path, filename string, content []byte)
// 移除文件
RemoveFile(fileId uint64, path string)
@@ -50,12 +53,14 @@ type MachineFile interface {
type machineFileAppImpl struct {
machineFileRepo repository.MachineFile
machineRepo repository.Machine
msgApp sysApplication.Msg
}
// 实现类单例
var MachineFileApp MachineFile = &machineFileAppImpl{
machineRepo: persistence.MachineDao,
machineFileRepo: persistence.MachineFileDao,
msgApp: sysApplication.MsgApp,
}
// 分页获取机器脚本信息列表
@@ -133,7 +138,7 @@ func (m *machineFileAppImpl) WriteFileContent(fileId uint64, path string, conten
}
// 上传文件
func (m *machineFileAppImpl) UploadFile(fileId uint64, path, filename string, content []byte) {
func (m *machineFileAppImpl) UploadFile(la *model.LoginAccount, fileId uint64, path, filename string, content []byte) {
path, machineId := m.checkAndReturnPathMid(fileId, path)
if !strings.HasSuffix(path, "/") {
path = path + "/"
@@ -145,6 +150,9 @@ func (m *machineFileAppImpl) UploadFile(fileId uint64, path, filename string, co
defer createfile.Close()
createfile.Write(content)
// 保存消息并发送文件上传成功通知
m.msgApp.CreateAndSend(la, ws.SuccessMsg("文件上传", fmt.Sprintf("[%s]文件已成功上传至[%s]", filename, path)))
}
// 删除文件