-
-
Save achingbrain/993c7c2d8570a90320a9810d6d46afec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/packages/ipfs-http-server/src/api/resources/dag.js b/packages/ipfs-http-server/src/api/resources/dag.js | |
index b76e19a3..17d8dab7 100644 | |
--- a/packages/ipfs-http-server/src/api/resources/dag.js | |
+++ b/packages/ipfs-http-server/src/api/resources/dag.js | |
@@ -9,6 +9,7 @@ const { | |
} = require('ipfs-core-utils/src/cid') | |
const all = require('it-all') | |
const uint8ArrayToString = require('uint8arrays/to-string') | |
+const { PassThrough } = require('stream') | |
const encodeBufferKeys = (obj, encoding) => { | |
if (!obj) { | |
@@ -220,6 +221,40 @@ exports.put = { | |
} | |
} = request | |
+ const stream = new PassThrough() | |
+ | |
+ // wait a bit before sending the response | |
+ setTimeout(async () => { | |
+ let cid | |
+ | |
+ try { | |
+ cid = await ipfs.dag.put(node, { | |
+ format, | |
+ hashAlg, | |
+ pin, | |
+ signal, | |
+ timeout | |
+ }) | |
+ } catch (err) { | |
+ throw Boom.boomify(err, { message: 'Failed to put node' }) | |
+ } | |
+ | |
+ stream.end(Buffer.from(JSON.stringify({ | |
+ Cid: { | |
+ '/': cidToString(cid, { | |
+ base: cidBase | |
+ }) | |
+ } | |
+ }))) | |
+ }, 100) | |
+ | |
+ // start writing some output so the client starts moving | |
+ stream.write(' ') | |
+ | |
+ return stream | |
+ | |
+/* | |
+ | |
let cid | |
try { | |
@@ -241,6 +276,8 @@ exports.put = { | |
}) | |
} | |
}) | |
+ | |
+ */ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment