This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
WIP: Modify response to add body in React Native and logging daemon requests #2874
Closed
pcowgill
wants to merge
23
commits into
ipfs:master
from
pcowgill:feature/logging-requests-and-stub-body
Closed
Changes from 16 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
d4826e1
Logging incoming requests
pcowgill c486583
Merge branch 'master' into feature/logging-add-requests
pcowgill 8f44ff1
Formatting fixes
pcowgill 5f29e6d
Fixed indentation
pcowgill 06a20c2
More formatting reversions
pcowgill 14f3b1b
More formatting reversions
pcowgill 14ace22
More formatting reversions
pcowgill 427fa4a
More formatting reversions
pcowgill c32b769
Undoing accidental lerna changes
pcowgill dd88b64
Fixing root package.json
pcowgill 6f4e910
Undoing autoformatting
pcowgill 24d6a9c
Undoing autoformatting
pcowgill 6d6d6f2
Undoing autoformatting
pcowgill 3633f92
Undoing autoformatting
pcowgill 4147294
Handle case where responses have no body with a getter
pcowgill 8c87db2
package.json newline at end
pcowgill 7c3496c
Missing newlines
pcowgill b62022b
Including local changes to ipfs-multipart
pcowgill b5ff4b9
Fix lint errors
pcowgill f92f5ed
Moved ipfs-http-client and ipfs-utils logs to monorepo
pcowgill 3d7f3c7
Merge branch 'master' into feature/logging-requests-and-stub-body
pcowgill 094161b
Logging monorepo version usage and function name
pcowgill 8352224
Merge branch 'master' into feature/logging-requests-and-stub-body
pcowgill File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
const ndjson = require('iterable-ndjson') | ||
const CID = require('cids') | ||
const configure = require('../lib/configure') | ||
const toIterable = require('stream-to-it/source') | ||
const toAsyncIterable = require('../lib/stream-to-async-iterable') | ||
const { toFormData } = require('./form-data') | ||
const toCamel = require('../lib/object-to-camel') | ||
|
||
|
@@ -32,16 +32,18 @@ module.exports = configure(({ ky }) => { | |
if (options.preload != null) searchParams.set('preload', options.preload) | ||
if (options.fileImportConcurrency != null) searchParams.set('file-import-concurrency', options.fileImportConcurrency) | ||
if (options.blockWriteConcurrency != null) searchParams.set('block-write-concurrency', options.blockWriteConcurrency) | ||
|
||
|
||
const formData = await toFormData(input) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hugomrdias @achingbrain Do you have any stylistic objections to building |
||
|
||
const res = await ky.post('add', { | ||
timeout: options.timeout, | ||
signal: options.signal, | ||
headers: options.headers, | ||
searchParams, | ||
body: await toFormData(input) | ||
body: formData | ||
}) | ||
|
||
for await (let file of ndjson(toIterable(res.body))) { | ||
for await (let file of ndjson(toAsyncIterable(res))) { | ||
file = toCamel(file) | ||
|
||
if (options.progress && file.bytes) { | ||
|
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
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
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
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
const { Buffer } = require('buffer') | ||
const configure = require('../lib/configure') | ||
const toIterable = require('stream-to-it/source') | ||
const toAsyncIterable = require('../lib/stream-to-async-iterable') | ||
|
||
module.exports = configure(({ ky }) => { | ||
return async function * read (path, options) { | ||
|
@@ -20,7 +20,7 @@ module.exports = configure(({ ky }) => { | |
searchParams | ||
}) | ||
|
||
for await (const chunk of toIterable(res.body)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hugomrdias It's interesting that there are still some methods where this |
||
for await (const chunk of toAsyncIterable(res)) { | ||
yield Buffer.from(chunk) | ||
} | ||
} | ||
|
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
27 changes: 27 additions & 0 deletions
27
packages/ipfs-http-client/src/lib/stream-to-async-iterable.js
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict' | ||
|
||
const toAsyncIterableOriginal = require('stream-to-it/source') | ||
|
||
// Note: Turned this into a helper that wraps `stream-to-it/source` | ||
// to handle the body undefined case without requiring that other libs | ||
// that consume that package such as `js-ipfs` and `js-ipfs-utils` modify | ||
// how they use it | ||
|
||
module.exports = function toAsyncIterable (res) { | ||
const { body } = res | ||
|
||
// An env where res.body getter for ReadableStream with getReader | ||
// is not supported, for example in React Native | ||
if (!body) { | ||
if (res.arrayBuffer) { | ||
return (async function * () { | ||
const arrayBuffer = await res.arrayBuffer() | ||
yield arrayBuffer | ||
})() | ||
} else { | ||
throw new Error('Neither Response.body nor Response.arrayBuffer is defined') | ||
} | ||
} | ||
|
||
return toAsyncIterableOriginal(body) | ||
} |
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any objections to these changes making it into the
.gitignore
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hugomrdias @achingbrain Thoughts? Thanks!