fix: optimize thumbnails

pull/818/head
withchao 2 years ago
parent b89a611e8f
commit cb3c8cc865

@ -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)
}

@ -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))
}

@ -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)

Loading…
Cancel
Save