|
@@ -109,47 +109,47 @@ func startGUI(cfg config.GUIConfiguration, assetDir string, m *model.Model) erro
|
|
|
|
|
|
// The GET handlers
|
|
|
getRestMux := http.NewServeMux()
|
|
|
- getRestMux.HandleFunc("/rest/ping", restPing)
|
|
|
- getRestMux.HandleFunc("/rest/completion", withModel(m, restGetCompletion))
|
|
|
- getRestMux.HandleFunc("/rest/config", restGetConfig)
|
|
|
- getRestMux.HandleFunc("/rest/config/sync", restGetConfigInSync)
|
|
|
- getRestMux.HandleFunc("/rest/connections", withModel(m, restGetConnections))
|
|
|
- getRestMux.HandleFunc("/rest/autocomplete/directory", restGetAutocompleteDirectory)
|
|
|
- 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/need", withModel(m, restGetNeed))
|
|
|
- getRestMux.HandleFunc("/rest/deviceid", restGetDeviceID)
|
|
|
- getRestMux.HandleFunc("/rest/report", withModel(m, restGetReport))
|
|
|
- getRestMux.HandleFunc("/rest/system", restGetSystem)
|
|
|
- getRestMux.HandleFunc("/rest/upgrade", restGetUpgrade)
|
|
|
- getRestMux.HandleFunc("/rest/version", restGetVersion)
|
|
|
- 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))
|
|
|
+ getRestMux.HandleFunc("/rest/db/completion", withModel(m, restGetDBCompletion)) // device folder
|
|
|
+ getRestMux.HandleFunc("/rest/db/file", withModel(m, restGetDBFile)) // folder file [blocks]
|
|
|
+ getRestMux.HandleFunc("/rest/db/ignores", withModel(m, restGetDBIgnores)) // folder
|
|
|
+ getRestMux.HandleFunc("/rest/db/need", withModel(m, restGetDBNeed)) // folder
|
|
|
+ getRestMux.HandleFunc("/rest/db/status", withModel(m, restGetDBStatus)) // folder
|
|
|
+ getRestMux.HandleFunc("/rest/db/browse", withModel(m, restGetDBBrowse)) // folder [prefix] [dirsonly] [levels]
|
|
|
+ getRestMux.HandleFunc("/rest/events", restGetEvents) // since [limit]
|
|
|
+ getRestMux.HandleFunc("/rest/stats/device", withModel(m, restGetDeviceStats)) // -
|
|
|
+ getRestMux.HandleFunc("/rest/stats/folder", withModel(m, restGetFolderStats)) // -
|
|
|
+ getRestMux.HandleFunc("/rest/svc/deviceid", restGetDeviceID) // id
|
|
|
+ getRestMux.HandleFunc("/rest/svc/lang", restGetLang) // -
|
|
|
+ getRestMux.HandleFunc("/rest/svc/report", withModel(m, restGetReport)) // -
|
|
|
+ getRestMux.HandleFunc("/rest/system/browse", restGetSystemBrowse) // current
|
|
|
+ getRestMux.HandleFunc("/rest/system/config", restGetSystemConfig) // -
|
|
|
+ getRestMux.HandleFunc("/rest/system/config/insync", RestGetSystemConfigInsync) // -
|
|
|
+ getRestMux.HandleFunc("/rest/system/connections", withModel(m, restGetSystemConnections)) // -
|
|
|
+ getRestMux.HandleFunc("/rest/system/discovery", restGetSystemDiscovery) // -
|
|
|
+ getRestMux.HandleFunc("/rest/system/error", restGetSystemError) // -
|
|
|
+ getRestMux.HandleFunc("/rest/system/ping", restPing) // -
|
|
|
+ getRestMux.HandleFunc("/rest/system/status", restGetSystemStatus) // -
|
|
|
+ getRestMux.HandleFunc("/rest/system/upgrade", restGetSystemUpgrade) // -
|
|
|
+ getRestMux.HandleFunc("/rest/system/version", restGetSystemVersion) // -
|
|
|
|
|
|
// The POST handlers
|
|
|
postRestMux := http.NewServeMux()
|
|
|
- postRestMux.HandleFunc("/rest/ping", restPing)
|
|
|
- postRestMux.HandleFunc("/rest/config", withModel(m, restPostConfig))
|
|
|
- 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", withModel(m, restPostReset))
|
|
|
- postRestMux.HandleFunc("/rest/restart", restPostRestart)
|
|
|
- postRestMux.HandleFunc("/rest/shutdown", restPostShutdown)
|
|
|
- postRestMux.HandleFunc("/rest/upgrade", restPostUpgrade)
|
|
|
- postRestMux.HandleFunc("/rest/scan", withModel(m, restPostScan))
|
|
|
- postRestMux.HandleFunc("/rest/bump", withModel(m, restPostBump))
|
|
|
+ postRestMux.HandleFunc("/rest/db/prio", withModel(m, restPostDBPrio)) // folder file
|
|
|
+ postRestMux.HandleFunc("/rest/db/ignores", withModel(m, restPostDBIgnores)) // folder
|
|
|
+ postRestMux.HandleFunc("/rest/db/override", withModel(m, restPostDBOverride)) // folder
|
|
|
+ postRestMux.HandleFunc("/rest/db/scan", withModel(m, restPostDBScan)) // folder [sub...]
|
|
|
+ postRestMux.HandleFunc("/rest/system/config", withModel(m, restPostSystemConfig)) // <body>
|
|
|
+ postRestMux.HandleFunc("/rest/system/discovery", restPostSystemDiscovery) // device addr
|
|
|
+ postRestMux.HandleFunc("/rest/system/error", restPostSystemError) // <body>
|
|
|
+ postRestMux.HandleFunc("/rest/system/error/clear", restPostSystemErrorClear) // -
|
|
|
+ postRestMux.HandleFunc("/rest/system/ping", restPing) // -
|
|
|
+ postRestMux.HandleFunc("/rest/system/reset", withModel(m, restPostSystemReset)) // [folder]
|
|
|
+ postRestMux.HandleFunc("/rest/system/restart", restPostSystemRestart) // -
|
|
|
+ postRestMux.HandleFunc("/rest/system/shutdown", restPostSystemShutdown) // -
|
|
|
+ postRestMux.HandleFunc("/rest/system/upgrade", restPostSystemUpgrade) // -
|
|
|
+
|
|
|
+ // Debug endpoints, not for general use
|
|
|
+ getRestMux.HandleFunc("/rest/debug/peerCompletion", withModel(m, restGetPeerCompletion))
|
|
|
|
|
|
// A handler that splits requests between the two above and disables
|
|
|
// caching
|
|
@@ -254,7 +254,7 @@ func restPing(w http.ResponseWriter, r *http.Request) {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-func restGetVersion(w http.ResponseWriter, r *http.Request) {
|
|
|
+func restGetSystemVersion(w http.ResponseWriter, r *http.Request) {
|
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
|
json.NewEncoder(w).Encode(map[string]string{
|
|
|
"version": Version,
|
|
@@ -264,7 +264,7 @@ func restGetVersion(w http.ResponseWriter, r *http.Request) {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-func restGetTree(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|
|
+func restGetDBBrowse(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|
|
qs := r.URL.Query()
|
|
|
folder := qs.Get("folder")
|
|
|
prefix := qs.Get("prefix")
|
|
@@ -282,7 +282,7 @@ func restGetTree(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|
|
json.NewEncoder(w).Encode(tree)
|
|
|
}
|
|
|
|
|
|
-func restGetCompletion(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|
|
+func restGetDBCompletion(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|
|
var qs = r.URL.Query()
|
|
|
var folder = qs.Get("folder")
|
|
|
var deviceStr = qs.Get("device")
|
|
@@ -301,7 +301,7 @@ func restGetCompletion(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|
|
json.NewEncoder(w).Encode(res)
|
|
|
}
|
|
|
|
|
|
-func restGetModel(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|
|
+func restGetDBStatus(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|
|
qs := r.URL.Query()
|
|
|
folder := qs.Get("folder")
|
|
|
res := folderSummary(m, folder)
|
|
@@ -340,13 +340,13 @@ func folderSummary(m *model.Model, folder string) map[string]interface{} {
|
|
|
return res
|
|
|
}
|
|
|
|
|
|
-func restPostOverride(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|
|
+func restPostDBOverride(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|
|
var qs = r.URL.Query()
|
|
|
var folder = qs.Get("folder")
|
|
|
go m.Override(folder)
|
|
|
}
|
|
|
|
|
|
-func restGetNeed(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|
|
+func restGetDBNeed(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|
|
var qs = r.URL.Query()
|
|
|
var folder = qs.Get("folder")
|
|
|
|
|
@@ -362,7 +362,7 @@ func restGetNeed(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|
|
json.NewEncoder(w).Encode(output)
|
|
|
}
|
|
|
|
|
|
-func restGetConnections(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|
|
+func restGetSystemConnections(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|
|
var res = m.ConnectionStats()
|
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
|
json.NewEncoder(w).Encode(res)
|
|
@@ -380,7 +380,7 @@ 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) {
|
|
|
+func restGetDBFile(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|
|
qs := r.URL.Query()
|
|
|
folder := qs.Get("folder")
|
|
|
file := qs.Get("file")
|
|
@@ -401,12 +401,12 @@ func restGetFileStatus(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-func restGetConfig(w http.ResponseWriter, r *http.Request) {
|
|
|
+func restGetSystemConfig(w http.ResponseWriter, r *http.Request) {
|
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
|
json.NewEncoder(w).Encode(cfg.Raw())
|
|
|
}
|
|
|
|
|
|
-func restPostConfig(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|
|
+func restPostSystemConfig(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|
|
var newCfg config.Configuration
|
|
|
err := json.NewDecoder(r.Body).Decode(&newCfg)
|
|
|
if err != nil {
|
|
@@ -453,17 +453,17 @@ func restPostConfig(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|
|
cfg.Save()
|
|
|
}
|
|
|
|
|
|
-func restGetConfigInSync(w http.ResponseWriter, r *http.Request) {
|
|
|
+func RestGetSystemConfigInsync(w http.ResponseWriter, r *http.Request) {
|
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
|
json.NewEncoder(w).Encode(map[string]bool{"configInSync": configInSync})
|
|
|
}
|
|
|
|
|
|
-func restPostRestart(w http.ResponseWriter, r *http.Request) {
|
|
|
+func restPostSystemRestart(w http.ResponseWriter, r *http.Request) {
|
|
|
flushResponse(`{"ok": "restarting"}`, w)
|
|
|
go restart()
|
|
|
}
|
|
|
|
|
|
-func restPostReset(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|
|
+func restPostSystemReset(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|
|
var qs = r.URL.Query()
|
|
|
folder := qs.Get("folder")
|
|
|
var err error
|
|
@@ -484,7 +484,7 @@ func restPostReset(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|
|
go restart()
|
|
|
}
|
|
|
|
|
|
-func restPostShutdown(w http.ResponseWriter, r *http.Request) {
|
|
|
+func restPostSystemShutdown(w http.ResponseWriter, r *http.Request) {
|
|
|
flushResponse(`{"ok": "shutting down"}`, w)
|
|
|
go shutdown()
|
|
|
}
|
|
@@ -498,7 +498,7 @@ func flushResponse(s string, w http.ResponseWriter) {
|
|
|
var cpuUsagePercent [10]float64 // The last ten seconds
|
|
|
var cpuUsageLock sync.RWMutex
|
|
|
|
|
|
-func restGetSystem(w http.ResponseWriter, r *http.Request) {
|
|
|
+func restGetSystemStatus(w http.ResponseWriter, r *http.Request) {
|
|
|
var m runtime.MemStats
|
|
|
runtime.ReadMemStats(&m)
|
|
|
|
|
@@ -526,20 +526,20 @@ func restGetSystem(w http.ResponseWriter, r *http.Request) {
|
|
|
json.NewEncoder(w).Encode(res)
|
|
|
}
|
|
|
|
|
|
-func restGetErrors(w http.ResponseWriter, r *http.Request) {
|
|
|
+func restGetSystemError(w http.ResponseWriter, r *http.Request) {
|
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
|
guiErrorsMut.Lock()
|
|
|
json.NewEncoder(w).Encode(map[string][]guiError{"errors": guiErrors})
|
|
|
guiErrorsMut.Unlock()
|
|
|
}
|
|
|
|
|
|
-func restPostError(w http.ResponseWriter, r *http.Request) {
|
|
|
+func restPostSystemError(w http.ResponseWriter, r *http.Request) {
|
|
|
bs, _ := ioutil.ReadAll(r.Body)
|
|
|
r.Body.Close()
|
|
|
showGuiError(0, string(bs))
|
|
|
}
|
|
|
|
|
|
-func restClearErrors(w http.ResponseWriter, r *http.Request) {
|
|
|
+func restPostSystemErrorClear(w http.ResponseWriter, r *http.Request) {
|
|
|
guiErrorsMut.Lock()
|
|
|
guiErrors = []guiError{}
|
|
|
guiErrorsMut.Unlock()
|
|
@@ -554,7 +554,7 @@ func showGuiError(l logger.LogLevel, err string) {
|
|
|
guiErrorsMut.Unlock()
|
|
|
}
|
|
|
|
|
|
-func restPostDiscoveryHint(w http.ResponseWriter, r *http.Request) {
|
|
|
+func restPostSystemDiscovery(w http.ResponseWriter, r *http.Request) {
|
|
|
var qs = r.URL.Query()
|
|
|
var device = qs.Get("device")
|
|
|
var addr = qs.Get("addr")
|
|
@@ -563,7 +563,7 @@ func restPostDiscoveryHint(w http.ResponseWriter, r *http.Request) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func restGetDiscovery(w http.ResponseWriter, r *http.Request) {
|
|
|
+func restGetSystemDiscovery(w http.ResponseWriter, r *http.Request) {
|
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
|
devices := map[string][]discover.CacheEntry{}
|
|
|
|
|
@@ -584,7 +584,7 @@ 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) {
|
|
|
+func restGetDBIgnores(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|
|
qs := r.URL.Query()
|
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
|
|
|
@@ -600,7 +600,7 @@ func restGetIgnores(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-func restPostIgnores(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|
|
+func restPostDBIgnores(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|
|
qs := r.URL.Query()
|
|
|
|
|
|
var data map[string][]string
|
|
@@ -618,7 +618,7 @@ func restPostIgnores(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- restGetIgnores(m, w, r)
|
|
|
+ restGetDBIgnores(m, w, r)
|
|
|
}
|
|
|
|
|
|
func restGetEvents(w http.ResponseWriter, r *http.Request) {
|
|
@@ -647,7 +647,7 @@ func restGetEvents(w http.ResponseWriter, r *http.Request) {
|
|
|
json.NewEncoder(w).Encode(evs)
|
|
|
}
|
|
|
|
|
|
-func restGetUpgrade(w http.ResponseWriter, r *http.Request) {
|
|
|
+func restGetSystemUpgrade(w http.ResponseWriter, r *http.Request) {
|
|
|
if noUpgrade {
|
|
|
http.Error(w, upgrade.ErrUpgradeUnsupported.Error(), 500)
|
|
|
return
|
|
@@ -693,7 +693,7 @@ func restGetLang(w http.ResponseWriter, r *http.Request) {
|
|
|
json.NewEncoder(w).Encode(langs)
|
|
|
}
|
|
|
|
|
|
-func restPostUpgrade(w http.ResponseWriter, r *http.Request) {
|
|
|
+func restPostSystemUpgrade(w http.ResponseWriter, r *http.Request) {
|
|
|
rel, err := upgrade.LatestGithubRelease(Version)
|
|
|
if err != nil {
|
|
|
l.Warnln("getting latest release:", err)
|
|
@@ -715,7 +715,7 @@ func restPostUpgrade(w http.ResponseWriter, r *http.Request) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func restPostScan(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|
|
+func restPostDBScan(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|
|
qs := r.URL.Query()
|
|
|
folder := qs.Get("folder")
|
|
|
if folder != "" {
|
|
@@ -733,12 +733,12 @@ func restPostScan(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func restPostBump(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|
|
+func restPostDBPrio(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|
|
qs := r.URL.Query()
|
|
|
folder := qs.Get("folder")
|
|
|
file := qs.Get("file")
|
|
|
m.BringToFront(folder, file)
|
|
|
- restGetNeed(m, w, r)
|
|
|
+ restGetDBNeed(m, w, r)
|
|
|
}
|
|
|
|
|
|
func getQR(w http.ResponseWriter, r *http.Request) {
|
|
@@ -779,7 +779,7 @@ func restGetPeerCompletion(m *model.Model, w http.ResponseWriter, r *http.Reques
|
|
|
json.NewEncoder(w).Encode(comp)
|
|
|
}
|
|
|
|
|
|
-func restGetAutocompleteDirectory(w http.ResponseWriter, r *http.Request) {
|
|
|
+func restGetSystemBrowse(w http.ResponseWriter, r *http.Request) {
|
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
|
qs := r.URL.Query()
|
|
|
current := qs.Get("current")
|