From 9461fe8874ebbbed97d1ba3b624a6a87d1e11a37 Mon Sep 17 00:00:00 2001 From: olokos <1755581+olokos@users.noreply.github.com> Date: Fri, 9 Sep 2022 23:38:26 +0200 Subject: [PATCH] Improve recorded videos dasboard counter Implemented new `util` function, which gets count of only `.mp4` extension. This solves the problem of folders being counted as recordings on the dashboard. --- machinery/src/routers/http/Routes.go | 2 +- machinery/src/utils/main.go | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/machinery/src/routers/http/Routes.go b/machinery/src/routers/http/Routes.go index e772388..d684192 100644 --- a/machinery/src/routers/http/Routes.go +++ b/machinery/src/routers/http/Routes.go @@ -73,7 +73,7 @@ func AddRoutes(r *gin.Engine, authMiddleware *jwt.GinJWTMiddleware, configuratio // The total number of recordings stored in the directory. recordingDirectory := "./data/recordings" - numberOfRecordings := utils.NumberOfFilesInDirectory(recordingDirectory) + numberOfRecordings := utils.NumberOfMP4sInDirectory(recordingDirectory) // All days stored in this agent. days := []string{} diff --git a/machinery/src/utils/main.go b/machinery/src/utils/main.go index 96a4fa5..9b354d2 100644 --- a/machinery/src/utils/main.go +++ b/machinery/src/utils/main.go @@ -186,6 +186,13 @@ func NumberOfFilesInDirectory(path string) int { return len(files) } +// NumberOfMP4sInDirectory returns the count of all files with mp4 extension in current directory +func NumberOfMP4sInDirectory(path string) int { + pattern := filepath.Join(path, "*.mp4") + files, _ := filepath.Glob(pattern) + return len(files) +} + func RandStringBytesRmndr(n int) string { b := make([]byte, n) for i := range b {