From cb3c8cc8656812b8127b860a63186772739fc308 Mon Sep 17 00:00:00 2001 From: withchao <993506633@qq.com> Date: Mon, 7 Aug 2023 18:33:12 +0800 Subject: [PATCH] fix: optimize thumbnails --- pkg/common/db/s3/cont/controller.go | 4 ++++ pkg/common/db/s3/cos/cos.go | 13 ------------- pkg/common/db/s3/oss/oss.go | 13 ------------- 3 files changed, 4 insertions(+), 26 deletions(-) diff --git a/pkg/common/db/s3/cont/controller.go b/pkg/common/db/s3/cont/controller.go index 01dbc787f..a3b78f4ba 100644 --- a/pkg/common/db/s3/cont/controller.go +++ b/pkg/common/db/s3/cont/controller.go @@ -256,5 +256,9 @@ func (c *Controller) IsNotFound(err error) bool { } func (c *Controller) AccessURL(ctx context.Context, name string, expire time.Duration, opt *s3.AccessURLOption) (string, error) { + if opt.Image != nil || opt.Video != nil { + opt.Filename = "" + opt.ContentType = "" + } return c.impl.AccessURL(ctx, name, expire, opt) } diff --git a/pkg/common/db/s3/cos/cos.go b/pkg/common/db/s3/cos/cos.go index cbdbd3722..2518fbe4d 100644 --- a/pkg/common/db/s3/cos/cos.go +++ b/pkg/common/db/s3/cos/cos.go @@ -20,7 +20,6 @@ import ( "fmt" "net/http" "net/url" - "path/filepath" "strconv" "strings" "time" @@ -287,12 +286,6 @@ func (c *Cos) AccessURL(ctx context.Context, name string, expire time.Duration, imageJpeg, imageGif, imageWebp: - opt.ContentType = "image/" + opt.Image.Format - if opt.Filename == "" { - opt.Filename = filepath.Base(name) + "." + opt.Image.Format - } else if filepath.Ext(opt.Filename) != "."+opt.Image.Format { - opt.Filename += "." + opt.Image.Format - } style = append(style, "format/"+opt.Image.Format) } if len(style) > 0 { @@ -316,12 +309,6 @@ func (c *Cos) AccessURL(ctx context.Context, name string, expire time.Duration, opt.Video.Format = videoSnapshotImageJpg } query.Set("format", opt.Video.Format) - opt.ContentType = "image/" + opt.Video.Format - if opt.Filename == "" { - opt.Filename = filepath.Base(name) + "." + opt.Video.Format - } else if filepath.Ext(opt.Filename) != "."+opt.Video.Format { - opt.Filename += "." + opt.Video.Format - } if opt.Video.Width > 0 { query.Set("width", strconv.Itoa(opt.Video.Width)) } diff --git a/pkg/common/db/s3/oss/oss.go b/pkg/common/db/s3/oss/oss.go index 08ade23c9..c8d59bc64 100644 --- a/pkg/common/db/s3/oss/oss.go +++ b/pkg/common/db/s3/oss/oss.go @@ -20,7 +20,6 @@ import ( "fmt" "net/http" "net/url" - "path/filepath" "strconv" "strings" "time" @@ -289,12 +288,6 @@ func (o *OSS) AccessURL(ctx context.Context, name string, expire time.Duration, default: opt.Image.Format = imageJpg } - opt.ContentType = "image/" + format - if opt.Filename == "" { - opt.Filename = filepath.Base(name) + "." + opt.Video.Format - } else if filepath.Ext(opt.Filename) != "."+opt.Video.Format { - opt.Filename += "." + opt.Video.Format - } // https://oss-console-img-demo-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=image/resize,h_100,m_lfit process := "image/resize,m_lfit" if opt.Video.Width > 0 { @@ -318,12 +311,6 @@ func (o *OSS) AccessURL(ctx context.Context, name string, expire time.Duration, default: opt.Video.Format = videoSnapshotImageJpg } - opt.ContentType = "image/" + opt.Video.Format - if opt.Filename == "" { - opt.Filename = filepath.Base(name) + "." + opt.Video.Format - } else if filepath.Ext(opt.Filename) != "."+opt.Video.Format { - opt.Filename += "." + opt.Video.Format - } process := "video/snapshot,t_" + strconv.Itoa(millisecond) + ",f_" + opt.Video.Format if opt.Video.Width > 0 { process += ",w_" + strconv.Itoa(opt.Video.Width)