- Fix issues with new setup

- Fix arr setup getting thr wrong crendentials
- Add file link invalidator
- Other minor bug fixes
This commit is contained in:
Mukhtar Akere
2025-10-08 08:13:13 +01:00
parent 22dae9efad
commit 700d00b802
29 changed files with 606 additions and 465 deletions

View File

@@ -12,16 +12,16 @@ import (
func (wb *Web) setupMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
cfg := config.Get()
needsAuth := cfg.NeedsSetup()
if needsAuth != nil && r.URL.Path != "/config" && r.URL.Path != "/api/config" {
http.Redirect(w, r, fmt.Sprintf("/config?inco=%s", needsAuth.Error()), http.StatusSeeOther)
needsSetup := cfg.CheckSetup()
if needsSetup != nil && r.URL.Path != "/settings" && r.URL.Path != "/api/config" {
http.Redirect(w, r, fmt.Sprintf("/settings?inco=%s", needsSetup.Error()), http.StatusSeeOther)
return
}
// strip inco from URL
if inco := r.URL.Query().Get("inco"); inco != "" && needsAuth == nil && r.URL.Path == "/config" {
if inco := r.URL.Query().Get("inco"); inco != "" && needsSetup == nil && r.URL.Path == "/settings" {
// redirect to the same URL without the inco parameter
http.Redirect(w, r, "/config", http.StatusSeeOther)
http.Redirect(w, r, "/settings", http.StatusSeeOther)
}
next.ServeHTTP(w, r)
})
@@ -79,8 +79,11 @@ func (wb *Web) isAPIRequest(r *http.Request) bool {
func (wb *Web) sendJSONError(w http.ResponseWriter, message string, statusCode int) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(statusCode)
json.NewEncoder(w).Encode(map[string]interface{}{
err := json.NewEncoder(w).Encode(map[string]interface{}{
"error": message,
"status": statusCode,
})
if err != nil {
return
}
}