Browse Source

fix: files are now listed individually and folder names are skipped

pull/2901/head
Elia Ravella 2 years ago
parent
commit
b14703f508
  1. 34
      internal/api/api.go

34
internal/api/api.go

@ -6,9 +6,11 @@ import ( @@ -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) { @@ -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)

Loading…
Cancel
Save