2024-05-17 18:28:59 +08:00
|
|
|
|
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved.
|
2022-04-01 16:20:36 +08:00
|
|
|
|
|
|
|
|
|
|
package nodeconfigs
|
|
|
|
|
|
|
|
|
|
|
|
import "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
|
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
|
_ = DefaultWebPImagePolicy.Init()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-11 11:08:48 +08:00
|
|
|
|
var DefaultWebPImagePolicy = NewWebPImagePolicy()
|
|
|
|
|
|
|
|
|
|
|
|
func NewWebPImagePolicy() *WebPImagePolicy {
|
|
|
|
|
|
return &WebPImagePolicy{
|
|
|
|
|
|
IsOn: true,
|
|
|
|
|
|
RequireCache: true,
|
|
|
|
|
|
MinLength: shared.NewSizeCapacity(0, shared.SizeCapacityUnitKB),
|
|
|
|
|
|
MaxLength: shared.NewSizeCapacity(128, shared.SizeCapacityUnitMB),
|
|
|
|
|
|
}
|
2022-04-01 16:20:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// WebPImagePolicy WebP策略
|
|
|
|
|
|
type WebPImagePolicy struct {
|
|
|
|
|
|
IsOn bool `yaml:"isOn" json:"isOn"` // 是否启用
|
|
|
|
|
|
RequireCache bool `yaml:"requireCache" json:"requireCache"` // 需要在缓存条件下进行
|
|
|
|
|
|
MinLength *shared.SizeCapacity `yaml:"minLength" json:"minLength"` // 最小压缩对象比如4m, 24k
|
|
|
|
|
|
MaxLength *shared.SizeCapacity `yaml:"maxLength" json:"maxLength"` // 最大压缩对象
|
2023-12-11 10:17:46 +08:00
|
|
|
|
Quality int `yaml:"quality" json:"quality"` // 生成的图片质量:0-100
|
2022-04-01 16:20:36 +08:00
|
|
|
|
|
|
|
|
|
|
minLength int64
|
|
|
|
|
|
maxLength int64
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *WebPImagePolicy) Init() error {
|
|
|
|
|
|
if this.MinLength != nil {
|
|
|
|
|
|
this.minLength = this.MinLength.Bytes()
|
|
|
|
|
|
}
|
|
|
|
|
|
if this.MaxLength != nil {
|
|
|
|
|
|
this.maxLength = this.MaxLength.Bytes()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *WebPImagePolicy) MinLengthBytes() int64 {
|
|
|
|
|
|
return this.minLength
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *WebPImagePolicy) MaxLengthBytes() int64 {
|
|
|
|
|
|
return this.maxLength
|
|
|
|
|
|
}
|