From e1975644d60f97f18d405d2f37e1230fd2d80dab Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Tue, 17 Mar 2015 17:51:50 +0000 Subject: [PATCH] Add /rest/filestatus --- cmd/syncthing/gui.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/cmd/syncthing/gui.go b/cmd/syncthing/gui.go index eecd2a58..a5169ff6 100644 --- a/cmd/syncthing/gui.go +++ b/cmd/syncthing/gui.go @@ -124,6 +124,7 @@ func startGUI(cfg config.GUIConfiguration, assetDir string, m *model.Model) erro getRestMux.HandleFunc("/rest/tree", withModel(m, restGetTree)) getRestMux.HandleFunc("/rest/stats/device", withModel(m, restGetDeviceStats)) getRestMux.HandleFunc("/rest/stats/folder", withModel(m, restGetFolderStats)) + getRestMux.HandleFunc("/rest/filestatus", withModel(m, restGetFileStatus)) // Debug endpoints, not for general use getRestMux.HandleFunc("/rest/debug/peerCompletion", withModel(m, restGetPeerCompletion)) @@ -365,6 +366,27 @@ func restGetFolderStats(m *model.Model, w http.ResponseWriter, r *http.Request) json.NewEncoder(w).Encode(res) } +func restGetFileStatus(m *model.Model, w http.ResponseWriter, r *http.Request) { + qs := r.URL.Query() + folder := qs.Get("folder") + file := qs.Get("file") + withBlocks := qs.Get("blocks") != "" + gf, _ := m.CurrentGlobalFile(folder, file) + lf, _ := m.CurrentFolderFile(folder, file) + + if !withBlocks { + gf.Blocks = nil + lf.Blocks = nil + } + + av := m.Availability(folder, file) + json.NewEncoder(w).Encode(map[string]interface{}{ + "global": gf, + "local": lf, + "availability": av, + }) +} + func restGetConfig(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json; charset=utf-8") json.NewEncoder(w).Encode(cfg.Raw())