mirror of
https://github.com/datarhei/core.git
synced 2025-10-29 02:22:35 +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{
|
var Version = versionInfo{
|
||||||
Major: 16,
|
Major: 16,
|
||||||
Minor: 18,
|
Minor: 18,
|
||||||
Patch: 1,
|
Patch: 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commit is the git commit the app is build from. It should be filled in during compilation
|
// 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 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 {
|
func cloneURL(src *url.URL) *url.URL {
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ type ProxyReader interface {
|
|||||||
ProbeProcess(nodeid string, id app.ProcessID) (clientapi.Probe, error)
|
ProbeProcess(nodeid string, id app.ProcessID) (clientapi.Probe, error)
|
||||||
ProbeProcessConfig(nodeid string, config *app.Config) (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)
|
GetURL(prefix, path string) (*url.URL, error)
|
||||||
GetFile(prefix, path string, offset int64) (io.ReadCloser, error)
|
GetFile(prefix, path string, offset int64) (io.ReadCloser, error)
|
||||||
|
|||||||
@@ -2,12 +2,9 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"sort"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/datarhei/core/v16/http/api"
|
|
||||||
"github.com/datarhei/core/v16/http/handler/util"
|
"github.com/datarhei/core/v16/http/handler/util"
|
||||||
"github.com/datarhei/core/v16/io/fs"
|
|
||||||
|
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
@@ -20,10 +17,6 @@ import (
|
|||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param storage path string true "Name of the filesystem"
|
// @Param storage path string true "Name of the filesystem"
|
||||||
// @Param glob query string false "glob pattern for file names"
|
// @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 sort query string false "none, name, size, lastmod"
|
||||||
// @Param order query string false "asc, desc"
|
// @Param order query string false "asc, desc"
|
||||||
// @Success 200 {array} api.FileInfo
|
// @Success 200 {array} api.FileInfo
|
||||||
@@ -31,48 +24,37 @@ import (
|
|||||||
// @Security ApiKeyAuth
|
// @Security ApiKeyAuth
|
||||||
// @Router /api/v3/cluster/fs/{storage} [get]
|
// @Router /api/v3/cluster/fs/{storage} [get]
|
||||||
func (h *ClusterHandler) ListFiles(c echo.Context) error {
|
func (h *ClusterHandler) ListFiles(c echo.Context) error {
|
||||||
//name := util.PathParam(c, "storage")
|
name := util.PathParam(c, "storage")
|
||||||
pattern := util.DefaultQuery(c, "glob", "")
|
pattern := util.DefaultQuery(c, "glob", "")
|
||||||
sizeMin := util.DefaultQuery(c, "size_min", "0")
|
sortby := util.DefaultQuery(c, "sort", "none")
|
||||||
sizeMax := util.DefaultQuery(c, "size_max", "0")
|
order := util.DefaultQuery(c, "order", "asc")
|
||||||
modifiedStart := util.DefaultQuery(c, "lastmod_start", "")
|
|
||||||
modifiedEnd := util.DefaultQuery(c, "lastmod_end", "")
|
|
||||||
//sortby := util.DefaultQuery(c, "sort", "none")
|
|
||||||
//order := util.DefaultQuery(c, "order", "asc")
|
|
||||||
|
|
||||||
options := fs.ListOptions{
|
files := h.proxy.ListFiles(name, pattern)
|
||||||
Pattern: pattern,
|
|
||||||
}
|
|
||||||
|
|
||||||
if x, err := strconv.ParseInt(sizeMin, 10, 64); err != nil {
|
var sortFunc func(i, j int) bool
|
||||||
return api.Err(http.StatusBadRequest, "", "size_min: %s", err.Error())
|
|
||||||
} else {
|
|
||||||
options.SizeMin = x
|
|
||||||
}
|
|
||||||
|
|
||||||
if x, err := strconv.ParseInt(sizeMax, 10, 64); err != nil {
|
switch sortby {
|
||||||
return api.Err(http.StatusBadRequest, "", "size_max: %s", err.Error())
|
case "name":
|
||||||
} else {
|
if order == "desc" {
|
||||||
options.SizeMax = x
|
sortFunc = func(i, j int) bool { return files[i].Name > files[j].Name }
|
||||||
}
|
|
||||||
|
|
||||||
if len(modifiedStart) != 0 {
|
|
||||||
if x, err := strconv.ParseInt(modifiedStart, 10, 64); err != nil {
|
|
||||||
return api.Err(http.StatusBadRequest, "", "lastmod_start: %s", err.Error())
|
|
||||||
} else {
|
} else {
|
||||||
t := time.Unix(x, 0)
|
sortFunc = func(i, j int) bool { return files[i].Name < files[j].Name }
|
||||||
options.ModifiedStart = &t
|
}
|
||||||
|
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 {
|
sort.Slice(files, sortFunc)
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return api.Err(http.StatusNotImplemented, "", "not implemented")
|
return c.JSON(http.StatusOK, files)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user