更新Web文件
This commit is contained in:
@@ -46,6 +46,7 @@ func (s *Server) Start() error {
|
||||
mux.HandleFunc("/api/config", s.handleConfig)
|
||||
// 添加统计相关接口
|
||||
mux.HandleFunc("/api/top-blocked", s.handleTopBlockedDomains)
|
||||
mux.HandleFunc("/api/top-resolved", s.handleTopResolvedDomains)
|
||||
mux.HandleFunc("/api/recent-blocked", s.handleRecentBlockedDomains)
|
||||
mux.HandleFunc("/api/hourly-stats", s.handleHourlyStats)
|
||||
}
|
||||
@@ -114,6 +115,28 @@ func (s *Server) handleTopBlockedDomains(w http.ResponseWriter, r *http.Request)
|
||||
json.NewEncoder(w).Encode(result)
|
||||
}
|
||||
|
||||
// handleTopResolvedDomains 处理获取最常解析的域名请求
|
||||
func (s *Server) handleTopResolvedDomains(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
domains := s.dnsServer.GetTopResolvedDomains(10)
|
||||
|
||||
// 转换为前端需要的格式
|
||||
result := make([]map[string]interface{}, len(domains))
|
||||
for i, domain := range domains {
|
||||
result[i] = map[string]interface{}{
|
||||
"domain": domain.Domain,
|
||||
"count": domain.Count,
|
||||
}
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(result)
|
||||
}
|
||||
|
||||
// handleRecentBlockedDomains 处理最近屏蔽域名请求
|
||||
func (s *Server) handleRecentBlockedDomains(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
|
||||
Reference in New Issue
Block a user