From 0fcdaff93701c10cd4acca60cfcf261d9dd8e473 Mon Sep 17 00:00:00 2001 From: Bulat-Ziganshin Date: Thu, 25 Aug 2022 01:59:45 +0300 Subject: [PATCH] Renamed REST param to "chunk" Also, call node.store without blockSize param if "?chunk" isn't specified in the upload URL --- codex/rest/api.nim | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/codex/rest/api.nim b/codex/rest/api.nim index de75091b..6b374de8 100644 --- a/codex/rest/api.nim +++ b/codex/rest/api.nim @@ -161,10 +161,10 @@ proc initRestApi*(node: CodexNodeRef, conf: CodexConf): RestRouter = router.rawApi( MethodPost, "/api/codex/v1/upload") do ( - blockSize: Option[uint] + chunk: Option[uint] ) -> RestApiResponse: ## Upload a file in a streamming manner, - ## split it into blocks of blockSize, + ## split it into blocks of `chunk` bytes, ## and save to the node's BlockStore ## @@ -177,12 +177,16 @@ proc initRestApi*(node: CodexNodeRef, conf: CodexConf): RestRouter = # wait 1000ms before giving up await request.handleExpect() - let - bodyStream = AsyncStreamWrapper.new(reader = AsyncStreamReader(bodyReader.get)) - blockSize = (blockSize.get |? BlockSize).int + let bodyStream = AsyncStreamWrapper.new(reader = AsyncStreamReader(bodyReader.get)) try: - without cid =? (await node.store(bodyStream, blockSize)), error: + let runUpload = + if blockSize =? chunk.get: + node.store(bodyStream, blockSize = blockSize.int) + else: + node.store(bodyStream) + + without cid =? (await runUpload), error: trace "Error uploading file", exc = error.msg return RestApiResponse.error(Http500, error.msg)