mirror of
https://github.com/datarhei/core.git
synced 2025-10-28 18:21:59 +08:00
Add missing implementation for GET /api/v3/cluster/fs/{storage}
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 }
|
||||
}
|
||||
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 {
|
||||
sortFunc = func(i, j int) bool { return files[i].LastMod > files[j].LastMod }
|
||||
}
|
||||
}
|
||||
|
||||
if len(modifiedEnd) != 0 {
|
||||
if x, err := strconv.ParseInt(modifiedEnd, 10, 64); err != nil {
|
||||
return api.Err(http.StatusBadRequest, "", "lastmode_end: %s", err.Error())
|
||||
} else {
|
||||
t := time.Unix(x+1, 0)
|
||||
options.ModifiedEnd = &t
|
||||
}
|
||||
}
|
||||
sort.Slice(files, sortFunc)
|
||||
|
||||
return api.Err(http.StatusNotImplemented, "", "not implemented")
|
||||
return c.JSON(http.StatusOK, files)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user