mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-01-07 12:17:02 +08:00
fix: optimize thumbnails
This commit is contained in:
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) {
|
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)
|
return c.impl.AccessURL(ctx, name, expire, opt)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,7 +20,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path/filepath"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -287,12 +286,6 @@ func (c *Cos) AccessURL(ctx context.Context, name string, expire time.Duration,
|
|||||||
imageJpeg,
|
imageJpeg,
|
||||||
imageGif,
|
imageGif,
|
||||||
imageWebp:
|
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)
|
style = append(style, "format/"+opt.Image.Format)
|
||||||
}
|
}
|
||||||
if len(style) > 0 {
|
if len(style) > 0 {
|
||||||
@ -316,12 +309,6 @@ func (c *Cos) AccessURL(ctx context.Context, name string, expire time.Duration,
|
|||||||
opt.Video.Format = videoSnapshotImageJpg
|
opt.Video.Format = videoSnapshotImageJpg
|
||||||
}
|
}
|
||||||
query.Set("format", opt.Video.Format)
|
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 {
|
if opt.Video.Width > 0 {
|
||||||
query.Set("width", strconv.Itoa(opt.Video.Width))
|
query.Set("width", strconv.Itoa(opt.Video.Width))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,7 +20,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path/filepath"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -289,12 +288,6 @@ func (o *OSS) AccessURL(ctx context.Context, name string, expire time.Duration,
|
|||||||
default:
|
default:
|
||||||
opt.Image.Format = imageJpg
|
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
|
// 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"
|
process := "image/resize,m_lfit"
|
||||||
if opt.Video.Width > 0 {
|
if opt.Video.Width > 0 {
|
||||||
@ -318,12 +311,6 @@ func (o *OSS) AccessURL(ctx context.Context, name string, expire time.Duration,
|
|||||||
default:
|
default:
|
||||||
opt.Video.Format = videoSnapshotImageJpg
|
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
|
process := "video/snapshot,t_" + strconv.Itoa(millisecond) + ",f_" + opt.Video.Format
|
||||||
if opt.Video.Width > 0 {
|
if opt.Video.Width > 0 {
|
||||||
process += ",w_" + strconv.Itoa(opt.Video.Width)
|
process += ",w_" + strconv.Itoa(opt.Video.Width)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user