Defines API

This commit is contained in:
benbierens 2024-07-30 15:33:49 +02:00
parent 4f56f2af26
commit ea5ca24341
No known key found for this signature in database
GPG Key ID: 877D2C2E09A22F3A
2 changed files with 68 additions and 0 deletions

View File

@ -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,

View File

@ -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"