diff --git a/app/version.go b/app/version.go index 38872ae0..807694b5 100644 --- a/app/version.go +++ b/app/version.go @@ -30,7 +30,7 @@ func (v versionInfo) MinorString() string { var Version = versionInfo{ Major: 16, Minor: 18, - Patch: 1, + Patch: 2, } // Commit is the git commit the app is build from. It should be filled in during compilation diff --git a/cluster/proxy/node.go b/cluster/proxy/node.go index 4b06e135..48f3ce99 100644 --- a/cluster/proxy/node.go +++ b/cluster/proxy/node.go @@ -738,7 +738,16 @@ func (n *node) FileList(storage, pattern string) ([]clientapi.FileInfo, error) { return nil, ErrNoPeer } - return n.peer.FilesystemList(storage, pattern, "", "") + files, err := n.peer.FilesystemList(storage, pattern, "", "") + if err != nil { + return nil, err + } + + for i := range files { + files[i].CoreID = n.id + } + + return files, nil } func cloneURL(src *url.URL) *url.URL { diff --git a/cluster/proxy/proxy.go b/cluster/proxy/proxy.go index d2a5e6a8..628a898d 100644 --- a/cluster/proxy/proxy.go +++ b/cluster/proxy/proxy.go @@ -44,7 +44,7 @@ type ProxyReader interface { ProbeProcess(nodeid string, id app.ProcessID) (clientapi.Probe, error) ProbeProcessConfig(nodeid string, config *app.Config) (clientapi.Probe, error) - ListFiles(storage, patter string) []clientapi.FileInfo + ListFiles(storage, pattern string) []clientapi.FileInfo GetURL(prefix, path string) (*url.URL, error) GetFile(prefix, path string, offset int64) (io.ReadCloser, error) diff --git a/http/handler/api/cluster_fs.go b/http/handler/api/cluster_fs.go index 7a0b9226..66ed390d 100644 --- a/http/handler/api/cluster_fs.go +++ b/http/handler/api/cluster_fs.go @@ -2,12 +2,9 @@ package api import ( "net/http" - "strconv" - "time" + "sort" - "github.com/datarhei/core/v16/http/api" "github.com/datarhei/core/v16/http/handler/util" - "github.com/datarhei/core/v16/io/fs" "github.com/labstack/echo/v4" ) @@ -20,10 +17,6 @@ import ( // @Produce json // @Param storage path string true "Name of the filesystem" // @Param glob query string false "glob pattern for file names" -// @Param size_min query int64 false "minimal size of files" -// @Param size_max query int64 false "maximal size of files" -// @Param lastmod_start query int64 false "minimal last modification time" -// @Param lastmod_end query int64 false "maximal last modification time" // @Param sort query string false "none, name, size, lastmod" // @Param order query string false "asc, desc" // @Success 200 {array} api.FileInfo @@ -31,48 +24,37 @@ import ( // @Security ApiKeyAuth // @Router /api/v3/cluster/fs/{storage} [get] func (h *ClusterHandler) ListFiles(c echo.Context) error { - //name := util.PathParam(c, "storage") + name := util.PathParam(c, "storage") pattern := util.DefaultQuery(c, "glob", "") - sizeMin := util.DefaultQuery(c, "size_min", "0") - sizeMax := util.DefaultQuery(c, "size_max", "0") - modifiedStart := util.DefaultQuery(c, "lastmod_start", "") - modifiedEnd := util.DefaultQuery(c, "lastmod_end", "") - //sortby := util.DefaultQuery(c, "sort", "none") - //order := util.DefaultQuery(c, "order", "asc") + sortby := util.DefaultQuery(c, "sort", "none") + order := util.DefaultQuery(c, "order", "asc") - options := fs.ListOptions{ - Pattern: pattern, - } + files := h.proxy.ListFiles(name, pattern) - if x, err := strconv.ParseInt(sizeMin, 10, 64); err != nil { - return api.Err(http.StatusBadRequest, "", "size_min: %s", err.Error()) - } else { - options.SizeMin = x - } + var sortFunc func(i, j int) bool - if x, err := strconv.ParseInt(sizeMax, 10, 64); err != nil { - return api.Err(http.StatusBadRequest, "", "size_max: %s", err.Error()) - } else { - options.SizeMax = x - } - - if len(modifiedStart) != 0 { - if x, err := strconv.ParseInt(modifiedStart, 10, 64); err != nil { - return api.Err(http.StatusBadRequest, "", "lastmod_start: %s", err.Error()) + switch sortby { + case "name": + if order == "desc" { + sortFunc = func(i, j int) bool { return files[i].Name > files[j].Name } } else { - t := time.Unix(x, 0) - options.ModifiedStart = &t + sortFunc = func(i, j int) bool { return files[i].Name < files[j].Name } } - } - - if len(modifiedEnd) != 0 { - if x, err := strconv.ParseInt(modifiedEnd, 10, 64); err != nil { - return api.Err(http.StatusBadRequest, "", "lastmode_end: %s", err.Error()) + case "size": + if order == "desc" { + sortFunc = func(i, j int) bool { return files[i].Size > files[j].Size } + } else { + sortFunc = func(i, j int) bool { return files[i].Size < files[j].Size } + } + default: + if order == "asc" { + sortFunc = func(i, j int) bool { return files[i].LastMod < files[j].LastMod } } else { - t := time.Unix(x+1, 0) - options.ModifiedEnd = &t + sortFunc = func(i, j int) bool { return files[i].LastMod > files[j].LastMod } } } - return api.Err(http.StatusNotImplemented, "", "not implemented") + sort.Slice(files, sortFunc) + + return c.JSON(http.StatusOK, files) }