moki 8 часов назад
Родитель
Сommit
e68af4bf22
2 измененных файлов с 1 добавлено и 64 удалено
  1. 0 24
      docs/api.md
  2. 1 40
      internal/api/api.go

+ 0 - 24
docs/api.md

@@ -18,7 +18,6 @@ POST /api/event
 ```json
 {
   "code": "busy",
-  "source": "opencode",
   "timestamp": "2026-06-27T14:30:00Z"
 }
 ```
@@ -26,7 +25,6 @@ POST /api/event
 | 字段 | 类型 | 必填 | 说明 |
 |------|------|------|------|
 | code | string | 是 | 状态码 |
-| source | string | 否 | 来源 (opencode/claude/codex) |
 | timestamp | string | 否 | 时间戳 |
 
 **响应示例:**
@@ -66,28 +64,6 @@ GET /api/health
 }
 ```
 
-### 2. 获取所有客户端状态
-
-```
-GET /api/clients
-```
-
-**响应示例:**
-```json
-{
-  "code": 0,
-  "message": "success",
-  "data": [
-    {
-      "port": 4096,
-      "status": "工作中",
-      "code": "busy",
-      "timestamp": "2026-06-03T14:30:00Z"
-    }
-  ]
-}
-```
-
 ### 3. 获取所有 MQTT 配置
 
 ```

+ 1 - 40
internal/api/api.go

@@ -5,7 +5,6 @@ import (
 	"fmt"
 	"io"
 	"net/http"
-	"sort"
 	"strconv"
 	"strings"
 	"sync"
@@ -17,11 +16,6 @@ import (
 	"ai-status-light/internal/web"
 )
 
-type ClientStatus struct {
-	Code      string `json:"code"`
-	Timestamp string `json:"timestamp"`
-}
-
 type EventRequest struct {
 	Code      string `json:"code"`
 	Timestamp string `json:"timestamp,omitempty"`
@@ -38,8 +32,6 @@ type Server struct {
 	server     *http.Server
 	sseClients map[*SSEClient]bool
 	sseMu      sync.Mutex
-	statusMap  map[int]*ClientStatus
-	statusMu   sync.RWMutex
 	certFile   string
 	keyFile    string
 	mqttClient *mqttcli.Client
@@ -56,11 +48,9 @@ func New(db *database.DB, addr string) *Server {
 	s := &Server{
 		db:         db,
 		sseClients: make(map[*SSEClient]bool),
-		statusMap:  make(map[int]*ClientStatus),
 	}
 
 	mux := http.NewServeMux()
-	mux.HandleFunc("/api/clients", s.handleClients)
 	mux.HandleFunc("/api/event", s.handleEvent)
 	mux.HandleFunc("/api/events", s.handleSSE)
 	mux.HandleFunc("/api/mqtt", s.handleMQTT)
@@ -224,15 +214,6 @@ func (s *Server) handleSSE(w http.ResponseWriter, r *http.Request) {
 }
 
 func (s *Server) broadcastSSE(code string) {
-	ts := time.Now().Format(time.RFC3339)
-
-	s.statusMu.Lock()
-	s.statusMap[0] = &ClientStatus{
-		Code:      code,
-		Timestamp: ts,
-	}
-	s.statusMu.Unlock()
-
 	s.sseMu.Lock()
 	defer s.sseMu.Unlock()
 
@@ -242,7 +223,7 @@ func (s *Server) broadcastSSE(code string) {
 
 	payload := map[string]interface{}{
 		"code":      code,
-		"timestamp": ts,
+		"timestamp": time.Now().Format(time.RFC3339),
 	}
 
 	data, err := json.Marshal(payload)
@@ -279,26 +260,6 @@ func (c *SSEClient) Close() {
 	}
 }
 
-func (s *Server) handleClients(w http.ResponseWriter, r *http.Request) {
-	if r.Method != http.MethodGet {
-		writeJSON(w, http.StatusMethodNotAllowed, Response{Code: -1, Message: "方法不允许"})
-		return
-	}
-
-	s.statusMu.RLock()
-	result := make([]*ClientStatus, 0, len(s.statusMap))
-	for _, cs := range s.statusMap {
-		result = append(result, cs)
-	}
-	s.statusMu.RUnlock()
-
-	sort.Slice(result, func(i, j int) bool {
-		return result[i].Code < result[j].Code
-	})
-
-	writeJSON(w, http.StatusOK, Response{Code: 0, Message: "success", Data: result})
-}
-
 func (s *Server) handleMQTT(w http.ResponseWriter, r *http.Request) {
 	logger.Debug("HTTP %s %s", r.Method, r.URL.Path)
 	switch r.Method {