updates
This commit is contained in:
@@ -2,6 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
@@ -39,6 +40,10 @@ func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
case path == "/stacks" && req.Method == http.MethodGet:
|
||||
r.listStacks(w, req)
|
||||
|
||||
// POST /api/stacks/rescan — re-scan stacks directory for new/removed stacks
|
||||
case path == "/stacks/rescan" && req.Method == http.MethodPost:
|
||||
r.rescanStacks(w, req)
|
||||
|
||||
// GET /api/stacks/{name}
|
||||
case strings.HasPrefix(path, "/stacks/") && req.Method == http.MethodGet && !hasSubpath(path, "/stacks/"):
|
||||
r.getStack(w, req, trimSegment(path, "/stacks/"))
|
||||
@@ -91,6 +96,21 @@ func (r *Router) listStacks(w http.ResponseWriter, _ *http.Request) {
|
||||
writeJSON(w, http.StatusOK, apiResponse{OK: true, Data: r.stackMgr.GetStacks()})
|
||||
}
|
||||
|
||||
func (r *Router) rescanStacks(w http.ResponseWriter, _ *http.Request) {
|
||||
r.logger.Printf("[API] Manual stack rescan requested")
|
||||
if err := r.stackMgr.ScanStacks(); err != nil {
|
||||
r.logger.Printf("[API] Stack rescan failed: %v", err)
|
||||
writeJSON(w, http.StatusInternalServerError, apiResponse{OK: false, Error: err.Error()})
|
||||
return
|
||||
}
|
||||
stackCount := len(r.stackMgr.GetStacks())
|
||||
r.logger.Printf("[API] Stack rescan completed: %d stacks found", stackCount)
|
||||
writeJSON(w, http.StatusOK, apiResponse{
|
||||
OK: true,
|
||||
Message: fmt.Sprintf("Rescan completed: %d stacks found", stackCount),
|
||||
})
|
||||
}
|
||||
|
||||
func (r *Router) getStack(w http.ResponseWriter, _ *http.Request, name string) {
|
||||
stack, ok := r.stackMgr.GetStack(name)
|
||||
if !ok {
|
||||
@@ -138,7 +158,7 @@ func (r *Router) deployStack(w http.ResponseWriter, req *http.Request, name stri
|
||||
if strings.Contains(err.Error(), "already deployed") {
|
||||
status = http.StatusConflict
|
||||
}
|
||||
if strings.Contains(err.Error(), "required field") || strings.Contains(err.Error(), "does not exist") {
|
||||
if strings.Contains(err.Error(), "required field") || strings.Contains(err.Error(), "does not exist") || strings.Contains(err.Error(), "kötelező") {
|
||||
status = http.StatusBadRequest
|
||||
}
|
||||
writeJSON(w, status, apiResponse{OK: false, Error: err.Error()})
|
||||
@@ -228,4 +248,4 @@ func writeJSON(w http.ResponseWriter, status int, v interface{}) {
|
||||
if err := json.NewEncoder(w).Encode(v); err != nil {
|
||||
log.Printf("[ERROR] Failed to write JSON response: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user