Skip to content

Commit

Permalink
fix: update route
Browse files Browse the repository at this point in the history
  • Loading branch information
acha-bill committed Nov 26, 2024
1 parent 9932741 commit e4311c4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 30 deletions.
42 changes: 21 additions & 21 deletions openapi/Swarm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
11 changes: 5 additions & 6 deletions pkg/api/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions pkg/api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}),
Expand Down

0 comments on commit e4311c4

Please sign in to comment.