diff --git a/internal/handler/browse.go b/internal/handler/browse.go index 1dc23a3..5296bab 100644 --- a/internal/handler/browse.go +++ b/internal/handler/browse.go @@ -76,13 +76,13 @@ func newListObjectsResponseNative(attrs map[string]string) ResponseObject { } } -func getNextDir(filepath, prefix string) string { +func getNextDir(filepath, prefix string) *string { restPath := strings.Replace(filepath, prefix, "", 1) index := strings.Index(restPath, "/") if index == -1 { - return "" + return nil } - return restPath[:index] + return ptr(restPath[:index]) } func lastPathElement(path string) string { @@ -143,7 +143,7 @@ func getParent(encPrefix string) string { if slashIndex == -1 { return "" } - return prefix[:slashIndex] + return prefix[:slashIndex+1] } func urlencode(path string) string { @@ -259,7 +259,7 @@ func (h *Handler) getDirObjectsNative(ctx context.Context, bucketInfo *data.Buck if _, ok := dirs[objExt.Object.FileName]; ok { continue } - objExt.Object.GetURL = "/get/" + bucketInfo.CID.EncodeToString() + urlencode(objExt.Object.FilePath) + objExt.Object.GetURL = "/get/" + bucketInfo.CID.EncodeToString() + "/" + urlencode(objExt.Object.FilePath) dirs[objExt.Object.FileName] = struct{}{} } else { objExt.Object.GetURL = "/get/" + bucketInfo.CID.EncodeToString() + "/" + objExt.Object.OID @@ -331,13 +331,13 @@ func (h *Handler) headDirObject(ctx context.Context, cnrID cid.ID, objID oid.ID, } dirname := getNextDir(attrs[object.AttributeFilePath], basePath) - if dirname == "" { + if dirname == nil { return newListObjectsResponseNative(attrs), nil } return ResponseObject{ - FileName: dirname, - FilePath: basePath + dirname, + FileName: *dirname, + FilePath: basePath + *dirname, IsDir: true, }, nil } diff --git a/internal/templates/index.gotmpl b/internal/templates/index.gotmpl index 4c03404..4337391 100644 --- a/internal/templates/index.gotmpl +++ b/internal/templates/index.gotmpl @@ -56,27 +56,15 @@
{{ $parentPrefix := getParent .Prefix }} - {{if $parentPrefix }}