From 88aaad361a440fbbf6a4eb520ad22167ef80dc82 Mon Sep 17 00:00:00 2001 From: Angira Kekteeva Date: Thu, 29 Jul 2021 19:16:43 +0300 Subject: [PATCH] [#180] api: Add continuation-token check Signed-off-by: Angira Kekteeva --- api/handler/object_list.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/api/handler/object_list.go b/api/handler/object_list.go index a508497e..a4b58ce4 100644 --- a/api/handler/object_list.go +++ b/api/handler/object_list.go @@ -2,9 +2,11 @@ package handler import ( "net/http" + "net/url" "strconv" "time" + "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-s3-gw/api" "github.com/nspcc-dev/neofs-s3-gw/api/layer" ) @@ -120,7 +122,11 @@ func parseListObjectsArgsV2(r *http.Request) (*layer.ListObjectsParamsV2, error) } res.ListObjectsParamsCommon = *common - res.ContinuationToken = queryValues.Get("continuation-token") + res.ContinuationToken, err = parseContinuationToken(queryValues) + if err != nil { + return nil, err + } + res.StartAfter = queryValues.Get("start-after") res.FetchOwner, _ = strconv.ParseBool(queryValues.Get("fetch-owner")) return &res, nil @@ -151,6 +157,16 @@ func parseListObjectArgs(r *http.Request) (*layer.ListObjectsParamsCommon, error return &res, nil } +func parseContinuationToken(queryValues url.Values) (string, error) { + if val, ok := queryValues["continuation-token"]; ok { + if err := object.NewID().Parse(val[0]); err != nil { + return "", api.GetAPIError(api.ErrIncorrectContinuationToken) + } + return val[0], nil + } + return "", nil +} + func fillPrefixes(src []string, encode string) []CommonPrefix { var dst []CommonPrefix for _, obj := range src {