From fe7ff6719d3c03ecb5edbde182d2ff4c612f9483 Mon Sep 17 00:00:00 2001 From: tian <11429339@qq.com> Date: Tue, 21 Jul 2026 10:06:48 +0800 Subject: [PATCH] rename: /v1/media-server/* -> /v1/edge-server/* --- cmd/safesightd/main.go | 8 ++++---- internal/api/handlers.go | 20 ++++++++++---------- internal/api/handlers_test.go | 4 ++-- internal/api/openapi.go | 8 ++++---- internal/service/agent_client.go | 2 +- internal/service/task.go | 10 +++++----- internal/service/task_test.go | 4 ++-- internal/web/ui.go | 20 ++++++++++---------- internal/web/ui/templates/console.html | 2 +- internal/web/ui_test.go | 4 ++-- 10 files changed, 41 insertions(+), 41 deletions(-) diff --git a/cmd/safesightd/main.go b/cmd/safesightd/main.go index 48d0906..3df79d1 100644 --- a/cmd/safesightd/main.go +++ b/cmd/safesightd/main.go @@ -140,10 +140,10 @@ func main() { r.Get("/devices/{id}/logs", h.ProxyAgent) r.Post("/devices/{id}/config/apply", h.ProxyAgent) r.Get("/devices/{id}/models", h.ProxyAgent) - r.Post("/devices/{id}/media-server/start", h.ProxyAgent) - r.Post("/devices/{id}/media-server/restart", h.ProxyAgent) - r.Post("/devices/{id}/media-server/stop", h.ProxyAgent) - r.Get("/devices/{id}/media-server/status", h.ProxyAgent) + r.Post("/devices/{id}/edge-server/start", h.ProxyAgent) + r.Post("/devices/{id}/edge-server/restart", h.ProxyAgent) + r.Post("/devices/{id}/edge-server/stop", h.ProxyAgent) + r.Get("/devices/{id}/edge-server/status", h.ProxyAgent) // Generic passthrough for device agent /v1/* (covers config/ui/*, face-gallery, etc.) r.Handle("/devices/{id}/v1/*", http.HandlerFunc(h.ProxyAgentV1)) diff --git a/internal/api/handlers.go b/internal/api/handlers.go index ff1f97f..2e9a1ce 100644 --- a/internal/api/handlers.go +++ b/internal/api/handlers.go @@ -170,22 +170,22 @@ func (h *Handler) ProxyAgent(w http.ResponseWriter, r *http.Request) { agentPath = "/v1/config/candidate/apply" method = "POST" case r.URL.Path == fmt.Sprintf("/api/devices/%s/reload", id): - agentPath = "/v1/media-server/reload" + agentPath = "/v1/edge-server/reload" method = "POST" case r.URL.Path == fmt.Sprintf("/api/devices/%s/rollback", id): - agentPath = "/v1/media-server/rollback" + agentPath = "/v1/edge-server/rollback" method = "POST" - case r.URL.Path == fmt.Sprintf("/api/devices/%s/media-server/start", id): - agentPath = "/v1/media-server/start" + case r.URL.Path == fmt.Sprintf("/api/devices/%s/edge-server/start", id): + agentPath = "/v1/edge-server/start" method = "POST" - case r.URL.Path == fmt.Sprintf("/api/devices/%s/media-server/restart", id): - agentPath = "/v1/media-server/restart" + case r.URL.Path == fmt.Sprintf("/api/devices/%s/edge-server/restart", id): + agentPath = "/v1/edge-server/restart" method = "POST" - case r.URL.Path == fmt.Sprintf("/api/devices/%s/media-server/stop", id): - agentPath = "/v1/media-server/stop" + case r.URL.Path == fmt.Sprintf("/api/devices/%s/edge-server/stop", id): + agentPath = "/v1/edge-server/stop" method = "POST" - case r.URL.Path == fmt.Sprintf("/api/devices/%s/media-server/status", id): - agentPath = "/v1/media-server/status" + case r.URL.Path == fmt.Sprintf("/api/devices/%s/edge-server/status", id): + agentPath = "/v1/edge-server/status" case r.URL.Path == fmt.Sprintf("/api/devices/%s/graphs", id): agentPath = "/v1/graphs" case name != "" && r.URL.Path == fmt.Sprintf("/api/devices/%s/graphs/%s", id, name): diff --git a/internal/api/handlers_test.go b/internal/api/handlers_test.go index 477ba15..ccccde5 100644 --- a/internal/api/handlers_test.go +++ b/internal/api/handlers_test.go @@ -274,8 +274,8 @@ func TestHandler_ProxyAgentMapsLongRunningRollback(t *testing.T) { if r.Method != http.MethodPost { t.Fatalf("expected POST, got %s", r.Method) } - if r.URL.Path != "/v1/media-server/rollback" { - t.Fatalf("expected /v1/media-server/rollback, got %s", r.URL.Path) + if r.URL.Path != "/v1/edge-server/rollback" { + t.Fatalf("expected /v1/edge-server/rollback, got %s", r.URL.Path) } time.Sleep(3500 * time.Millisecond) w.Header().Set("Content-Type", "application/json") diff --git a/internal/api/openapi.go b/internal/api/openapi.go index 6410e16..e7277fe 100644 --- a/internal/api/openapi.go +++ b/internal/api/openapi.go @@ -99,25 +99,25 @@ func OpenAPI(w http.ResponseWriter, r *http.Request) { "responses": map[string]any{"200": map[string]any{"description": "ok"}}, }, }, - "/api/devices/{id}/media-server/start": map[string]any{ + "/api/devices/{id}/edge-server/start": map[string]any{ "post": map[string]any{ "parameters": []any{map[string]any{"name": "id", "in": "path", "required": true, "schema": map[string]any{"type": "string"}}}, "responses": map[string]any{"200": map[string]any{"description": "ok"}}, }, }, - "/api/devices/{id}/media-server/restart": map[string]any{ + "/api/devices/{id}/edge-server/restart": map[string]any{ "post": map[string]any{ "parameters": []any{map[string]any{"name": "id", "in": "path", "required": true, "schema": map[string]any{"type": "string"}}}, "responses": map[string]any{"200": map[string]any{"description": "ok"}}, }, }, - "/api/devices/{id}/media-server/stop": map[string]any{ + "/api/devices/{id}/edge-server/stop": map[string]any{ "post": map[string]any{ "parameters": []any{map[string]any{"name": "id", "in": "path", "required": true, "schema": map[string]any{"type": "string"}}}, "responses": map[string]any{"200": map[string]any{"description": "ok"}}, }, }, - "/api/devices/{id}/media-server/status": map[string]any{ + "/api/devices/{id}/edge-server/status": map[string]any{ "get": map[string]any{ "parameters": []any{map[string]any{"name": "id", "in": "path", "required": true, "schema": map[string]any{"type": "string"}}}, "responses": map[string]any{"200": map[string]any{"description": "status", "content": map[string]any{"application/json": map[string]any{"schema": map[string]any{"type": "object"}}}}}, diff --git a/internal/service/agent_client.go b/internal/service/agent_client.go index 8b3aa74..25d3fa8 100644 --- a/internal/service/agent_client.go +++ b/internal/service/agent_client.go @@ -106,7 +106,7 @@ func isLongOp(method, path string) bool { if method == http.MethodPost && path == "/v1/config/candidate/apply" { return true } - if method == http.MethodPost && path == "/v1/media-server/rollback" { + if method == http.MethodPost && path == "/v1/edge-server/rollback" { return true } if strings.HasPrefix(path, "/v1/config/ui/") { diff --git a/internal/service/task.go b/internal/service/task.go index b7c7cc7..a620ff8 100644 --- a/internal/service/task.go +++ b/internal/service/task.go @@ -323,7 +323,7 @@ func (s *TaskService) executeOnDevice(task *models.Task, did string) { s.appendAuditLog(task, did, models.TaskSuccess, "") case "reload": - _, code, err := s.agent.DoStream("POST", dev.IP, dev.AgentPort, "/v1/media-server/reload", nil, "", 0) + _, code, err := s.agent.DoStream("POST", dev.IP, dev.AgentPort, "/v1/edge-server/reload", nil, "", 0) if err != nil { s.updateDeviceStatus(task.ID, did, models.TaskFailed, 0, err.Error()) return @@ -336,7 +336,7 @@ func (s *TaskService) executeOnDevice(task *models.Task, did string) { s.appendAuditLog(task, did, models.TaskSuccess, "") case "rollback": - _, code, err := s.agent.DoStream("POST", dev.IP, dev.AgentPort, "/v1/media-server/rollback", nil, "", 0) + _, code, err := s.agent.DoStream("POST", dev.IP, dev.AgentPort, "/v1/edge-server/rollback", nil, "", 0) if err != nil { s.updateDeviceStatus(task.ID, did, models.TaskFailed, 0, err.Error()) return @@ -354,7 +354,7 @@ func (s *TaskService) executeOnDevice(task *models.Task, did string) { s.updateDeviceStatus(task.ID, did, models.TaskFailed, 0, err.Error()) return } - _, code, err := s.agent.DoStream("POST", dev.IP, dev.AgentPort, "/v1/media-server/start", bodyR, "", bodyLen) + _, code, err := s.agent.DoStream("POST", dev.IP, dev.AgentPort, "/v1/edge-server/start", bodyR, "", bodyLen) if err != nil { s.updateDeviceStatus(task.ID, did, models.TaskFailed, 0, err.Error()) return @@ -372,7 +372,7 @@ func (s *TaskService) executeOnDevice(task *models.Task, did string) { s.updateDeviceStatus(task.ID, did, models.TaskFailed, 0, err.Error()) return } - _, code, err := s.agent.DoStream("POST", dev.IP, dev.AgentPort, "/v1/media-server/restart", bodyR, "", bodyLen) + _, code, err := s.agent.DoStream("POST", dev.IP, dev.AgentPort, "/v1/edge-server/restart", bodyR, "", bodyLen) if err != nil { s.updateDeviceStatus(task.ID, did, models.TaskFailed, 0, err.Error()) return @@ -385,7 +385,7 @@ func (s *TaskService) executeOnDevice(task *models.Task, did string) { s.appendAuditLog(task, did, models.TaskSuccess, "") case "media_stop": - _, code, err := s.agent.DoStream("POST", dev.IP, dev.AgentPort, "/v1/media-server/stop", nil, "", 0) + _, code, err := s.agent.DoStream("POST", dev.IP, dev.AgentPort, "/v1/edge-server/stop", nil, "", 0) if err != nil { s.updateDeviceStatus(task.ID, did, models.TaskFailed, 0, err.Error()) return diff --git a/internal/service/task_test.go b/internal/service/task_test.go index 05ec2d6..d9ef196 100644 --- a/internal/service/task_test.go +++ b/internal/service/task_test.go @@ -147,8 +147,8 @@ func TestTaskService_MediaStart_IgnoresInvalidConfigShape(t *testing.T) { if r.Method != http.MethodPost { t.Fatalf("expected POST, got %s", r.Method) } - if r.URL.Path != "/v1/media-server/start" { - t.Fatalf("expected path /v1/media-server/start, got %s", r.URL.Path) + if r.URL.Path != "/v1/edge-server/start" { + t.Fatalf("expected path /v1/edge-server/start, got %s", r.URL.Path) } bodyBytes, _ = io.ReadAll(r.Body) w.WriteHeader(http.StatusOK) diff --git a/internal/web/ui.go b/internal/web/ui.go index 86534b2..83533cb 100644 --- a/internal/web/ui.go +++ b/internal/web/ui.go @@ -819,8 +819,8 @@ func (u *UI) Routes() (chi.Router, error) { r.Post("/devices/{id}/face-gallery/upload", u.actionDeviceFaceGalleryUpload) r.Post("/devices/{id}/face-gallery/reload", u.actionDeviceFaceGalleryReload) r.Post("/devices/{id}/models/upload", u.actionDeviceModelUpload) - r.Post("/devices/{id}/media-server/configs/upload", u.actionDeviceMediaServerConfigUpload) - r.Post("/devices/{id}/media-server/configs/upload-batch", u.actionDeviceMediaServerConfigUploadBatch) + r.Post("/devices/{id}/edge-server/configs/upload", u.actionDeviceMediaServerConfigUpload) + r.Post("/devices/{id}/edge-server/configs/upload-batch", u.actionDeviceMediaServerConfigUploadBatch) r.Get("/tasks", u.pageTasks) r.Post("/tasks", u.actionCreateTask) @@ -1773,18 +1773,18 @@ func (u *UI) actionDeviceAction(w http.ResponseWriter, r *http.Request) { path := "" switch action { case "reload": - path = "/v1/media-server/reload" + path = "/v1/edge-server/reload" case "rollback": - path = "/v1/media-server/rollback" + path = "/v1/edge-server/rollback" case "media_start": - path = "/v1/media-server/start" + path = "/v1/edge-server/start" case "media_restart": - path = "/v1/media-server/restart" + path = "/v1/edge-server/restart" case "media_stop": - path = "/v1/media-server/stop" + path = "/v1/edge-server/stop" case "media_status": method = "GET" - path = "/v1/media-server/status" + path = "/v1/edge-server/status" case "info": method = "GET" path = "/v1/info" @@ -1980,7 +1980,7 @@ func (u *UI) actionDeviceMediaServerConfigUpload(w http.ResponseWriter, r *http. } defer file.Close() - path := "/v1/media-server/configs/" + url.PathEscape(name) + path := "/v1/edge-server/configs/" + url.PathEscape(name) resp, code, derr := u.agent.DoStream("PUT", dev.IP, dev.AgentPort, path, file, "application/json", hdr.Size) data := PageData{Title: "设备详情", Device: dev, Message: fmt.Sprintf("PUT %s -> %d", path, code), RawText: string(resp)} if derr != nil { @@ -2026,7 +2026,7 @@ func (u *UI) actionDeviceMediaServerConfigUploadBatch(w http.ResponseWriter, r * sb.WriteString(fmt.Sprintf("%s -> open failed: %v\n", name, err)) continue } - path := "/v1/media-server/configs/" + url.PathEscape(name) + path := "/v1/edge-server/configs/" + url.PathEscape(name) resp, code, derr := u.agent.DoStream("PUT", dev.IP, dev.AgentPort, path, file, "application/json", hdr.Size) _ = file.Close() if derr != nil { diff --git a/internal/web/ui/templates/console.html b/internal/web/ui/templates/console.html index 58ccf9d..8e9ae6f 100644 --- a/internal/web/ui/templates/console.html +++ b/internal/web/ui/templates/console.html @@ -365,7 +365,7 @@ overlay.style.cssText = 'position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,0.5);z-index:9999;display:flex;align-items:center;justify-content:center'; overlay.innerHTML = '