mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-10 01:13:10 +00:00
fixing problems after rebasing
This commit is contained in:
parent
b0ec507c70
commit
cbaace39a9
@ -137,8 +137,13 @@ proc uploadTorrent*(
|
||||
]
|
||||
let response =
|
||||
await client.post(client.baseurl & "/torrent", body = contents, headers = headers)
|
||||
assert response.status == 200
|
||||
MultiHash.init((await response.body).hexToSeqByte).mapFailure
|
||||
if not response.status == 200:
|
||||
return failure($response.status)
|
||||
let body = await response.body
|
||||
let bytesRes = catch(body.hexToSeqByte)
|
||||
without bytes =? bytesRes, err:
|
||||
return failure(err)
|
||||
MultiHash.init(bytes).mapFailure
|
||||
|
||||
proc uploadTorrent*(
|
||||
client: CodexClient, bytes: seq[byte], filename = string.none
|
||||
@ -180,6 +185,17 @@ proc downloadNoStream*(
|
||||
|
||||
success await response.body
|
||||
|
||||
proc downloadTorrent*(
|
||||
client: CodexClient, infoHash: MultiHash
|
||||
): Future[?!string] {.async: (raises: [CancelledError, HttpError]).} =
|
||||
let response =
|
||||
await client.get(client.baseurl & "/torrent/" & infoHash.hex & "/network/stream")
|
||||
|
||||
if response.status != 200:
|
||||
return failure($response.status)
|
||||
|
||||
success await response.body
|
||||
|
||||
proc downloadManifestOnly*(
|
||||
client: CodexClient, cid: Cid
|
||||
): Future[?!string] {.async: (raises: [CancelledError, HttpError]).} =
|
||||
@ -193,7 +209,7 @@ proc downloadManifestOnly*(
|
||||
|
||||
proc downloadTorrentManifestOnly*(
|
||||
client: CodexClient, infoHash: MultiHash
|
||||
): Future[?!RestTorrentContent] =
|
||||
): Future[?!RestTorrentContent] {.async: (raises: [CancelledError, HttpError]).} =
|
||||
let response =
|
||||
await client.get(client.baseurl & "/torrent/" & infoHash.hex & "/network/manifest")
|
||||
|
||||
|
||||
@ -57,8 +57,8 @@ proc createInfoDictionaryForContent(
|
||||
twonodessuite "BitTorrent API":
|
||||
test "uploading and downloading the content", twoNodesConfig:
|
||||
let exampleContent = exampleString(100)
|
||||
let infoHash = client1.uploadTorrent(exampleContent).tryGet
|
||||
let downloadedContent = client2.downloadTorrent(infoHash).tryGet
|
||||
let infoHash = (await client1.uploadTorrent(exampleContent)).tryGet
|
||||
let downloadedContent = (await client2.downloadTorrent(infoHash)).tryGet
|
||||
check downloadedContent == exampleContent
|
||||
|
||||
test "uploading and downloading the content (exactly one piece long)", twoNodesConfig:
|
||||
@ -67,8 +67,8 @@ twonodessuite "BitTorrent API":
|
||||
blocks = numOfBlocksPerPiece, blockSize = BitTorrentBlockSize.int
|
||||
)
|
||||
|
||||
let infoHash = client1.uploadTorrent(bytes).tryGet
|
||||
let downloadedContent = client2.downloadTorrent(infoHash).tryGet
|
||||
let infoHash = (await client1.uploadTorrent(bytes)).tryGet
|
||||
let downloadedContent = (await client2.downloadTorrent(infoHash)).tryGet
|
||||
check downloadedContent.toBytes == bytes
|
||||
|
||||
test "uploading and downloading the content (exactly two pieces long)", twoNodesConfig:
|
||||
@ -77,8 +77,8 @@ twonodessuite "BitTorrent API":
|
||||
blocks = numOfBlocksPerPiece * 2, blockSize = BitTorrentBlockSize.int
|
||||
)
|
||||
|
||||
let infoHash = client1.uploadTorrent(bytes).tryGet
|
||||
let downloadedContent = client2.downloadTorrent(infoHash).tryGet
|
||||
let infoHash = (await client1.uploadTorrent(bytes)).tryGet
|
||||
let downloadedContent = (await client2.downloadTorrent(infoHash)).tryGet
|
||||
check downloadedContent.toBytes == bytes
|
||||
|
||||
# use with debugging to see the content
|
||||
@ -90,24 +90,28 @@ twonodessuite "BitTorrent API":
|
||||
test "retrieving torrent manifest for given info hash", twoNodesConfig:
|
||||
let exampleFileName = "example.txt"
|
||||
let exampleContent = exampleString(100)
|
||||
let infoHash = client1.uploadTorrent(
|
||||
contents = exampleContent,
|
||||
filename = some exampleFileName,
|
||||
contentType = "text/plain",
|
||||
let infoHash = (
|
||||
await client1.uploadTorrent(
|
||||
contents = exampleContent,
|
||||
filename = some exampleFileName,
|
||||
contentType = "text/plain",
|
||||
)
|
||||
).tryGet
|
||||
|
||||
let expectedInfo = createInfoDictionaryForContent(
|
||||
content = exampleContent.toBytes, name = some exampleFileName
|
||||
).tryGet
|
||||
|
||||
let restTorrentContent = client2.downloadTorrentManifestOnly(infoHash).tryGet
|
||||
let restTorrentContent =
|
||||
(await client2.downloadTorrentManifestOnly(infoHash)).tryGet
|
||||
let torrentManifest = restTorrentContent.torrentManifest
|
||||
let info = torrentManifest.info
|
||||
|
||||
check info == expectedInfo
|
||||
|
||||
let response =
|
||||
client2.downloadManifestOnly(cid = torrentManifest.codexManifestCid).tryGet
|
||||
let response = (
|
||||
await client2.downloadManifestOnly(cid = torrentManifest.codexManifestCid)
|
||||
).tryGet
|
||||
|
||||
let restContent = RestContent.fromJson(response).tryGet
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user