屏蔽规则页面丰富显示
This commit is contained in:
@@ -875,23 +875,41 @@ func (s *Server) handleShieldBlacklists(w http.ResponseWriter, r *http.Request)
|
||||
json.NewEncoder(w).Encode(map[string]string{"status": "success"})
|
||||
|
||||
case http.MethodPut:
|
||||
// 更新所有远程黑名单
|
||||
blacklists := s.shieldManager.GetBlacklists()
|
||||
for i := range blacklists {
|
||||
// 更新每个黑名单的时间戳
|
||||
blacklists[i].LastUpdateTime = time.Now().Format(time.RFC3339)
|
||||
// 更新黑名单列表(包括启用/禁用状态)
|
||||
var updatedBlacklists []struct {
|
||||
Name string `json:"Name" json:"name"`
|
||||
URL string `json:"URL" json:"url"`
|
||||
Enabled bool `json:"Enabled" json:"enabled"`
|
||||
LastUpdateTime string `json:"LastUpdateTime" json:"lastUpdateTime"`
|
||||
}
|
||||
|
||||
s.shieldManager.UpdateBlacklist(blacklists)
|
||||
if err := json.NewDecoder(r.Body).Decode(&updatedBlacklists); err != nil {
|
||||
http.Error(w, "Invalid request body", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// 转换为config.BlacklistEntry类型
|
||||
var newBlacklists []config.BlacklistEntry
|
||||
for _, entry := range updatedBlacklists {
|
||||
newBlacklists = append(newBlacklists, config.BlacklistEntry{
|
||||
Name: entry.Name,
|
||||
URL: entry.URL,
|
||||
Enabled: entry.Enabled,
|
||||
LastUpdateTime: entry.LastUpdateTime,
|
||||
})
|
||||
}
|
||||
|
||||
// 更新黑名单
|
||||
s.shieldManager.UpdateBlacklist(newBlacklists)
|
||||
// 更新全局配置中的黑名单
|
||||
s.globalConfig.Shield.Blacklists = blacklists
|
||||
s.globalConfig.Shield.Blacklists = newBlacklists
|
||||
// 保存配置到文件
|
||||
if err := saveConfigToFile(s.globalConfig, "config.json"); err != nil {
|
||||
logger.Error("保存配置文件失败", "error", err)
|
||||
http.Error(w, "保存配置失败", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
// 重新加载所有规则
|
||||
// 重新加载规则
|
||||
s.shieldManager.LoadRules()
|
||||
|
||||
json.NewEncoder(w).Encode(map[string]string{"status": "success"})
|
||||
|
||||
Reference in New Issue
Block a user