mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-02 13:33:10 +00:00
chore(restapi): add headers to support on progress when downloading (#1150)
* Add headers to support on progress on download * Replace http session by http client in downloadBytes * Use int instead of int64 for datasetSize * Rename variable to avoid shallowing client
This commit is contained in:
parent
2a3a29720f
commit
703921df32
@ -114,6 +114,8 @@ proc retrieveCid(
|
||||
else:
|
||||
resp.setHeader("Content-Disposition", "attachment")
|
||||
|
||||
resp.setHeader("Content-Length", $manifest.datasetSize.int)
|
||||
|
||||
await resp.prepareChunked()
|
||||
|
||||
while not stream.atEof:
|
||||
@ -342,6 +344,7 @@ proc initDataApi(node: CodexNodeRef, repoStore: RepoStore, router: var RestRoute
|
||||
resp.setCorsHeaders("GET", corsOrigin)
|
||||
resp.setHeader("Access-Control-Headers", "X-Requested-With")
|
||||
|
||||
resp.setHeader("Access-Control-Expose-Headers", "Content-Disposition")
|
||||
await node.retrieveCid(cid.get(), local = false, resp = resp)
|
||||
|
||||
router.api(MethodGet, "/api/codex/v1/data/{cid}/network/manifest") do(
|
||||
|
||||
@ -76,15 +76,15 @@ proc downloadNoStream*(client: CodexClient, cid: Cid): ?!string =
|
||||
proc downloadBytes*(
|
||||
client: CodexClient, cid: Cid, local = false
|
||||
): Future[?!seq[byte]] {.async.} =
|
||||
let uri =
|
||||
parseUri(client.baseurl & "/data/" & $cid & (if local: "" else: "/network/stream"))
|
||||
let uri = client.baseurl & "/data/" & $cid & (if local: "" else: "/network/stream")
|
||||
|
||||
let (status, bytes) = await client.session.fetch(uri)
|
||||
let httpClient = newHttpClient()
|
||||
let response = httpClient.get(uri)
|
||||
|
||||
if status != 200:
|
||||
return failure("fetch failed with status " & $status)
|
||||
if response.status != "200 OK":
|
||||
return failure("fetch failed with status " & $response.status)
|
||||
|
||||
success bytes
|
||||
success response.body.toBytes
|
||||
|
||||
proc delete*(client: CodexClient, cid: Cid): ?!void =
|
||||
let
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user