-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update deps in api and client (#855)
- Loading branch information
1 parent
b60fa1c
commit 22155db
Showing
10 changed files
with
1,743 additions
and
1,748 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,26 @@ | ||
const { importer } = require('ipfs-unixfs-importer') | ||
|
||
const block = { | ||
get: async cid => { throw new Error(`unexpected block API get for ${cid}`) }, | ||
put: async () => { throw new Error('unexpected block API put') } | ||
} | ||
const { CarReader } = require('@ipld/car') | ||
|
||
/** | ||
* https://github.com/sinedied/smoke#javascript-mocks | ||
* @typedef {{ buffer: Buffer, originalname: string }} MultrFile | ||
* @param {{ query: Record<string, string>, files: MultrFile[] }} request | ||
*/ | ||
module.exports = async ({ files, query }) => { | ||
const results = [] | ||
|
||
const options = { | ||
onlyHash: true, | ||
cidVersion: 1, | ||
rawLeaves: true | ||
} | ||
|
||
const candidateImports = files.map((f) => ({ content: f.buffer })) | ||
for await (const { cid } of importer(candidateImports, block, options)) { | ||
results.push({ | ||
cid: { | ||
'/': cid.toString() | ||
} | ||
}) | ||
module.exports = async ({ query, files }) => { | ||
const car = await CarReader.fromBytes(files[0].buffer) | ||
const roots = await car.getRoots() | ||
// @ts-ignore | ||
const { cid, bytes } = await car.get(roots[0]) | ||
const result = { | ||
cid: { | ||
'/': cid.toString() | ||
}, | ||
name: files[0].originalname, | ||
// car uploads may not be unixfs, so get a bytes property instead of `size` https://github.com/ipfs/ipfs-cluster/issues/1362 | ||
bytes: bytes.length | ||
} | ||
return { | ||
statusCode: 200, | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: query['stream-channels'] === 'false' ? results : results[0] | ||
body: query['stream-channels'] === 'false' ? [result] : result | ||
} | ||
} |
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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