client rebuilding in progress
This commit is contained in:
@@ -256,9 +256,7 @@ type ListAccountsResult struct {
|
||||
|
||||
func (oper *Operator) ListAccounts(ctx context.Context, params *ListAccountsParams) (*ListAccountsResult, error) {
|
||||
var err error
|
||||
res := &ListAccountsResult{
|
||||
Accounts: make([]descr.AccountShort, 0),
|
||||
}
|
||||
res := &ListAccountsResult{}
|
||||
|
||||
accountDescrs, err := oper.mdb.ReducedListAccounts(ctx)
|
||||
if err != nil {
|
||||
|
||||
+126
-130
@@ -24,7 +24,7 @@ import (
|
||||
"mstore/pkg/auxtool"
|
||||
"mstore/pkg/auxuuid"
|
||||
"mstore/pkg/descr"
|
||||
"mstore/pkg/terms"
|
||||
"mstore/pkg/filecli"
|
||||
)
|
||||
|
||||
// FileInfo
|
||||
@@ -39,11 +39,10 @@ type FileInfoResult struct {
|
||||
ContentType string
|
||||
ContentSize string
|
||||
ContentDigest string
|
||||
|
||||
ContentCreatedAt string
|
||||
ContentCreatedBy string
|
||||
ContentUpdatedAt string
|
||||
ContentUpdatedBy string
|
||||
ContentCreatedAt string
|
||||
ContentCreatedBy string
|
||||
ContentUpdatedAt string
|
||||
ContentUpdatedBy string
|
||||
}
|
||||
|
||||
func cleanFilepath(filename string) (string, error) {
|
||||
@@ -299,122 +298,10 @@ func (oper *Operator) DeleteFile(ctx context.Context, operatorID string, params
|
||||
return code, res, err
|
||||
}
|
||||
|
||||
// ListFiles
|
||||
type ListFilesParams struct {
|
||||
Filepath string
|
||||
PathAs string `param:"pathAs"`
|
||||
}
|
||||
type ListFilesResult struct {
|
||||
Files []descr.File `json:"files,omitempty"`
|
||||
}
|
||||
|
||||
func (oper *Operator) ListFiles(ctx context.Context, operatorID string, params *ListFilesParams) (int, *ListFilesResult, error) {
|
||||
var err error
|
||||
res := &ListFilesResult{
|
||||
Files: make([]descr.File, 0),
|
||||
}
|
||||
switch params.PathAs {
|
||||
case terms.AsRegexp:
|
||||
files, err := oper.listFilesWithRegex(ctx, params.Filepath)
|
||||
if err != nil {
|
||||
code := http.StatusInternalServerError
|
||||
return code, res, err
|
||||
}
|
||||
res.Files = files
|
||||
case terms.AsPrefix:
|
||||
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: // Fine
|
||||
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.listFilesInOneCollection(ctx, params.Filepath)
|
||||
if err != nil {
|
||||
code := http.StatusInternalServerError
|
||||
return code, res, err
|
||||
}
|
||||
res.Files = files
|
||||
|
||||
}
|
||||
code := http.StatusOK
|
||||
return code, res, err
|
||||
}
|
||||
|
||||
func (oper *Operator) listFilesInOneCollection(ctx context.Context, collection string) ([]descr.File, error) {
|
||||
var err error
|
||||
res := make([]descr.File, 0)
|
||||
files, err := oper.mdb.ListFilesByCollection(ctx, collection)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res = files
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (oper *Operator) listFilesWithPrefix(ctx context.Context, prefix string) ([]descr.File, error) {
|
||||
var err error
|
||||
res := make([]descr.File, 0)
|
||||
files, err := oper.mdb.ListAllFiles(ctx)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
for _, file := range files {
|
||||
fullpath := filepath.Join(file.Collection, file.Name)
|
||||
if strings.HasPrefix(fullpath, prefix) {
|
||||
res = append(res, file)
|
||||
}
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (oper *Operator) listFilesWithRegex(ctx context.Context, regex string) ([]descr.File, error) {
|
||||
var err error
|
||||
res := make([]descr.File, 0)
|
||||
|
||||
re, err := regexp.Compile(regex)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
files, err := oper.mdb.ListAllFiles(ctx)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
for _, file := range files {
|
||||
fullpath := filepath.Join(file.Collection, file.Name)
|
||||
if re.MatchString(fullpath) {
|
||||
res = append(res, file)
|
||||
}
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
// ListCollections
|
||||
type ListCollectionsParams struct {
|
||||
Path string
|
||||
PathAS string `param:"pathAs"`
|
||||
Path string
|
||||
PathType string `param:"pathType"`
|
||||
}
|
||||
type ListCollectionsResult struct {
|
||||
Collections []string `json:"collection,omitempty"`
|
||||
@@ -427,14 +314,14 @@ func (oper *Operator) ListCollections(ctx context.Context, operatorID string, pa
|
||||
}
|
||||
|
||||
collectionList := make([]string, 0)
|
||||
switch param.PathAS {
|
||||
case terms.AsRegexp:
|
||||
switch param.PathType {
|
||||
case filecli.PathTypeRegexp:
|
||||
collectionList, err = oper.listCollectionsWithRegexp(ctx, param.Path)
|
||||
if err != nil {
|
||||
code := http.StatusInternalServerError
|
||||
return code, res, err
|
||||
}
|
||||
case terms.AsPrefix:
|
||||
case filecli.PathTypePrefix:
|
||||
param.Path, err = cleanFilepath(param.Path)
|
||||
if err != nil {
|
||||
code := http.StatusInternalServerError
|
||||
@@ -545,9 +432,9 @@ func (oper *Operator) listAllCollections(ctx context.Context) ([]string, error)
|
||||
|
||||
// DeleteColletion
|
||||
type DeleteColletionParams struct {
|
||||
Path string
|
||||
PathAs string `param:"pathAs"`
|
||||
DryRun bool `param:"dryRun"`
|
||||
Path string
|
||||
PathType string `param:"pathType"`
|
||||
DryRun bool `param:"dryRun"`
|
||||
}
|
||||
type DeleteColletionResult struct {
|
||||
Files []descr.File `json:"files,omitempty"`
|
||||
@@ -558,8 +445,8 @@ func (oper *Operator) DeleteColletion(ctx context.Context, operatorID string, pa
|
||||
res := &DeleteColletionResult{
|
||||
Files: make([]descr.File, 0),
|
||||
}
|
||||
switch param.PathAs {
|
||||
case terms.AsRegexp:
|
||||
switch param.PathType {
|
||||
case filecli.PathTypeRegexp:
|
||||
collections, err := oper.listCollectionsWithRegexp(ctx, param.Path)
|
||||
if err != nil {
|
||||
code := http.StatusInternalServerError
|
||||
@@ -576,7 +463,7 @@ func (oper *Operator) DeleteColletion(ctx context.Context, operatorID string, pa
|
||||
}
|
||||
res.Files = allfiles
|
||||
|
||||
case terms.AsPrefix:
|
||||
case filecli.PathTypePrefix:
|
||||
param.Path, err = cleanFilepath(param.Path)
|
||||
if err != nil {
|
||||
code := http.StatusInternalServerError
|
||||
@@ -598,7 +485,7 @@ func (oper *Operator) DeleteColletion(ctx context.Context, operatorID string, pa
|
||||
allfiles = append(allfiles, files...)
|
||||
}
|
||||
res.Files = allfiles
|
||||
default: // Fine
|
||||
default:
|
||||
param.Path, err = cleanFilepath(param.Path)
|
||||
if err != nil {
|
||||
code := http.StatusInternalServerError
|
||||
@@ -641,3 +528,112 @@ func (oper *Operator) deleteFilesInCollection(ctx context.Context, collection st
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
// ListFiles
|
||||
type ListFilesParams struct {
|
||||
Filepath string
|
||||
PathType string `param:"pathType"`
|
||||
}
|
||||
type ListFilesResult struct {
|
||||
Files []descr.File `json:"files,omitempty"`
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
}
|
||||
code := http.StatusOK
|
||||
return code, res, err
|
||||
}
|
||||
|
||||
func (oper *Operator) listFilesInCollection(ctx context.Context, collection string) ([]descr.File, error) {
|
||||
var err error
|
||||
res := make([]descr.File, 0)
|
||||
files, err := oper.mdb.ListFilesByCollection(ctx, collection)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res = files
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (oper *Operator) listFilesWithPrefix(ctx context.Context, prefix string) ([]descr.File, error) {
|
||||
var err error
|
||||
res := make([]descr.File, 0)
|
||||
files, err := oper.mdb.ListAllFiles(ctx)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
for _, file := range files {
|
||||
fullpath := filepath.Join(file.Collection, file.Name)
|
||||
if strings.HasPrefix(fullpath, prefix) {
|
||||
res = append(res, file)
|
||||
}
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (oper *Operator) listFilesWithRegex(ctx context.Context, regex string) ([]descr.File, error) {
|
||||
var err error
|
||||
res := make([]descr.File, 0)
|
||||
|
||||
re, err := regexp.Compile(regex)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
files, err := oper.mdb.ListAllFiles(ctx)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
for _, file := range files {
|
||||
fullpath := filepath.Join(file.Collection, file.Name)
|
||||
if re.MatchString(fullpath) {
|
||||
res = append(res, file)
|
||||
}
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
@@ -321,17 +321,27 @@ func (oper *Operator) GetManifest(ctx context.Context, params *GetManifestParams
|
||||
if !exists {
|
||||
return res, http.StatusNotFound, err
|
||||
}
|
||||
/*
|
||||
index, indexBytes, err := indexFromManigestDescrs(manifestDescrs)
|
||||
if err != nil {
|
||||
return res, http.StatusInternalServerError, err
|
||||
}
|
||||
indexDigest := auxoci.SHA256DigestFromString(indexBytes)
|
||||
res.DockerContentDigest = indexDigest.String()
|
||||
|
||||
index, indexBytes, err := indexFromManigestDescrs(manifestDescrs)
|
||||
if err != nil {
|
||||
return res, http.StatusInternalServerError, err
|
||||
}
|
||||
indexDigest := auxoci.SHA256DigestFromString(indexBytes)
|
||||
res.DockerContentDigest = indexDigest.String()
|
||||
res.ContentLength = strconv.FormatInt(int64(len(indexBytes)), 10)
|
||||
res.ContentType = index.MediaType
|
||||
res.Payload = string(indexBytes)
|
||||
*/
|
||||
manifestDescr = manifestDescrs[0]
|
||||
|
||||
manifestDigest := auxoci.SHA256DigestFromString(manifestDescr.Payload)
|
||||
res.DockerContentDigest = manifestDigest.String()
|
||||
|
||||
res.ContentLength = strconv.FormatInt(int64(len(manifestDescr.Payload)), 10)
|
||||
res.ContentType = manifestDescr.ContentType
|
||||
res.Payload = manifestDescr.Payload
|
||||
|
||||
res.ContentLength = strconv.FormatInt(int64(len(indexBytes)), 10)
|
||||
res.ContentType = index.MediaType
|
||||
res.Payload = string(indexBytes)
|
||||
}
|
||||
return res, http.StatusOK, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user