diff --git a/main.go b/main.go index 738bb2de2..0e74c7cbd 100644 --- a/main.go +++ b/main.go @@ -96,18 +96,49 @@ var cache map[string]interface{} var cacheDate string var cacheMut sync.Mutex +func fileList() ([]string, error) { + files := make(map[string]string) + t0 := time.Now().Add(-24 * time.Hour).Format("20060102") + t1 := time.Now().Format("20060102") + + dir := filepath.Join(*dbDir, t0) + gr, err := filepath.Glob(filepath.Join(dir, "*.json")) + if err != nil { + return nil, err + } + for _, f := range gr { + bn := filepath.Base(f) + files[bn] = f + } + + dir = filepath.Join(*dbDir, t1) + gr, err = filepath.Glob(filepath.Join(dir, "*.json")) + if err != nil { + return nil, err + } + for _, f := range gr { + bn := filepath.Base(f) + files[bn] = f + } + + l := make([]string, 0, len(files)) + for _, f := range files { + l = append(l, f) + } + + return l, nil +} + func reportHandler(w http.ResponseWriter, r *http.Request) { - yesterday := time.Now().Add(-24 * time.Hour).Format("20060102") + cd := time.Now().Format("20060102T15") cacheMut.Lock() cacheMut.Unlock() - if cacheDate != yesterday { + if cacheDate != cd { cache = make(map[string]interface{}) - dir := filepath.Join(*dbDir, yesterday) - - files, err := filepath.Glob(filepath.Join(dir, "*.json")) + files, err := fileList() if err != nil { http.Error(w, "Glob error", 500) return @@ -156,6 +187,7 @@ func reportHandler(w http.ResponseWriter, r *http.Request) { } cache = make(map[string]interface{}) + cache["cache"] = cd cache["nodes"] = nodes cache["versions"] = versions cache["platforms"] = platforms diff --git a/static/index.html b/static/index.html index 5f096f807..4cb52edec 100644 --- a/static/index.html +++ b/static/index.html @@ -29,7 +29,7 @@ found in the LICENSE file.

Syncthing Usage Data

- This is the aggregated usage report data for yesterday. Data based on {{ report.nodes }} nodes that have reported in. + This is the aggregated usage report data for today and yesterday. Data based on {{ report.nodes }} nodes that have reported in.