[#240] Fix s3 index page
Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
parent
96a22d98f2
commit
39cf4e508e
4 changed files with 35 additions and 15 deletions
|
@ -150,8 +150,11 @@ func urlencode(path string) string {
|
|||
var res strings.Builder
|
||||
|
||||
prefixParts := strings.Split(path, "/")
|
||||
for _, prefixPart := range prefixParts {
|
||||
prefixPart = "/" + url.PathEscape(prefixPart)
|
||||
for i, prefixPart := range prefixParts {
|
||||
prefixPart = url.PathEscape(prefixPart)
|
||||
if i != 0 {
|
||||
prefixPart = "/" + prefixPart
|
||||
}
|
||||
if prefixPart == "/." || prefixPart == "/.." {
|
||||
prefixPart = url.PathEscape(prefixPart)
|
||||
}
|
||||
|
@ -168,11 +171,16 @@ type GetObjectsResponse struct {
|
|||
}
|
||||
|
||||
func (h *Handler) getDirObjectsS3(ctx context.Context, bucketInfo *data.BucketInfo, prefix string) (*GetObjectsResponse, error) {
|
||||
if prefix != "" && prefix[len(prefix)-1] == '/' {
|
||||
prefix = prefix[:len(prefix)-1]
|
||||
var treePrefix *string
|
||||
if prefix != "" {
|
||||
if prefix[len(prefix)-1] == '/' {
|
||||
treePrefix = ptr(prefix[:len(prefix)-1])
|
||||
} else {
|
||||
treePrefix = &prefix
|
||||
}
|
||||
}
|
||||
|
||||
nodes, err := h.tree.GetSubTreeByPrefix(ctx, bucketInfo, prefix, true)
|
||||
nodes, err := h.tree.GetSubTreeByPrefix(ctx, bucketInfo, treePrefix, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -193,14 +201,18 @@ func (h *Handler) getDirObjectsS3(ctx context.Context, bucketInfo *data.BucketIn
|
|||
if obj.IsDeleteMarker {
|
||||
continue
|
||||
}
|
||||
obj.FilePath = prefix + "/" + obj.FileName
|
||||
obj.GetURL = "/get/" + bucketInfo.Name + urlencode(obj.FilePath)
|
||||
obj.FilePath = prefix + obj.FileName
|
||||
obj.GetURL = "/get/" + bucketInfo.Name + "/" + urlencode(obj.FilePath)
|
||||
result.objects = append(result.objects, obj)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func ptr(s string) *string {
|
||||
return &s
|
||||
}
|
||||
|
||||
func (h *Handler) getDirObjectsNative(ctx context.Context, bucketInfo *data.BucketInfo, prefix string) (*GetObjectsResponse, error) {
|
||||
basePath := prefix
|
||||
if basePath != "" && basePath[len(basePath)-1] != '/' {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue