From e4311c4bb30324224c738f2b1a532a38c3d67dfc Mon Sep 17 00:00:00 2001 From: Acha Bill Date: Tue, 26 Nov 2024 00:11:52 -0500 Subject: [PATCH] fix: update route --- openapi/Swarm.yaml | 42 +++++++++++++++++++++--------------------- pkg/api/pin.go | 11 +++++------ pkg/api/router.go | 5 ++--- 3 files changed, 28 insertions(+), 30 deletions(-) diff --git a/openapi/Swarm.yaml b/openapi/Swarm.yaml index 9412209415..b3fa5cf9ef 100644 --- a/openapi/Swarm.yaml +++ b/openapi/Swarm.yaml @@ -720,50 +720,50 @@ paths: default: description: Default response - "/pins": - get: - summary: Get the list of pinned root hash references + "/pins/{reference}/repair": + post: + summary: Repair pinned chunks by fetching missing/invalid chunks from the network tags: - Pinning + parameters: + - in: path + name: reference + schema: + $ref: "SwarmCommon.yaml#/components/schemas/SwarmOnlyReference" + required: true + description: Swarm reference of the root hash. responses: "200": - description: List of pinned root hash references + description: List of repaired chunks content: application/json: schema: - $ref: "SwarmCommon.yaml#/components/schemas/SwarmOnlyReferencesList" + $ref: "SwarmCommon.yaml#/components/schemas/PinRepairResponse" "500": $ref: "SwarmCommon.yaml#/components/responses/500" default: description: Default response - "/pins/check": + "/pins": get: - summary: Validate pinned chunks integerity + summary: Get the list of pinned root hash references tags: - Pinning - parameters: - - in: query - name: ref - schema: - $ref: "SwarmCommon.yaml#/components/schemas/SwarmOnlyReference" - required: false - description: The number of items to skip before starting to collect the result set. responses: "200": - description: List of checked root hash references + description: List of pinned root hash references content: application/json: schema: - $ref: "SwarmCommon.yaml#/components/schemas/PinCheckResponse" + $ref: "SwarmCommon.yaml#/components/schemas/SwarmOnlyReferencesList" "500": $ref: "SwarmCommon.yaml#/components/responses/500" default: description: Default response - "/pins/repair": - post: - summary: Repair pinned chunks by fetching missing/invalid chunks from the network + "/pins/check": + get: + summary: Validate pinned chunks integerity tags: - Pinning parameters: @@ -775,11 +775,11 @@ paths: description: The number of items to skip before starting to collect the result set. responses: "200": - description: List of repaired chunks + description: List of checked root hash references content: application/json: schema: - $ref: "SwarmCommon.yaml#/components/schemas/PinRepairResponse" + $ref: "SwarmCommon.yaml#/components/schemas/PinCheckResponse" "500": $ref: "SwarmCommon.yaml#/components/responses/500" default: diff --git a/pkg/api/pin.go b/pkg/api/pin.go index 7002c5af33..e46fbdbade 100644 --- a/pkg/api/pin.go +++ b/pkg/api/pin.go @@ -263,17 +263,16 @@ func (s *Service) pinIntegrityHandler(w http.ResponseWriter, r *http.Request) { func (s *Service) repairPins(w http.ResponseWriter, r *http.Request) { logger := s.logger.WithName("post_repair_pins").Build() - query := struct { - Ref swarm.Address `map:"ref"` + paths := struct { + Reference swarm.Address `map:"reference" validate:"required"` }{} - - if response := s.mapStructure(r.URL.Query(), &query); response != nil { - response("invalid query params", logger, w) + if response := s.mapStructure(mux.Vars(r), &paths); response != nil { + response("invalid path params", logger, w) return } res := make(chan storer.RepairPinResult) - go s.pinIntegrity.Repair(r.Context(), logger, query.Ref.String(), s.storer, res) + go s.pinIntegrity.Repair(r.Context(), logger, paths.Reference.String(), s.storer, res) flusher, ok := w.(http.Flusher) if !ok { diff --git a/pkg/api/router.go b/pkg/api/router.go index e89ce9a658..3abc1ce30f 100644 --- a/pkg/api/router.go +++ b/pkg/api/router.go @@ -373,10 +373,9 @@ func (s *Service) mountAPI() { "GET": http.HandlerFunc(s.getPinnedRootHash), "POST": http.HandlerFunc(s.pinRootHash), "DELETE": http.HandlerFunc(s.unpinRootHash), - }, - ) + }) - handle("/pins/repair", web.ChainHandlers( + handle("/pins/{reference}/repair", web.ChainHandlers( web.FinalHandler(jsonhttp.MethodHandler{ "POST": http.HandlerFunc(s.repairPins), }),