feat:合图新增debug模块

This commit is contained in:
momo 2023-10-18 11:48:32 +08:00
parent 6a982689ef
commit e14fd8b286
2 changed files with 27 additions and 10 deletions

View File

@ -136,6 +136,7 @@ type (
Metadata *string
DiffTimeLogoCombine int64
DiffTimeUploadFile int64
DebugData *auth.DebugData `json:"debug_data"`
}
)
type TemplateTagColor struct {
@ -144,6 +145,7 @@ type TemplateTagColor struct {
}
func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq) (*LogoCombineRes, error) {
var resp = &LogoCombineRes{}
logoResourceId := s3url_to_s3id.GetS3ResourceIdFormUrl(in.LogoUrl)
if logoResourceId == "" {
return nil, errors.New("invalid logo url")
@ -167,10 +169,12 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq
resourceModel := gmodel.NewFsResourceModel(l.MysqlConn)
resourceInfo, err := resourceModel.FindOneById(ctx, resourceId)
if err == nil && resourceInfo.ResourceId != "" {
if in.Debug == nil || (in.Debug != nil && in.Debug.IsCache == 1) {
return &LogoCombineRes{
ResourceId: resourceId,
ResourceUrl: resourceInfo.ResourceUrl,
}, nil
}
} else {
if err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
@ -308,12 +312,19 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq
return nil, err
}
return &LogoCombineRes{
ResourceId: uploadRes.ResourceId,
ResourceUrl: &uploadRes.ResourceUrl,
resp.ResourceId = uploadRes.ResourceId
resp.ResourceUrl = &uploadRes.ResourceUrl
resp.DiffTimeLogoCombine = diffTimeLogoCombine
resp.DiffTimeUploadFile = diffTimeUploadFile
if in.Debug != nil {
resp.DebugData = &auth.DebugData{
DiffTimeLogoCombine: diffTimeLogoCombine,
DiffTimeUploadFile: diffTimeUploadFile,
}, nil
}
}
return resp, nil
}
/* logo合图 */

View File

@ -24,6 +24,12 @@ const (
IDTYPE_Guest IDTYPE = 2
)
// DebugData
type DebugData struct {
DiffTimeLogoCombine int64 `json:"diff_time_logo_combine"` // 合图算法时间
DiffTimeUploadFile int64 `json:"diff_time_upload_file"` // 合图上传时间
}
// Debug 相关的结构
type Debug struct {
Exp *int64 `json:"exp"`