80 lines
1.9 KiB
Go
80 lines
1.9 KiB
Go
package web
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/gin/engine"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
"net/http"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
//上传配置文件
|
|
func (this *Api_Comp) Upload(c *engine.Context) {
|
|
var (
|
|
errdata *pb.ErrorData
|
|
)
|
|
defer func() {
|
|
c.JSON(http.StatusOK, &Respond{
|
|
Code: errdata.Code,
|
|
Message: errdata.Message,
|
|
})
|
|
}()
|
|
filenum := c.PostForm("filenum")
|
|
if filenum != "" {
|
|
if n, err := strconv.Atoi(filenum); err != nil {
|
|
this.module.Errorln(err)
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
} else {
|
|
for i := 0; i < n; i++ {
|
|
if fn, err := c.FormFile(fmt.Sprintf("file_%d", i)); err != nil {
|
|
this.module.Errorln(err)
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
} else {
|
|
if err = c.SaveUploadedFile(fn, fmt.Sprintf("%s/%s", configure.ConfigurePath(), fn.Filename)); err != nil {
|
|
this.module.Errorln(err)
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
ctx, _ := context.WithTimeout(context.TODO(), time.Second*5)
|
|
if err := this.module.service.RpcBroadcast(
|
|
ctx,
|
|
comm.Service_Worker,
|
|
string(comm.Rpc_ConfigureUpDate),
|
|
&pb.EmptyReq{},
|
|
&pb.EmptyResp{}); err != nil {
|
|
this.module.Errorln(err)
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_RpcFuncExecutionError,
|
|
Title: pb.ErrorCode_RpcFuncExecutionError.ToString(),
|
|
}
|
|
}
|
|
} else {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
}
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_Success,
|
|
Title: pb.ErrorCode_Success.ToString(),
|
|
}
|
|
}
|