forked from TrueCloudLab/frostfs-http-gw
Fix browse page invocation
Signed-off-by: Alex Vanin <a.vanin@yadro.com>
This commit is contained in:
parent
181568f442
commit
d2ab6bab23
3 changed files with 66 additions and 5 deletions
|
@ -23,12 +23,16 @@ import (
|
||||||
|
|
||||||
// DownloadByAddressOrBucketName handles download requests using simple cid/oid or bucketname/key format.
|
// DownloadByAddressOrBucketName handles download requests using simple cid/oid or bucketname/key format.
|
||||||
func (h *Handler) DownloadByAddressOrBucketName(c *fasthttp.RequestCtx) {
|
func (h *Handler) DownloadByAddressOrBucketName(c *fasthttp.RequestCtx) {
|
||||||
cnrIDStr, _ := c.UserValue("cid").(string)
|
oidURLParam := c.UserValue("oid").(string)
|
||||||
var cnrID cid.ID
|
cidURLParam := c.UserValue("cid").(string)
|
||||||
if err := cnrID.DecodeString(cnrIDStr); err != nil {
|
|
||||||
h.byS3Path(c, h.receiveFile)
|
switch {
|
||||||
} else {
|
case isContainerID(oidURLParam) && isObjectID(cidURLParam):
|
||||||
h.byNativeAddress(c, h.receiveFile)
|
h.byNativeAddress(c, h.receiveFile)
|
||||||
|
case !isContainerRoot(cidURLParam) && !isDir(cidURLParam):
|
||||||
|
h.byS3Path(c, h.receiveFile)
|
||||||
|
default:
|
||||||
|
h.browseIndex(c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -285,6 +285,53 @@ func (h *Handler) byS3Path(c *fasthttp.RequestCtx, f func(context.Context, reque
|
||||||
f(ctx, *h.newRequest(c, log), addr)
|
f(ctx, *h.newRequest(c, log), addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *Handler) browseIndex(c *fasthttp.RequestCtx) {
|
||||||
|
if !h.config.IndexPageEnabled() {
|
||||||
|
c.SetStatusCode(fasthttp.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
cidURLParam := c.UserValue("cid").(string)
|
||||||
|
oidURLParam := c.UserValue("oid").(string)
|
||||||
|
|
||||||
|
ctx := utils.GetContextFromRequest(c)
|
||||||
|
reqLog := utils.GetReqLogOrDefault(ctx, h.log)
|
||||||
|
log := reqLog.With(zap.String("cid", cidURLParam), zap.String("oid", oidURLParam))
|
||||||
|
|
||||||
|
unescapedKey, err := url.QueryUnescape(oidURLParam)
|
||||||
|
if err != nil {
|
||||||
|
logAndSendBucketError(c, log, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
bktInfo, err := h.getBucketInfo(ctx, oidURLParam, log)
|
||||||
|
if err != nil {
|
||||||
|
logAndSendBucketError(c, log, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.SetStatusCode(fasthttp.StatusOK)
|
||||||
|
|
||||||
|
listFunc := h.getDirObjectsS3
|
||||||
|
isNativeList := false
|
||||||
|
|
||||||
|
_, err = h.tree.GetLatestVersion(ctx, &bktInfo.CID, "")
|
||||||
|
if err != nil {
|
||||||
|
// tree probe failed, try to use native
|
||||||
|
fmt.Println("!!! I failed tree probe")
|
||||||
|
listFunc = h.getDirObjectsS3
|
||||||
|
isNativeList = true
|
||||||
|
}
|
||||||
|
|
||||||
|
c.SetStatusCode(fasthttp.StatusOK)
|
||||||
|
h.browseObjects(c, browseParams{
|
||||||
|
bucketInfo: bktInfo,
|
||||||
|
prefix: unescapedKey,
|
||||||
|
listObjects: listFunc,
|
||||||
|
isNative: isNativeList,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// byAttribute is a wrapper similar to byNativeAddress.
|
// byAttribute is a wrapper similar to byNativeAddress.
|
||||||
func (h *Handler) byAttribute(c *fasthttp.RequestCtx, f func(context.Context, request, oid.Address)) {
|
func (h *Handler) byAttribute(c *fasthttp.RequestCtx, f func(context.Context, request, oid.Address)) {
|
||||||
scid, _ := c.UserValue("cid").(string)
|
scid, _ := c.UserValue("cid").(string)
|
||||||
|
|
|
@ -51,6 +51,16 @@ func isContainerRoot(key string) bool {
|
||||||
return key == ""
|
return key == ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isContainerID(s string) bool {
|
||||||
|
var cnrID cid.ID
|
||||||
|
return cnrID.DecodeString(s) == nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func isObjectID(s string) bool {
|
||||||
|
var objID oid.ID
|
||||||
|
return objID.DecodeString(s) == nil
|
||||||
|
}
|
||||||
|
|
||||||
func checkErrorType(err error) int {
|
func checkErrorType(err error) int {
|
||||||
switch {
|
switch {
|
||||||
case err == nil:
|
case err == nil:
|
||||||
|
|
Loading…
Reference in a new issue