mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2025-11-03 20:40:25 +08:00
网站设置增加HLS加密功能(商业版本)
This commit is contained in:
29
pkg/serverconfigs/hls_config.go
Normal file
29
pkg/serverconfigs/hls_config.go
Normal file
@@ -0,0 +1,29 @@
|
||||
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package serverconfigs
|
||||
|
||||
// HLSConfig HTTP Living Streaming相关配置
|
||||
type HLSConfig struct {
|
||||
IsPrior bool `yaml:"isPrior" json:"isPrior"`
|
||||
Encrypting *HLSEncryptingConfig `yaml:"encrypting" json:"encrypting"` // 加密设置
|
||||
}
|
||||
|
||||
func (this *HLSConfig) Init() error {
|
||||
// encrypting
|
||||
if this.Encrypting != nil {
|
||||
err := this.Encrypting.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *HLSConfig) IsEmpty() bool {
|
||||
if this.Encrypting != nil && this.Encrypting.IsOn {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
54
pkg/serverconfigs/hls_encrypting_config.go
Normal file
54
pkg/serverconfigs/hls_encrypting_config.go
Normal file
@@ -0,0 +1,54 @@
|
||||
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package serverconfigs
|
||||
|
||||
import "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||
|
||||
// HLSEncryptingConfig HLS加密配置
|
||||
type HLSEncryptingConfig struct {
|
||||
IsOn bool `yaml:"isOn" json:"isOn"` // 是否启用
|
||||
|
||||
OnlyURLPatterns []*shared.URLPattern `yaml:"onlyURLPatterns" json:"onlyURLPatterns"` // 仅限的URL
|
||||
ExceptURLPatterns []*shared.URLPattern `yaml:"exceptURLPatterns" json:"exceptURLPatterns"` // 排除的URL
|
||||
}
|
||||
|
||||
func (this *HLSEncryptingConfig) Init() error {
|
||||
for _, pattern := range this.OnlyURLPatterns {
|
||||
err := pattern.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for _, pattern := range this.ExceptURLPatterns {
|
||||
err := pattern.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *HLSEncryptingConfig) MatchURL(url string) bool {
|
||||
// except
|
||||
if len(this.ExceptURLPatterns) > 0 {
|
||||
for _, pattern := range this.ExceptURLPatterns {
|
||||
if pattern.Match(url) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// only
|
||||
if len(this.OnlyURLPatterns) > 0 {
|
||||
for _, pattern := range this.OnlyURLPatterns {
|
||||
if pattern.Match(url) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
@@ -32,6 +32,7 @@ type HTTPWebConfig struct {
|
||||
FastcgiRef *HTTPFastcgiRef `yaml:"fastcgiRef" json:"fastcgiRef"` // Fastcgi引用
|
||||
FastcgiList []*HTTPFastcgiConfig `yaml:"fastcgiList" json:"fastcgiList"` // Fastcgi配置
|
||||
UserAgent *UserAgentConfig `yaml:"userAgent" json:"userAgent"` // UserAgent配置
|
||||
HLS *HLSConfig `yaml:"hls" json:"hls"` // HLS配置
|
||||
|
||||
RequestHeaderPolicyRef *shared.HTTPHeaderPolicyRef `yaml:"requestHeaderPolicyRef" json:"requestHeaderPolicyRef"` // 请求Header
|
||||
RequestHeaderPolicy *shared.HTTPHeaderPolicy `yaml:"requestHeaderPolicy" json:"requestHeaderPolicy"` // 请求Header策略
|
||||
@@ -311,6 +312,14 @@ func (this *HTTPWebConfig) Init(ctx context.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
// hls
|
||||
if this.HLS != nil {
|
||||
err := this.HLS.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user