diff --git a/server/stats.go b/server/stats.go index f825a92..091cbd4 100644 --- a/server/stats.go +++ b/server/stats.go @@ -21,6 +21,9 @@ type StatsDisplay struct { Charts []ChartData Libraries []Library SelectedLibrary string + Size []int + Duration []int + Count []int } type ChartData struct { @@ -320,10 +323,27 @@ func handleStats(w http.ResponseWriter, r *http.Request) { return } + var size int + var count int + var duration int + err = db.QueryRow(r.Context(), + `SELECT SUM(size) AS size, + COUNT(id) as count, + 0 as duration + FROM files WHERE ($1 = -1 OR files.library_id = $1) AND status = $2`, id, constants.FILE_STATUS_EXISTS).Scan(&size, &count, &duration) + if err != nil { + size = 0 + count = 0 + duration = 0 + } + buf := bytes.Buffer{} err = templates.ExecuteTemplate(&buf, constants.STATS_TEMPLATE_NAME, StatsDisplay{ Libraries: libraries, SelectedLibrary: id, + Size: splitInt(size), + Count: splitInt(count), + Duration: splitInt(duration), Charts: data, }) if err != nil { diff --git a/tmpl/stats.tmpl b/tmpl/stats.tmpl index 94134ad..0f6b149 100644 --- a/tmpl/stats.tmpl +++ b/tmpl/stats.tmpl @@ -8,6 +8,42 @@ {{end}} + +