From ea5ca24341e5484cdb07edf9b56761bccb9ce65e Mon Sep 17 00:00:00 2001 From: benbierens Date: Tue, 30 Jul 2024 15:33:49 +0200 Subject: [PATCH] Defines API --- codex/rest/api.nim | 27 +++++++++++++++++++++++++++ openapi.yaml | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/codex/rest/api.nim b/codex/rest/api.nim index d44cffa4..61ea6059 100644 --- a/codex/rest/api.nim +++ b/codex/rest/api.nim @@ -209,6 +209,33 @@ proc initDataApi(node: CodexNodeRef, repoStore: RepoStore, router: var RestRoute ) return RestApiResponse.response($json, contentType="application/json") + router.api( + MethodPut, + "api/codex/v1/pin/{cid}") do ( + cid: Cid, resp: HttpResponseRef) -> RestApiResponse: + ## Pins a file to the node. Node will keep the file in local storage while pinned. + ## + if cid.isErr: + return RestApiResponse.error( + Http400, + $cid.error()) + + await node.pinCid(cid.get(), resp=resp) + + router.api( + MethodDelete, + "api/codex/v1/pin/{cid}") do ( + cid: Cid, resp: HttpResponseRef) -> RestApiResponse: + ## Remove a pinned file from the node. Node will delete the local copy of the file. + ## + if cid.isErr: + return RestApiResponse.error( + Http400, + $cid.error()) + + await node.unpinCid(cid.get(), resp=resp) + + proc initSalesApi(node: CodexNodeRef, router: var RestRouter) = router.api( MethodGet, diff --git a/openapi.yaml b/openapi.yaml index 94450bf3..3a6f4a91 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -475,6 +475,47 @@ paths: "500": description: "It's not working as planned" + "/pin/{cid}": + put: + summary: "Pins a file to the node. Node will keep the file in local storage while pinned." + tags: [ Data ] + operationId: pinToLocal + parameters: + - in: path + name: cid + required: true + schema: + $ref: "#/components/schemas/Cid" + description: File to be pinned. + responses: + "200": + description: OK. Node will start fetching the file from the network if needed. + "400": + description: Invalid CID is specified + "500": + description: Well it was bad-bad + + delete: + summary: "Remove a pinned file from the node. Node will delete the local copy of the file." + tags: [ Data ] + operationId: unpinFromLocal + parameters: + - in: path + name: cid + required: true + schema: + $ref: "#/components/schemas/Cid" + description: Pinned CID to be removed. + responses: + "200": + description: OK. Node will delete the previously pinned file from local storage. + "400": + description: Invalid CID is specified + "404": + description: The provided CID was not previously pinned + "500": + description: Well it was bad-bad + "/sales/slots": get: summary: "Returns active slots"