added file checker, completation/size/digest
This commit is contained in:
+47
-43
@@ -26,51 +26,13 @@ type ListFilesResult struct {
|
||||
func (oper *Operator) ListFiles(ctx context.Context, operatorID string, params *ListFilesParams) (int, *ListFilesResult, error) {
|
||||
var err error
|
||||
res := &ListFilesResult{}
|
||||
switch params.PathType {
|
||||
case filecli.PathTypeRegexp:
|
||||
files, err := oper.listFilesWithRegex(ctx, params.Filepath)
|
||||
if err != nil {
|
||||
code := http.StatusInternalServerError
|
||||
return code, res, err
|
||||
}
|
||||
res.Files = files
|
||||
case filecli.PathTypePrefix:
|
||||
params.Filepath, err = cleanFilepath(params.Filepath)
|
||||
if err != nil {
|
||||
code := http.StatusInternalServerError
|
||||
return code, res, err
|
||||
}
|
||||
params.Filepath, err = cleanFilepath(params.Filepath)
|
||||
if err != nil {
|
||||
code := http.StatusInternalServerError
|
||||
return code, res, err
|
||||
}
|
||||
|
||||
files, err := oper.listFilesWithPrefix(ctx, params.Filepath)
|
||||
if err != nil {
|
||||
code := http.StatusInternalServerError
|
||||
return code, res, err
|
||||
}
|
||||
res.Files = files
|
||||
default:
|
||||
params.Filepath, err = cleanFilepath(params.Filepath)
|
||||
if err != nil {
|
||||
code := http.StatusInternalServerError
|
||||
return code, res, err
|
||||
}
|
||||
params.Filepath, err = cleanFilepath(params.Filepath)
|
||||
if err != nil {
|
||||
code := http.StatusInternalServerError
|
||||
return code, res, err
|
||||
}
|
||||
files, err := oper.listFilesInCollection(ctx, params.Filepath)
|
||||
if err != nil {
|
||||
code := http.StatusInternalServerError
|
||||
return code, res, err
|
||||
}
|
||||
res.Files = files
|
||||
|
||||
files, err := oper.listFiles(ctx, params.PathType, params.Filepath)
|
||||
if err != nil {
|
||||
code := http.StatusInternalServerError
|
||||
return code, res, err
|
||||
}
|
||||
res.Files = files
|
||||
code := http.StatusOK
|
||||
return code, res, err
|
||||
}
|
||||
@@ -122,3 +84,45 @@ func (oper *Operator) listFilesWithRegex(ctx context.Context, regex string) ([]d
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (oper *Operator) listFiles(ctx context.Context, pathType, filepath string) ([]descr.File, error) {
|
||||
res := make([]descr.File, 0)
|
||||
var err error
|
||||
switch pathType {
|
||||
case filecli.PathTypeRegexp:
|
||||
files, err := oper.listFilesWithRegex(ctx, filepath)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res = files
|
||||
case filecli.PathTypePrefix:
|
||||
filepath, err = cleanFilepath(filepath)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
filepath, err = cleanFilepath(filepath)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
files, err := oper.listFilesWithPrefix(ctx, filepath)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res = files
|
||||
default:
|
||||
filepath, err = cleanFilepath(filepath)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
filepath, err = cleanFilepath(filepath)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
files, err := oper.listFilesInCollection(ctx, filepath)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res = files
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user