forked from JointCloud/pcm-octopus
56 lines
1.4 KiB
Go
56 lines
1.4 KiB
Go
package logic
|
|
|
|
import (
|
|
"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"
|
|
"log"
|
|
"strconv"
|
|
)
|
|
|
|
type DownloadAlgorithmLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewDownloadAlgorithmLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DownloadAlgorithmLogic {
|
|
return &DownloadAlgorithmLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *DownloadAlgorithmLogic) DownloadAlgorithm(in *octopus.DownloadAlgorithmReq) (*octopus.DownloadAlgorithmResp, error) {
|
|
resp := &octopus.DownloadAlgorithmResp{}
|
|
|
|
var url_prefix = common.OctopusUrls[in.Platform]
|
|
var reqUrl = url_prefix + l.svcCtx.Config.OctopusApi.DownloadAlgorithm
|
|
|
|
token := common.GetToken(in.Platform)
|
|
if token == "" {
|
|
log.Println("获取token失败, platform : ", in.Platform)
|
|
return nil, errors.New("获取token失败")
|
|
}
|
|
|
|
req := tool.GetACHttpRequest()
|
|
_, err := req.
|
|
SetHeader("Authorization", "Bearer "+token).
|
|
SetPathParam("algorithmId", in.AlgorithmId).
|
|
SetPathParam("version", in.Version).
|
|
SetQueryParam("compressAt", strconv.FormatInt(in.CompressAt, 10)).
|
|
SetQueryParam("domain", in.Domain).
|
|
SetResult(resp).
|
|
Get(reqUrl)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return resp, nil
|
|
}
|