pcm-octopus/internal/logic/downloadcompresslogic.go

54 lines
1.3 KiB
Go

package logic
import (
"context"
"errors"
"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"
"github.com/zeromicro/go-zero/core/logx"
)
type DownloadCompressLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewDownloadCompressLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DownloadCompressLogic {
return &DownloadCompressLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *DownloadCompressLogic) DownloadCompress(in *octopus.DownloadCompressReq) (*octopus.DownloadCompressResp, error) {
resp := &octopus.DownloadCompressResp{}
var url_prefix = common.OctopusUrls[in.Platform]
var reqUrl = url_prefix + l.svcCtx.Config.OctopusApi.DownloadCompress
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).
SetResult(resp).
Get(reqUrl)
if err != nil {
return nil, err
}
return resp, nil
}