forked from JointCloud/pcm-octopus
65 lines
1.4 KiB
Go
65 lines
1.4 KiB
Go
package logic
|
|
|
|
import (
|
|
"archive/zip"
|
|
"bytes"
|
|
"context"
|
|
"errors"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
"gitlink.org.cn/JointCloud/pcm-octopus/internal/common"
|
|
"gitlink.org.cn/JointCloud/pcm-octopus/internal/svc"
|
|
"gitlink.org.cn/JointCloud/pcm-octopus/octopus"
|
|
"gitlink.org.cn/jcce-pcm/utils/tool"
|
|
"io"
|
|
"log"
|
|
)
|
|
|
|
type DownloadAlgorithmUrlLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewDownloadAlgorithmUrlLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DownloadAlgorithmUrlLogic {
|
|
return &DownloadAlgorithmUrlLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *DownloadAlgorithmUrlLogic) DownloadAlgorithmUrl(in *octopus.AlgorithmUrlReq) (*octopus.AlgorithmUrlResp, error) {
|
|
resp := &octopus.AlgorithmUrlResp{}
|
|
|
|
token := common.GetToken(in.Platform)
|
|
if token == "" {
|
|
log.Println("获取token失败, platform : ", in.Platform)
|
|
return nil, errors.New("获取token失败")
|
|
}
|
|
|
|
req := tool.GetACHttpRequest()
|
|
rs, err := req.
|
|
SetHeader("token", token).
|
|
Get(in.Url)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
file := rs.Body()
|
|
reader, _ := zip.NewReader(bytes.NewReader(file), int64(len(file)))
|
|
zf := &zip.File{}
|
|
for _, f := range reader.File {
|
|
if f.FileInfo().IsDir() {
|
|
continue
|
|
}
|
|
zf = f
|
|
}
|
|
rc, _ := zf.Open()
|
|
all, err := io.ReadAll(rc)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
resp.Algorithm = string(all)
|
|
return resp, nil
|
|
}
|