mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-04-18 18:53:15 +00:00
Adds debug/fetch endpoint
This commit is contained in:
parent
d3a22a7b7b
commit
7c50c135ea
@ -41,6 +41,7 @@ export net, DefaultQuotaBytes, DefaultBlockTtl, DefaultBlockMaintenanceInterval,
|
||||
|
||||
const
|
||||
codex_enable_api_debug_peers* {.booldefine.} = false
|
||||
codex_enable_api_debug_fetch* {.booldefine.} = false
|
||||
codex_enable_proof_failures* {.booldefine.} = false
|
||||
|
||||
type
|
||||
|
||||
@ -93,6 +93,25 @@ proc formatPeerRecord(peerRecord: PeerRecord): JsonNode =
|
||||
}
|
||||
return jobj
|
||||
|
||||
proc formatManifest(manifest: Manifest): JsonNode =
|
||||
let jarray = newJArray()
|
||||
for blkcid in manifest:
|
||||
jarray.add(%*{
|
||||
"cid": $blkcid
|
||||
})
|
||||
|
||||
let jobj = %*{
|
||||
"originalBytes": $manifest.originalBytes,
|
||||
"blockSize": $manifest.blockSize,
|
||||
"numberOfBlocks": $manifest.len,
|
||||
"blocks": jarray,
|
||||
"version": $manifest.version,
|
||||
"hcodec": $manifest.hcodec,
|
||||
"codec": $manifest.codec,
|
||||
"protected": $manifest.protected
|
||||
}
|
||||
return jobj
|
||||
|
||||
proc initRestApi*(node: CodexNodeRef, conf: CodexConf): RestRouter =
|
||||
var router = RestRouter.init(validate)
|
||||
router.api(
|
||||
@ -309,7 +328,6 @@ proc initRestApi*(node: CodexNodeRef, conf: CodexConf): RestRouter =
|
||||
router.api(
|
||||
MethodGet,
|
||||
"/api/codex/v1/debug/peer/{peerId}") do (peerId: PeerId) -> RestApiResponse:
|
||||
|
||||
trace "debug/peer start"
|
||||
without peerRecord =? (await node.findPeer(peerId.get())):
|
||||
trace "debug/peer peer not found!"
|
||||
@ -321,6 +339,31 @@ proc initRestApi*(node: CodexNodeRef, conf: CodexConf): RestRouter =
|
||||
trace "debug/peer returning peer record"
|
||||
return RestApiResponse.response($json)
|
||||
|
||||
when codex_enable_api_debug_fetch:
|
||||
router.api(
|
||||
MethodGet,
|
||||
"/api/codex/v1/debug/fetch/{id}") do (id: Cid) -> RestApiResponse:
|
||||
if id.isErr:
|
||||
return RestApiResponse.error(
|
||||
Http400,
|
||||
$id.error())
|
||||
|
||||
try:
|
||||
trace "Fetching manifest"
|
||||
without manifest =? (await node.fetchManifest(id.get())), error:
|
||||
return RestApiResponse.error(Http404, error.msg)
|
||||
|
||||
trace "Manifest fetched. Fetching blocks.", n=manifest.len
|
||||
if isErr(await node.fetchBatched(manifest)):
|
||||
return RestApiResponse.error(Http404, "fetchBatched failed.")
|
||||
|
||||
let json = formatManifest(manifest)
|
||||
trace "Blocks fetched. Debug/fetch returning manifest"
|
||||
return RestApiResponse.response($json)
|
||||
except CatchableError as exc:
|
||||
trace "Excepting fetching", exc = exc.msg
|
||||
return RestApiResponse.error(Http500)
|
||||
|
||||
router.api(
|
||||
MethodGet,
|
||||
"/api/codex/v1/sales/slots") do () -> RestApiResponse:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user