mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-12-09 03:30:24 +08:00
实现UA名单功能
This commit is contained in:
@@ -468,6 +468,16 @@ func (this *HTTPWebDAO) ComposeWebConfig(tx *dbs.Tx, webId int64, cacheMap *util
|
||||
config.Referers = referersConfig
|
||||
}
|
||||
|
||||
// User-Agent
|
||||
if IsNotNull(web.UserAgent) {
|
||||
var userAgentConfig = serverconfigs.NewUserAgentConfig()
|
||||
err = json.Unmarshal(web.UserAgent, userAgentConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config.UserAgent = userAgentConfig
|
||||
}
|
||||
|
||||
if cacheMap != nil {
|
||||
cacheMap.Put(cacheKey, config)
|
||||
}
|
||||
@@ -1252,6 +1262,35 @@ func (this *HTTPWebDAO) FindWebReferers(tx *dbs.Tx, webId int64) ([]byte, error)
|
||||
FindJSONCol()
|
||||
}
|
||||
|
||||
// UpdateWebUserAgent 修改User-Agent设置
|
||||
func (this *HTTPWebDAO) UpdateWebUserAgent(tx *dbs.Tx, webId int64, userAgentConfig *serverconfigs.UserAgentConfig) error {
|
||||
if userAgentConfig == nil {
|
||||
return nil
|
||||
}
|
||||
configJSON, err := json.Marshal(userAgentConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = this.Query(tx).
|
||||
Pk(webId).
|
||||
Set("userAgent", configJSON).
|
||||
UpdateQuickly()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return this.NotifyUpdate(tx, webId)
|
||||
}
|
||||
|
||||
// FindWebUserAgent 查找服务User-Agent配置
|
||||
func (this *HTTPWebDAO) FindWebUserAgent(tx *dbs.Tx, webId int64) ([]byte, error) {
|
||||
return this.Query(tx).
|
||||
Pk(webId).
|
||||
Result("userAgent").
|
||||
FindJSONCol()
|
||||
}
|
||||
|
||||
// NotifyUpdate 通知更新
|
||||
func (this *HTTPWebDAO) NotifyUpdate(tx *dbs.Tx, webId int64) error {
|
||||
// server
|
||||
|
||||
Reference in New Issue
Block a user