This commit is contained in:
Kar
2026-02-01 20:38:58 +05:30
parent 52265ed4cc
commit 5e563fb436
11 changed files with 159 additions and 51 deletions

View File

@@ -33,7 +33,6 @@ func (s *HTTPServer) Start(addr string) error {
// API routes
mux.HandleFunc("/api/repos", s.handleRepos)
mux.HandleFunc("/api/repos/", s.handleRepo)
mux.HandleFunc("/api/repos/", s.handleRepoActions)
// SSE endpoint
@@ -94,20 +93,35 @@ func (s *HTTPServer) handleRepoActions(w http.ResponseWriter, r *http.Request) {
return
}
action := extractAction(r.URL.Path)
switch r.Method {
case http.MethodPost:
switch action {
case "stop":
s.stopRepo(w, r, repoID)
case "restart":
s.restartRepo(w, r, repoID)
// Check if this is an action endpoint
parts := strings.Split(r.URL.Path, "/")
if len(parts) >= 5 {
// This is an action endpoint (/api/repos/{id}/{action})
action := extractAction(r.URL.Path)
switch r.Method {
case http.MethodPost:
switch action {
case "stop":
s.stopRepo(w, r, repoID)
case "restart":
s.restartRepo(w, r, repoID)
default:
http.Error(w, "Invalid action", http.StatusBadRequest)
}
default:
http.Error(w, "Invalid action", http.StatusBadRequest)
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
}
} else {
// This is a repo detail endpoint (/api/repos/{id})
switch r.Method {
case http.MethodGet:
s.getRepo(w, r, repoID)
case http.MethodDelete:
s.deleteRepo(w, r, repoID)
default:
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
}
default:
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
}
}