mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-10 03:10:25 +08:00
feat: 新增linux文件上传成功后websocket通知
This commit is contained in:
@@ -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)))
|
||||
|
||||
}
|
||||
|
||||
// 删除文件
|
||||
|
||||
Reference in New Issue
Block a user