s1
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user