From 760a9d6d352f73558bc0966d8094038eddabce3e Mon Sep 17 00:00:00 2001 From: Audrius Butkevicius Date: Mon, 15 Sep 2014 23:12:29 +0100 Subject: [PATCH] Expose ignores rest endpoints --- cmd/syncthing/gui.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/cmd/syncthing/gui.go b/cmd/syncthing/gui.go index 6aead4795..58c741154 100644 --- a/cmd/syncthing/gui.go +++ b/cmd/syncthing/gui.go @@ -84,6 +84,7 @@ func startGUI(cfg config.GUIConfiguration, assetDir string, m *model.Model) erro getRestMux.HandleFunc("/rest/discovery", restGetDiscovery) getRestMux.HandleFunc("/rest/errors", restGetErrors) getRestMux.HandleFunc("/rest/events", restGetEvents) + getRestMux.HandleFunc("/rest/ignores", withModel(m, restGetIgnores)) getRestMux.HandleFunc("/rest/lang", restGetLang) getRestMux.HandleFunc("/rest/model", withModel(m, restGetModel)) getRestMux.HandleFunc("/rest/model/version", withModel(m, restGetModelVersion)) @@ -105,6 +106,7 @@ func startGUI(cfg config.GUIConfiguration, assetDir string, m *model.Model) erro postRestMux.HandleFunc("/rest/discovery/hint", restPostDiscoveryHint) postRestMux.HandleFunc("/rest/error", restPostError) postRestMux.HandleFunc("/rest/error/clear", restClearErrors) + postRestMux.HandleFunc("/rest/ignores", withModel(m, restPostIgnores)) postRestMux.HandleFunc("/rest/model/override", withModel(m, restPostOverride)) postRestMux.HandleFunc("/rest/reset", restPostReset) postRestMux.HandleFunc("/rest/restart", restPostRestart) @@ -457,6 +459,40 @@ func restGetReport(m *model.Model, w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(reportData(m)) } +func restGetIgnores(m *model.Model, w http.ResponseWriter, r *http.Request) { + qs := r.URL.Query() + w.Header().Set("Content-Type", "application/json; charset=utf-8") + + ignores, err := m.GetIgnores(qs.Get("repo")) + if err != nil { + http.Error(w, err.Error(), 500) + return + } + json.NewEncoder(w).Encode(map[string][]string{ + "ignore": ignores, + }) +} + +func restPostIgnores(m *model.Model, w http.ResponseWriter, r *http.Request) { + qs := r.URL.Query() + + var data map[string][]string + err := json.NewDecoder(r.Body).Decode(&data) + r.Body.Close() + if err != nil { + http.Error(w, err.Error(), 500) + return + } + + err = m.SetIgnores(qs.Get("repo"), data["ignore"]) + if err != nil { + http.Error(w, err.Error(), 500) + return + } + + restGetIgnores(m, w, r) +} + func restGetEvents(w http.ResponseWriter, r *http.Request) { qs := r.URL.Query() sinceStr := qs.Get("since")