2023-01-11 18:05:29 +08:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"hpds-iot-web/internal/proto"
|
|
|
|
"hpds-iot-web/internal/service"
|
|
|
|
"hpds-iot-web/model"
|
|
|
|
e "hpds-iot-web/pkg/err"
|
2023-03-24 08:42:28 +08:00
|
|
|
"strconv"
|
2023-01-11 18:05:29 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func (s HandlerService) UploadFile(c *gin.Context) (data interface{}, err error) {
|
|
|
|
repo := service.NewFileService(s.AppConfig, s.Engine, s.Logger)
|
|
|
|
us, _ := c.Get("operatorUser")
|
|
|
|
userInfo := us.(*model.SystemUser)
|
|
|
|
var req proto.UploadFileRequest
|
|
|
|
form, err := c.MultipartForm()
|
|
|
|
if err != nil {
|
|
|
|
go s.SaveLog("UploadFile", "Manage", "", "", userInfo.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
|
|
return nil, e.NewValidErr(err)
|
|
|
|
}
|
|
|
|
files := form.File["file"]
|
2023-03-24 08:42:28 +08:00
|
|
|
val := form.Value["scene"]
|
|
|
|
scene := val[0]
|
2023-01-11 18:05:29 +08:00
|
|
|
if len(scene) < 1 {
|
|
|
|
scene = "other"
|
|
|
|
}
|
2023-03-24 08:42:28 +08:00
|
|
|
datasetId, _ := strconv.ParseInt(form.Value["datasetId"][0], 10, 64)
|
2023-01-11 18:05:29 +08:00
|
|
|
req = proto.UploadFileRequest{
|
2023-03-24 08:42:28 +08:00
|
|
|
Creator: userInfo.UserId,
|
|
|
|
Scene: scene,
|
|
|
|
Files: files,
|
|
|
|
DatasetId: datasetId,
|
2023-01-11 18:05:29 +08:00
|
|
|
}
|
|
|
|
data, err = repo.UploadFile(c, req)
|
|
|
|
go s.SaveLog("文件上传", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
|
|
return
|
|
|
|
}
|