Server qr fixes.
Some checks failed
CI / Test (1.23) (push) Failing after -25m23s
CI / Test (1.22) (push) Failing after -25m21s
CI / Build (push) Failing after -25m59s
CI / Lint (push) Successful in -25m51s

This commit is contained in:
2025-12-29 22:44:10 +02:00
parent 94fc899bab
commit fd2527219e
7 changed files with 202 additions and 76 deletions

View File

@@ -38,10 +38,63 @@ func (h *Handlers) AddAccount(w http.ResponseWriter, r *http.Request) {
h.config.WhatsApp = append(h.config.WhatsApp, account)
if h.configPath != "" {
if err := config.Save(h.configPath, h.config); err != nil {
logging.Error("Failed to save config", "error", err)
logging.Error("Failed to save config after adding account", "account_id", account.ID, "error", err)
} else {
logging.Info("Config saved after adding account", "account_id", account.ID)
}
}
w.WriteHeader(http.StatusCreated)
writeJSON(w, map[string]string{"status": "ok", "account_id": account.ID})
}
// RemoveAccount removes a WhatsApp account from the system
func (h *Handlers) RemoveAccount(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
var req struct {
ID string `json:"id"`
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
// Disconnect the account
if err := h.whatsappMgr.Disconnect(req.ID); err != nil {
logging.Warn("Failed to disconnect account during removal", "account_id", req.ID, "error", err)
// Continue with removal even if disconnect fails
}
// Remove from config
found := false
newAccounts := make([]config.WhatsAppConfig, 0)
for _, acc := range h.config.WhatsApp {
if acc.ID != req.ID {
newAccounts = append(newAccounts, acc)
} else {
found = true
}
}
if !found {
http.Error(w, "Account not found", http.StatusNotFound)
return
}
h.config.WhatsApp = newAccounts
// Save config
if h.configPath != "" {
if err := config.Save(h.configPath, h.config); err != nil {
logging.Error("Failed to save config after removing account", "account_id", req.ID, "error", err)
} else {
logging.Info("Config saved after removing account", "account_id", req.ID)
}
}
writeJSON(w, map[string]string{"status": "ok"})
}