From a26893aabc9b4c14ab31e398826eea51919db8cb Mon Sep 17 00:00:00 2001 From: Darren Yu <62318640+YUDONGLING@users.noreply.github.com> Date: Wed, 5 Jul 2023 22:13:24 +0800 Subject: [PATCH] Add: thumb quality for 3rd storage policy (#1763) Add thumb quality for third party storage policy. --- pkg/filesystem/driver/cos/handler.go | 7 +++++-- pkg/filesystem/driver/oss/handler.go | 4 +++- pkg/filesystem/driver/qiniu/handler.go | 6 ++++-- pkg/filesystem/driver/upyun/handler.go | 4 +++- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/pkg/filesystem/driver/cos/handler.go b/pkg/filesystem/driver/cos/handler.go index fe43bc9..50b500c 100644 --- a/pkg/filesystem/driver/cos/handler.go +++ b/pkg/filesystem/driver/cos/handler.go @@ -234,9 +234,12 @@ func (handler Driver) Thumb(ctx context.Context, file *model.File) (*response.Co ok = false ) if thumbSize, ok = ctx.Value(fsctx.ThumbSizeCtx).([2]uint); !ok { - return nil, errors.New("无法获取缩略图尺寸设置") + return nil, errors.New("failed to get thumbnail size") } - thumbParam := fmt.Sprintf("imageMogr2/thumbnail/%dx%d", thumbSize[0], thumbSize[1]) + + thumbEncodeQuality := model.GetIntSetting("thumb_encode_quality", 85) + + thumbParam := fmt.Sprintf("imageMogr2/thumbnail/%dx%d/quality/%d", thumbSize[0], thumbSize[1], thumbEncodeQuality) source, err := handler.signSourceURL( ctx, diff --git a/pkg/filesystem/driver/oss/handler.go b/pkg/filesystem/driver/oss/handler.go index 8a0f2cb..2ae50a3 100644 --- a/pkg/filesystem/driver/oss/handler.go +++ b/pkg/filesystem/driver/oss/handler.go @@ -312,7 +312,9 @@ func (handler *Driver) Thumb(ctx context.Context, file *model.File) (*response.C return nil, errors.New("failed to get thumbnail size") } - thumbParam := fmt.Sprintf("image/resize,m_lfit,h_%d,w_%d", thumbSize[1], thumbSize[0]) + thumbEncodeQuality := model.GetIntSetting("thumb_encode_quality", 85) + + thumbParam := fmt.Sprintf("image/resize,m_lfit,h_%d,w_%d/quality,q_%d", thumbSize[1], thumbSize[0], thumbEncodeQuality) ctx = context.WithValue(ctx, fsctx.ThumbSizeCtx, thumbParam) thumbOption := []oss.Option{oss.Process(thumbParam)} thumbURL, err := handler.signSourceURL( diff --git a/pkg/filesystem/driver/qiniu/handler.go b/pkg/filesystem/driver/qiniu/handler.go index c0f53a6..a11b574 100644 --- a/pkg/filesystem/driver/qiniu/handler.go +++ b/pkg/filesystem/driver/qiniu/handler.go @@ -242,10 +242,12 @@ func (handler *Driver) Thumb(ctx context.Context, file *model.File) (*response.C ok = false ) if thumbSize, ok = ctx.Value(fsctx.ThumbSizeCtx).([2]uint); !ok { - return nil, errors.New("无法获取缩略图尺寸设置") + return nil, errors.New("failed to get thumbnail size") } - thumb := fmt.Sprintf("%s?imageView2/1/w/%d/h/%d", file.SourceName, thumbSize[0], thumbSize[1]) + thumbEncodeQuality := model.GetIntSetting("thumb_encode_quality", 85) + + thumb := fmt.Sprintf("%s?imageView2/1/w/%d/h/%d/q/%d", file.SourceName, thumbSize[0], thumbSize[1], thumbEncodeQuality) return &response.ContentResponse{ Redirect: true, URL: handler.signSourceURL( diff --git a/pkg/filesystem/driver/upyun/handler.go b/pkg/filesystem/driver/upyun/handler.go index de5dcc2..a9d18d6 100644 --- a/pkg/filesystem/driver/upyun/handler.go +++ b/pkg/filesystem/driver/upyun/handler.go @@ -235,7 +235,9 @@ func (handler Driver) Thumb(ctx context.Context, file *model.File) (*response.Co return nil, errors.New("failed to get thumbnail size") } - thumbParam := fmt.Sprintf("!/fwfh/%dx%d", thumbSize[0], thumbSize[1]) + thumbEncodeQuality := model.GetIntSetting("thumb_encode_quality", 85) + + thumbParam := fmt.Sprintf("!/fwfh/%dx%d/quality/%d", thumbSize[0], thumbSize[1], thumbEncodeQuality) thumbURL, err := handler.Source(ctx, file.SourceName+thumbParam, int64(model.GetIntSetting("preview_timeout", 60)), false, 0) if err != nil { return nil, err