集群可以设置WebP策略

This commit is contained in:
刘祥超
2022-04-01 16:18:15 +08:00
parent 59faf95885
commit 048c6f213b
2 changed files with 42 additions and 27 deletions

View File

@@ -6,13 +6,13 @@ import (
"bufio"
"bytes"
"errors"
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/TeaOSLab/EdgeNode/internal/caches"
"github.com/TeaOSLab/EdgeNode/internal/compressions"
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
"github.com/TeaOSLab/EdgeNode/internal/utils"
"github.com/TeaOSLab/EdgeNode/internal/utils/readers"
"github.com/TeaOSLab/EdgeNode/internal/utils/sizes"
"github.com/TeaOSLab/EdgeNode/internal/utils/writers"
_ "github.com/biessek/golang-ico"
"github.com/iwind/TeaGo/lists"
@@ -444,18 +444,27 @@ func (this *HTTPWriter) PrepareWebP(resp *http.Response, size int64) {
return
}
// 集群配置
var policy = sharedNodeConfig.FindWebPImagePolicyWithClusterId(this.req.ReqServer.ClusterId)
if policy == nil {
policy = nodeconfigs.DefaultWebPImagePolicy
}
if !policy.IsOn {
return
}
// 只有在开启了缓存之后,才会转换,防止占用的系统资源过高
if this.req.cacheRef == nil {
if policy.RequireCache && this.req.cacheRef == nil {
return
}
// 限制最小和最大尺寸
// TODO 需要可以在集群里WebP选项里设置
// TODO 需要将reader修改为LimitReader
if resp.ContentLength == 0 {
return
}
if resp.ContentLength > 128*sizes.M {
if resp.ContentLength > 0 && (resp.ContentLength < policy.MinLengthBytes() || (policy.MaxLengthBytes() > 0 && resp.ContentLength > policy.MaxLengthBytes())) {
return
}