mirror of
				https://github.com/TeaOSLab/EdgeCommon.git
				synced 2025-11-04 05:00:24 +08:00 
			
		
		
		
	集群可以设置WebP策略
This commit is contained in:
		
							
								
								
									
										46
									
								
								pkg/nodeconfigs/image_webp_policy.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								pkg/nodeconfigs/image_webp_policy.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,46 @@
 | 
			
		||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
 | 
			
		||||
 | 
			
		||||
package nodeconfigs
 | 
			
		||||
 | 
			
		||||
import "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
	_ = DefaultWebPImagePolicy.Init()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var DefaultWebPImagePolicy = &WebPImagePolicy{
 | 
			
		||||
	IsOn:         true,
 | 
			
		||||
	RequireCache: true,
 | 
			
		||||
	MinLength:    shared.NewSizeCapacity(0, shared.SizeCapacityUnitKB),
 | 
			
		||||
	MaxLength:    shared.NewSizeCapacity(128, shared.SizeCapacityUnitMB),
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 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"`       // 最大压缩对象
 | 
			
		||||
 | 
			
		||||
	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
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user