working commit

This commit is contained in:
2026-02-15 17:47:45 +02:00
parent 15a3379e5c
commit 2373af081e
10 changed files with 159 additions and 49 deletions
+12 -7
View File
@@ -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