|
@@ -233,8 +233,8 @@ func (s *apiService) Serve() {
|
|
|
getRestMux.HandleFunc("/rest/db/need", s.getDBNeed) // folder [perpage] [page]
|
|
getRestMux.HandleFunc("/rest/db/need", s.getDBNeed) // folder [perpage] [page]
|
|
|
getRestMux.HandleFunc("/rest/db/status", s.getDBStatus) // folder
|
|
getRestMux.HandleFunc("/rest/db/status", s.getDBStatus) // folder
|
|
|
getRestMux.HandleFunc("/rest/db/browse", s.getDBBrowse) // folder [prefix] [dirsonly] [levels]
|
|
getRestMux.HandleFunc("/rest/db/browse", s.getDBBrowse) // folder [prefix] [dirsonly] [levels]
|
|
|
- getRestMux.HandleFunc("/rest/events", s.getIndexEvents) // since [limit]
|
|
|
|
|
- getRestMux.HandleFunc("/rest/events/disk", s.getDiskEvents) // since [limit]
|
|
|
|
|
|
|
+ getRestMux.HandleFunc("/rest/events", s.getIndexEvents) // since [limit] [timeout]
|
|
|
|
|
+ getRestMux.HandleFunc("/rest/events/disk", s.getDiskEvents) // since [limit] [timeout]
|
|
|
getRestMux.HandleFunc("/rest/stats/device", s.getDeviceStats) // -
|
|
getRestMux.HandleFunc("/rest/stats/device", s.getDeviceStats) // -
|
|
|
getRestMux.HandleFunc("/rest/stats/folder", s.getFolderStats) // -
|
|
getRestMux.HandleFunc("/rest/stats/folder", s.getFolderStats) // -
|
|
|
getRestMux.HandleFunc("/rest/svc/deviceid", s.getDeviceID) // id
|
|
getRestMux.HandleFunc("/rest/svc/deviceid", s.getDeviceID) // id
|
|
@@ -1019,9 +1019,15 @@ func (s *apiService) getEvents(w http.ResponseWriter, r *http.Request, eventSub
|
|
|
qs := r.URL.Query()
|
|
qs := r.URL.Query()
|
|
|
sinceStr := qs.Get("since")
|
|
sinceStr := qs.Get("since")
|
|
|
limitStr := qs.Get("limit")
|
|
limitStr := qs.Get("limit")
|
|
|
|
|
+ timeoutStr := qs.Get("timeout")
|
|
|
since, _ := strconv.Atoi(sinceStr)
|
|
since, _ := strconv.Atoi(sinceStr)
|
|
|
limit, _ := strconv.Atoi(limitStr)
|
|
limit, _ := strconv.Atoi(limitStr)
|
|
|
|
|
|
|
|
|
|
+ timeout := defaultEventTimeout
|
|
|
|
|
+ if timeoutSec, timeoutErr := strconv.Atoi(timeoutStr); timeoutErr == nil && timeoutSec >= 0 { // 0 is a valid timeout
|
|
|
|
|
+ timeout = time.Duration(timeoutSec) * time.Second
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// Flush before blocking, to indicate that we've received the request and
|
|
// Flush before blocking, to indicate that we've received the request and
|
|
|
// that it should not be retried. Must set Content-Type header before
|
|
// that it should not be retried. Must set Content-Type header before
|
|
|
// flushing.
|
|
// flushing.
|
|
@@ -1029,7 +1035,8 @@ func (s *apiService) getEvents(w http.ResponseWriter, r *http.Request, eventSub
|
|
|
f := w.(http.Flusher)
|
|
f := w.(http.Flusher)
|
|
|
f.Flush()
|
|
f.Flush()
|
|
|
|
|
|
|
|
- evs := eventSub.Since(since, nil)
|
|
|
|
|
|
|
+ // If there are no events available return an empty slice, as this gets serialized as `[]`
|
|
|
|
|
+ evs := eventSub.Since(since, []events.Event{}, timeout)
|
|
|
if 0 < limit && limit < len(evs) {
|
|
if 0 < limit && limit < len(evs) {
|
|
|
evs = evs[len(evs)-limit:]
|
|
evs = evs[len(evs)-limit:]
|
|
|
}
|
|
}
|