Tidy up the REST interface URLs (fixes #1593)

This commit is contained in:
Jakob Borg 2015-04-06 10:23:27 +02:00
parent 5f6a8fdc20
commit e884d0fda6
6 changed files with 127 additions and 118 deletions

View File

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

View File

@ -74,15 +74,15 @@ angular.module('syncthing.core')
refreshDeviceStats(); refreshDeviceStats();
refreshFolderStats(); refreshFolderStats();
$http.get(urlbase + '/version').success(function (data) { $http.get(urlbase + '/system/version').success(function (data) {
$scope.version = data.version; $scope.version = data.version;
}).error($scope.emitHTTPError); }).error($scope.emitHTTPError);
$http.get(urlbase + '/report').success(function (data) { $http.get(urlbase + '/system/report').success(function (data) {
$scope.reportData = data; $scope.reportData = data;
}).error($scope.emitHTTPError); }).error($scope.emitHTTPError);
$http.get(urlbase + '/upgrade').success(function (data) { $http.get(urlbase + '/system/upgrade').success(function (data) {
$scope.upgradeInfo = data; $scope.upgradeInfo = data;
}).error(function () { }).error(function () {
$scope.upgradeInfo = null; $scope.upgradeInfo = null;
@ -198,7 +198,7 @@ angular.module('syncthing.core')
$scope.$on('ConfigSaved', function (event, arg) { $scope.$on('ConfigSaved', function (event, arg) {
updateLocalConfig(arg.data); updateLocalConfig(arg.data);
$http.get(urlbase + '/config/sync').success(function (data) { $http.get(urlbase + '/system/config/insync').success(function (data) {
$scope.configInSync = data.configInSync; $scope.configInSync = data.configInSync;
}).error($scope.emitHTTPError); }).error($scope.emitHTTPError);
}); });
@ -282,7 +282,7 @@ angular.module('syncthing.core')
var key = "refreshFolder" + folder; var key = "refreshFolder" + folder;
if (!debouncedFuncs[key]) { if (!debouncedFuncs[key]) {
debouncedFuncs[key] = debounce(function () { debouncedFuncs[key] = debounce(function () {
$http.get(urlbase + '/model?folder=' + encodeURIComponent(folder)).success(function (data) { $http.get(urlbase + '/db/status?folder=' + encodeURIComponent(folder)).success(function (data) {
$scope.model[folder] = data; $scope.model[folder] = data;
console.log("refreshFolder", folder, data); console.log("refreshFolder", folder, data);
}).error($scope.emitHTTPError); }).error($scope.emitHTTPError);
@ -319,7 +319,7 @@ angular.module('syncthing.core')
} }
function refreshSystem() { function refreshSystem() {
$http.get(urlbase + '/system').success(function (data) { $http.get(urlbase + '/system/status').success(function (data) {
$scope.myID = data.myID; $scope.myID = data.myID;
$scope.system = data; $scope.system = data;
$scope.announceServersTotal = data.extAnnounceOK ? Object.keys(data.extAnnounceOK).length : 0; $scope.announceServersTotal = data.extAnnounceOK ? Object.keys(data.extAnnounceOK).length : 0;
@ -339,7 +339,7 @@ angular.module('syncthing.core')
return; return;
} }
$http.get(urlbase + '/completion?device=' + device + '&folder=' + encodeURIComponent(folder)).success(function (data) { $http.get(urlbase + '/db/completion?device=' + device + '&folder=' + encodeURIComponent(folder)).success(function (data) {
if (!$scope.completion[device]) { if (!$scope.completion[device]) {
$scope.completion[device] = {}; $scope.completion[device] = {};
} }
@ -361,7 +361,7 @@ angular.module('syncthing.core')
} }
function refreshConnectionStats() { function refreshConnectionStats() {
$http.get(urlbase + '/connections').success(function (data) { $http.get(urlbase + '/system/connections').success(function (data) {
var now = Date.now(), var now = Date.now(),
td = (now - prevDate) / 1000, td = (now - prevDate) / 1000,
id; id;
@ -385,25 +385,25 @@ angular.module('syncthing.core')
} }
function refreshErrors() { function refreshErrors() {
$http.get(urlbase + '/errors').success(function (data) { $http.get(urlbase + '/system/errors').success(function (data) {
$scope.errors = data.errors; $scope.errors = data.errors;
console.log("refreshErrors", data); console.log("refreshErrors", data);
}).error($scope.emitHTTPError); }).error($scope.emitHTTPError);
} }
function refreshConfig() { function refreshConfig() {
$http.get(urlbase + '/config').success(function (data) { $http.get(urlbase + '/system/config').success(function (data) {
updateLocalConfig(data); updateLocalConfig(data);
console.log("refreshConfig", data); console.log("refreshConfig", data);
}).error($scope.emitHTTPError); }).error($scope.emitHTTPError);
$http.get(urlbase + '/config/sync').success(function (data) { $http.get(urlbase + '/system/config/insync').success(function (data) {
$scope.configInSync = data.configInSync; $scope.configInSync = data.configInSync;
}).error($scope.emitHTTPError); }).error($scope.emitHTTPError);
} }
function refreshNeed(folder) { function refreshNeed(folder) {
$http.get(urlbase + "/need?folder=" + encodeURIComponent(folder)).success(function (data) { $http.get(urlbase + "/db/need?folder=" + encodeURIComponent(folder)).success(function (data) {
if ($scope.neededFolder == folder) { if ($scope.neededFolder == folder) {
console.log("refreshNeed", folder, data); console.log("refreshNeed", folder, data);
$scope.needed = data; $scope.needed = data;
@ -608,8 +608,8 @@ angular.module('syncthing.core')
'Content-Type': 'application/json' 'Content-Type': 'application/json'
} }
}; };
$http.post(urlbase + '/config', cfg, opts).success(function () { $http.post(urlbase + '/system/config', cfg, opts).success(function () {
$http.get(urlbase + '/config/sync').success(function (data) { $http.get(urlbase + '/system/config/insync').success(function (data) {
$scope.configInSync = data.configInSync; $scope.configInSync = data.configInSync;
}); });
}).error($scope.emitHTTPError); }).error($scope.emitHTTPError);
@ -658,7 +658,7 @@ angular.module('syncthing.core')
$scope.restart = function () { $scope.restart = function () {
restarting = true; restarting = true;
$('#restarting').modal(); $('#restarting').modal();
$http.post(urlbase + '/restart'); $http.post(urlbase + '/system/restart');
$scope.configInSync = true; $scope.configInSync = true;
// Switch webpage protocol if needed // Switch webpage protocol if needed
@ -680,7 +680,7 @@ angular.module('syncthing.core')
$scope.upgrade = function () { $scope.upgrade = function () {
restarting = true; restarting = true;
$('#upgrading').modal(); $('#upgrading').modal();
$http.post(urlbase + '/upgrade').success(function () { $http.post(urlbase + '/system/upgrade').success(function () {
$('#restarting').modal(); $('#restarting').modal();
$('#upgrading').modal('hide'); $('#upgrading').modal('hide');
}).error(function () { }).error(function () {
@ -690,7 +690,7 @@ angular.module('syncthing.core')
$scope.shutdown = function () { $scope.shutdown = function () {
restarting = true; restarting = true;
$http.post(urlbase + '/shutdown').success(function () { $http.post(urlbase + '/system/shutdown').success(function () {
$('#shutdown').modal(); $('#shutdown').modal();
}).error($scope.emitHTTPError); }).error($scope.emitHTTPError);
$scope.configInSync = true; $scope.configInSync = true;
@ -716,7 +716,7 @@ angular.module('syncthing.core')
}; };
$scope.addDevice = function () { $scope.addDevice = function () {
$http.get(urlbase + '/discovery') $http.get(urlbase + '/system/discovery')
.success(function (registry) { .success(function (registry) {
$scope.discovery = registry; $scope.discovery = registry;
}) })
@ -871,7 +871,7 @@ angular.module('syncthing.core')
$scope.clearErrors = function () { $scope.clearErrors = function () {
$scope.seenError = $scope.errors[$scope.errors.length - 1].time; $scope.seenError = $scope.errors[$scope.errors.length - 1].time;
$http.post(urlbase + '/error/clear'); $http.post(urlbase + '/system/error/clear');
}; };
$scope.friendlyDevices = function (str) { $scope.friendlyDevices = function (str) {
@ -889,7 +889,7 @@ angular.module('syncthing.core')
$scope.directoryList = []; $scope.directoryList = [];
$scope.$watch('currentFolder.path', function (newvalue) { $scope.$watch('currentFolder.path', function (newvalue) {
$http.get(urlbase + '/autocomplete/directory', { $http.get(urlbase + '/system/browse', {
params: { current: newvalue } params: { current: newvalue }
}).success(function (data) { }).success(function (data) {
$scope.directoryList = data; $scope.directoryList = data;
@ -1093,7 +1093,7 @@ angular.module('syncthing.core')
} }
$('#editIgnoresButton').attr('disabled', 'disabled'); $('#editIgnoresButton').attr('disabled', 'disabled');
$http.get(urlbase + '/ignores?folder=' + encodeURIComponent($scope.currentFolder.id)) $http.get(urlbase + '/db/ignores?folder=' + encodeURIComponent($scope.currentFolder.id))
.success(function (data) { .success(function (data) {
data.ignore = data.ignore || []; data.ignore = data.ignore || [];
@ -1120,7 +1120,7 @@ angular.module('syncthing.core')
return; return;
} }
$http.post(urlbase + '/ignores?folder=' + encodeURIComponent($scope.currentFolder.id), { $http.post(urlbase + '/db/ignores?folder=' + encodeURIComponent($scope.currentFolder.id), {
ignore: $('#editIgnores textarea').val().split('\n') ignore: $('#editIgnores textarea').val().split('\n')
}); });
}; };
@ -1173,7 +1173,7 @@ angular.module('syncthing.core')
}; };
$scope.override = function (folder) { $scope.override = function (folder) {
$http.post(urlbase + "/model/override?folder=" + encodeURIComponent(folder)); $http.post(urlbase + "/db/override?folder=" + encodeURIComponent(folder));
}; };
$scope.about = function () { $scope.about = function () {
@ -1185,15 +1185,15 @@ angular.module('syncthing.core')
}; };
$scope.rescanAllFolders = function () { $scope.rescanAllFolders = function () {
$http.post(urlbase + "/scan"); $http.post(urlbase + "/db/scan");
}; };
$scope.rescanFolder = function (folder) { $scope.rescanFolder = function (folder) {
$http.post(urlbase + "/scan?folder=" + encodeURIComponent(folder)); $http.post(urlbase + "/db/scan?folder=" + encodeURIComponent(folder));
}; };
$scope.bumpFile = function (folder, file) { $scope.bumpFile = function (folder, file) {
$http.post(urlbase + "/bump?folder=" + encodeURIComponent(folder) + "&file=" + encodeURIComponent(file)).success(function (data) { $http.post(urlbase + "/db/prio?folder=" + encodeURIComponent(folder) + "&file=" + encodeURIComponent(file)).success(function (data) {
if ($scope.neededFolder == folder) { if ($scope.neededFolder == folder) {
console.log("bumpFile", folder, data); console.log("bumpFile", folder, data);
$scope.needed = data; $scope.needed = data;

File diff suppressed because one or more lines are too long

View File

@ -18,18 +18,27 @@ import (
) )
var jsonEndpoints = []string{ var jsonEndpoints = []string{
"/rest/completion?device=I6KAH76-66SLLLB-5PFXSOA-UFJCDZC-YAOMLEK-CP2GB32-BV5RQST-3PSROAU&folder=default", "/rest/db/completion?device=I6KAH76-66SLLLB-5PFXSOA-UFJCDZC-YAOMLEK-CP2GB32-BV5RQST-3PSROAU&folder=default",
"/rest/config", "/rest/db/ignores?folder=default",
"/rest/config/sync", "/rest/db/need?folder=default",
"/rest/connections", "/rest/db/status?folder=default",
"/rest/errors", "/rest/db/browse?folder=default",
"/rest/events", "/rest/events?since=-1&limit=5",
"/rest/lang", "/rest/stats/device",
"/rest/model?folder=default", "/rest/stats/folder",
"/rest/need", "/rest/svc/deviceid?id=I6KAH76-66SLLLB-5PFXSOA-UFJCDZC-YAOMLEK-CP2GB32-BV5RQST-3PSROAU",
"/rest/deviceid?id=I6KAH7666SLLLB5PFXSOAUFJCDZCYAOMLEKCP2GB32BV5RQST3PSROAU", "/rest/svc/lang",
"/rest/report", "/rest/svc/report",
"/rest/system", "/rest/system/browse?current=.",
"/rest/system/config",
"/rest/system/config/insync",
"/rest/system/connections",
"/rest/system/discovery",
"/rest/system/error",
"/rest/system/ping",
"/rest/system/status",
"/rest/system/upgrade",
"/rest/system/version",
} }
func TestGetIndex(t *testing.T) { func TestGetIndex(t *testing.T) {
@ -194,7 +203,7 @@ func TestPOSTWithoutCSRF(t *testing.T) {
// Should fail without CSRF // Should fail without CSRF
req, err := http.NewRequest("POST", "http://127.0.0.1:8082/rest/error/clear", nil) req, err := http.NewRequest("POST", "http://127.0.0.1:8082/rest/system/error/clear", nil)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -241,7 +250,7 @@ func TestPOSTWithoutCSRF(t *testing.T) {
// Should fail with incorrect CSRF // Should fail with incorrect CSRF
req, err = http.NewRequest("POST", "http://127.0.0.1:8082/rest/error/clear", nil) req, err = http.NewRequest("POST", "http://127.0.0.1:8082/rest/system/error/clear", nil)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -45,7 +45,7 @@ func TestManyPeers(t *testing.T) {
} }
defer receiver.stop() defer receiver.stop()
resp, err := receiver.get("/rest/config") resp, err := receiver.get("/rest/system/config")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -70,7 +70,7 @@ func TestManyPeers(t *testing.T) {
var buf bytes.Buffer var buf bytes.Buffer
json.NewEncoder(&buf).Encode(cfg) json.NewEncoder(&buf).Encode(cfg)
resp, err = receiver.post("/rest/config", &buf) resp, err = receiver.post("/rest/system/config", &buf)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -79,7 +79,7 @@ func (p *syncthingProcess) start() error {
for { for {
time.Sleep(250 * time.Millisecond) time.Sleep(250 * time.Millisecond)
resp, err := p.get("/rest/system") resp, err := p.get("/rest/system/status")
if err != nil { if err != nil {
continue continue
} }
@ -89,14 +89,14 @@ func (p *syncthingProcess) start() error {
resp.Body.Close() resp.Body.Close()
if err != nil { if err != nil {
// This one is unexpected. Print it. // This one is unexpected. Print it.
log.Println("/rest/system (JSON):", err) log.Println("/rest/system/status (JSON):", err)
continue continue
} }
id, err := protocol.DeviceIDFromString(sysData["myID"].(string)) id, err := protocol.DeviceIDFromString(sysData["myID"].(string))
if err != nil { if err != nil {
// This one is unexpected. Print it. // This one is unexpected. Print it.
log.Println("/rest/system (myID):", err) log.Println("/rest/system/status (myID):", err)
continue continue
} }
@ -241,7 +241,7 @@ type model struct {
} }
func (p *syncthingProcess) model(folder string) (model, error) { func (p *syncthingProcess) model(folder string) (model, error) {
resp, err := p.get("/rest/model?folder=" + folder) resp, err := p.get("/rest/db/status?folder=" + folder)
if err != nil { if err != nil {
return model{}, err return model{}, err
} }
@ -283,7 +283,7 @@ type versionResp struct {
} }
func (p *syncthingProcess) version() (string, error) { func (p *syncthingProcess) version() (string, error) {
resp, err := p.get("/rest/version") resp, err := p.get("/rest/system/version")
if err != nil { if err != nil {
return "", err return "", err
} }
@ -298,7 +298,7 @@ func (p *syncthingProcess) version() (string, error) {
} }
func (p *syncthingProcess) rescan(folder string) error { func (p *syncthingProcess) rescan(folder string) error {
resp, err := p.post("/rest/scan?folder="+folder, nil) resp, err := p.post("/rest/db/scan?folder="+folder, nil)
if err != nil { if err != nil {
return err return err
} }
@ -311,7 +311,7 @@ func (p *syncthingProcess) rescan(folder string) error {
} }
func (p *syncthingProcess) reset(folder string) error { func (p *syncthingProcess) reset(folder string) error {
resp, err := p.post("/rest/reset?folder="+folder, nil) resp, err := p.post("/rest/system/reset?folder="+folder, nil)
if err != nil { if err != nil {
return err return err
} }