feat: add GET and POST /preferences route

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
ashisgreat22 2026-03-22 13:53:23 +01:00
parent b4053b7f98
commit 70818558cd
2 changed files with 25 additions and 0 deletions

View file

@ -84,6 +84,8 @@ func main() {
mux.HandleFunc("/healthz", h.Healthz) mux.HandleFunc("/healthz", h.Healthz)
mux.HandleFunc("/search", h.Search) mux.HandleFunc("/search", h.Search)
mux.HandleFunc("/autocompleter", h.Autocompleter) mux.HandleFunc("/autocompleter", h.Autocompleter)
mux.HandleFunc("/preferences", h.Preferences)
mux.HandleFunc("POST /preferences", h.PreferencesPOST)
mux.HandleFunc("/opensearch.xml", h.OpenSearch(cfg.Server.BaseURL)) mux.HandleFunc("/opensearch.xml", h.OpenSearch(cfg.Server.BaseURL))
// Serve embedded static files (CSS, JS, images). // Serve embedded static files (CSS, JS, images).

View file

@ -142,3 +142,26 @@ func (h *Handler) Autocompleter(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json; charset=utf-8")
_ = json.NewEncoder(w).Encode(suggestions) _ = json.NewEncoder(w).Encode(suggestions)
} }
// Preferences renders the preferences page.
func (h *Handler) Preferences(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/preferences" {
http.NotFound(w, r)
return
}
if err := views.RenderPreferences(w, h.sourceURL); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
// PreferencesPOST handles form submission from the preferences page.
// NOTE: This is a no-op. All preferences are stored in localStorage on the client
// via JavaScript. This handler exists only for form submission completeness (e.g.,
// if a form POSTs without JS). The JavaScript in settings.js handles all saves.
func (h *Handler) PreferencesPOST(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/preferences" {
http.NotFound(w, r)
return
}
http.Redirect(w, r, "/preferences", http.StatusFound)
}