From b14703f5083934100f71e49dc3e1b11e829f60bb Mon Sep 17 00:00:00 2001 From: Elia Ravella Date: Thu, 11 Jan 2024 11:10:59 +0100 Subject: [PATCH] fix: files are now listed individually and folder names are skipped --- internal/api/api.go | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/internal/api/api.go b/internal/api/api.go index 88505fcb..f41dd9cc 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -6,9 +6,11 @@ import ( "fmt" "net/http" "os" + "path/filepath" "reflect" "sort" "strconv" + "strings" "sync" "time" @@ -973,15 +975,35 @@ func (a *API) onSRTConnsKick(ctx *gin.Context) { } func (a *API) onListRecordings(ctx *gin.Context) { - files, err := os.ReadDir(a.Conf.PathDefaults.RecordPath) - if err != nil { - a.writeError(ctx, http.StatusInternalServerError, err) - return + // get the path until the first parametrized part + // ./recordings/stream-%path/%Y --> ./recordings + var parts []string = strings.Split(a.Conf.PathDefaults.RecordPath, "/") + var recordingsRoot string + var recordingsRootParts []string + + for _, part := range parts { + if strings.Contains(part, "%") { + break + } + recordingsRootParts = append(recordingsRootParts, part) } + recordingsRoot = strings.Join(recordingsRootParts, "/") + var fileNames []string - for _, f := range files { - fileNames = append(fileNames, f.Name()) + err := filepath.WalkDir(recordingsRoot, func(path string, d os.DirEntry, err error) error { + if err != nil { + return err + } + if !d.IsDir() { + fileNames = append(fileNames, path) + } + return nil + }) + + if err != nil { + a.writeError(ctx, http.StatusInternalServerError, err) + return } ctx.JSON(http.StatusOK, fileNames)