updadted uploadFile logic

This commit is contained in:
tzwang 2024-04-26 17:56:03 +08:00
parent 9d5a86ac23
commit 549fefd8be
2 changed files with 53 additions and 5 deletions

View File

@ -2,9 +2,11 @@ package logic
import (
"context"
"errors"
"gitlink.org.cn/JointCloud/pcm-ac/hpcAC"
"gitlink.org.cn/JointCloud/pcm-ac/internal/common"
"gitlink.org.cn/JointCloud/pcm-ac/internal/svc"
"log"
"github.com/zeromicro/go-zero/core/logx"
)
@ -24,7 +26,26 @@ func NewGetFileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetFileLo
}
func (l *GetFileLogic) GetFile(in *hpcAC.GetFileReq) (*hpcAC.GetFileResp, error) {
// todo: add your logic here and delete this line
resp := &hpcAC.GetFileResp{}
var reqUrl = common.EFileUrlPrefix() + l.svcCtx.Config.FileConf.GetFile
return &hpcAC.GetFileResp{}, nil
token := common.GetToken()
if token == "" {
log.Println("获取token失败")
return nil, errors.New("获取token失败")
}
req := common.GetRestyRequest(3)
rpse, err := req.
SetHeader("token", token).
SetQueryParam("path", in.Path).
Get(reqUrl)
if err != nil {
return nil, err
}
resp.Content = string(rpse.Body())
return resp, nil
}

View File

@ -1,7 +1,12 @@
package logic
import (
"bytes"
"context"
"errors"
"fmt"
"gitlink.org.cn/JointCloud/pcm-ac/internal/common"
"log"
"gitlink.org.cn/JointCloud/pcm-ac/hpcAC"
"gitlink.org.cn/JointCloud/pcm-ac/internal/svc"
@ -24,7 +29,29 @@ func NewUploadFileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Upload
}
func (l *UploadFileLogic) UploadFile(in *hpcAC.UploadFileReq) (*hpcAC.UploadFileResp, error) {
// todo: add your logic here and delete this line
resp := &hpcAC.UploadFileResp{}
var reqUrl = common.EFileUrlPrefix() + l.svcCtx.Config.FileConf.UploadFile
return &hpcAC.UploadFileResp{}, nil
token := common.GetToken()
if token == "" {
log.Println("获取token失败")
return nil, errors.New("获取token失败")
}
req := common.GetRestyRequest(3)
_, err := req.
SetHeader("token", token).
SetFileReader("file", "train.py", bytes.NewReader([]byte(in.File))).
SetFormData(map[string]string{
"path": in.Path,
"cover": in.Cover,
}).
SetResult(resp).
Post(reqUrl)
if err != nil {
fmt.Println("err")
}
return resp, nil
}