Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
chore: upgrade ipfs-multipart
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Aug 29, 2019
1 parent 6e1730b commit 2521277
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 31 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"err-code": "^2.0.0",
"hamt-sharding": "~0.0.2",
"interface-datastore": "~0.7.0",
"ipfs-multipart": "~0.1.0",
"ipfs-multipart": "~0.2.0",
"ipfs-unixfs": "~0.1.16",
"ipfs-unixfs-exporter": "~0.38.0",
"ipfs-unixfs-importer": "~0.40.0",
Expand Down
54 changes: 24 additions & 30 deletions src/http/write.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,39 +28,33 @@ const mfsWrite = {
shardSplitThreshold
} = request.query

const fileStream = await new Promise((resolve, reject) => {
const parser = multipart.reqParser(request.payload)
let fileStream
let files = 0

parser.on('file', (_, stream) => {
if (fileStream) {
return reject(Boom.badRequest('Please only send one file'))
}

fileStream = stream
resolve(fileStream)
})
for await (const entry of multipart(request)) {
if (entry.type === 'file') {
files++

parser.on('error', (error) => {
reject(error)
})
})
if (files > 1) {
throw Boom.badRequest('Please only send one file')
}

await ipfs.files.write(arg, fileStream, {
offset,
length,
create,
truncate,
rawLeaves,
cidVersion,
hashAlg,
format,
parents,
progress,
strategy,
flush,
shardSplitThreshold
})
await ipfs.files.write(arg, entry.content, {
offset,
length,
create,
truncate,
rawLeaves,
cidVersion,
hashAlg,
format,
parents,
progress,
strategy,
flush,
shardSplitThreshold
})
}
}

return h.response()
},
Expand Down

0 comments on commit 2521277

Please sign in to comment.