Skip to content

Instantly share code, notes, and snippets.

@achingbrain
Created January 12, 2021 12:24
Show Gist options
  • Save achingbrain/993c7c2d8570a90320a9810d6d46afec to your computer and use it in GitHub Desktop.
Save achingbrain/993c7c2d8570a90320a9810d6d46afec to your computer and use it in GitHub Desktop.
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