working commit
This commit is contained in:
+12
-7
@@ -17,6 +17,7 @@ import (
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"mstore/app/descr"
|
||||
"mstore/pkg/auxtool"
|
||||
@@ -281,19 +282,17 @@ type ListFilesParams struct {
|
||||
Filepath string
|
||||
}
|
||||
type ListFilesResult struct {
|
||||
Files []descr.File `json:"files,omitempty"`
|
||||
//Catalogs []string `json:"files,omitempty"`
|
||||
Files []descr.File `json:"files,omitempty"`
|
||||
Collections []string `json:"collection,omitempty"`
|
||||
}
|
||||
|
||||
func (oper *Operator) ListFiles(ctx context.Context, operID string, param *ListFilesParams) (int, *ListFilesResult, error) {
|
||||
var err error
|
||||
res := &ListFilesResult{
|
||||
Files: make([]descr.File, 0),
|
||||
//Catalogs: make([]string, 0)
|
||||
Files: make([]descr.File, 0),
|
||||
Collections: make([]string, 0),
|
||||
}
|
||||
|
||||
// TODO: convert file path to a unified and secure state
|
||||
|
||||
_, err = cleanFilepath(param.Filepath)
|
||||
if err != nil {
|
||||
code := http.StatusInternalServerError
|
||||
@@ -305,8 +304,14 @@ func (oper *Operator) ListFiles(ctx context.Context, operID string, param *ListF
|
||||
code := http.StatusInternalServerError
|
||||
return code, res, err
|
||||
}
|
||||
rFilepath := filepath.Join("/", param.Filepath)
|
||||
for _, item := range fileDescrs {
|
||||
res.Files = append(res.Files, item)
|
||||
cFilepath := filepath.Join("/", item.Collection, item.Name)
|
||||
collection := filepath.Join("/", item.Collection)
|
||||
if strings.HasPrefix(cFilepath, rFilepath) {
|
||||
res.Files = append(res.Files, item)
|
||||
res.Collections = append(res.Collections, collection)
|
||||
}
|
||||
}
|
||||
code := http.StatusOK
|
||||
return code, res, err
|
||||
|
||||
Reference in New Issue
Block a user