This repository was archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 296
feat: support UnixFSv1.5 metadata #1186
Merged
Merged
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a8ca9d5
feat: support UnixFSv1.5 metadata
achingbrain 6a7e5c9
fix: expose new mfs functions
achingbrain 90758e1
refactor: send mtime and mode as headers instead of message parts
achingbrain bf755d2
fix: include headers for directories
achingbrain 65a6ec5
chore: update ipfs utils dep version
achingbrain dbb73e1
Merge remote-tracking branch 'origin/master' into support-unixfs-meta…
achingbrain efe07fd
chore: update ipfs-utils dep
achingbrain a20984c
Merge remote-tracking branch 'origin/master' into support-unixfs-meta…
achingbrain e55f92d
fix: stringify mode in browser
achingbrain 6885692
Merge remote-tracking branch 'origin/master' into support-unixfs-meta…
achingbrain 40d9699
Merge remote-tracking branch 'origin/master' into support-unixfs-meta…
achingbrain d34944e
test: add tests for unixfs metadata
achingbrain 0833e2e
fix: fix up tests etc for optional mtime
achingbrain 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -9,6 +9,16 @@ exports.toFormData = async input => { | |
let i = 0 | ||
|
||
for await (const file of files) { | ||
const headers = {} | ||
|
||
if (file.mtime) { | ||
headers.mtime = file.mtime | ||
} | ||
|
||
if (file.mode) { | ||
headers.mode = file.mode | ||
} | ||
|
||
if (file.content) { | ||
// In the browser there's _currently_ no streaming upload, buffer up our | ||
// async iterator chunks and append a big Blob :( | ||
|
@@ -18,9 +28,13 @@ exports.toFormData = async input => { | |
bufs.push(chunk) | ||
} | ||
|
||
formData.append(`file-${i}`, new Blob(bufs, { type: 'application/octet-stream' }), encodeURIComponent(file.path)) | ||
formData.append(`file-${i}`, new Blob(bufs, { type: 'application/octet-stream' }), encodeURIComponent(file.path), { | ||
header: headers | ||
}) | ||
} else { | ||
formData.append(`dir-${i}`, new Blob([], { type: 'application/x-directory' }), encodeURIComponent(file.path)) | ||
formData.append(`dir-${i}`, new Blob([], { type: 'application/x-directory' }), encodeURIComponent(file.path), { | ||
header: headers | ||
}) | ||
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. I'm not sure this is working... const fd = new FormData
fd.append('test', new Blob(['data'], { type: 'application/octet-stream' }), 'path', { header: { mtime: Date.now(), mode: 'rwx' } })
const opts = { method: 'post', body: fd }
const r0 = new Request('/test', opts)
await r0.text()
"-----------------------------21291924801818001399752183477
Content-Disposition: form-data; name=\"test\"; filename=\"path\"
Content-Type: application/octet-stream
data
-----------------------------21291924801818001399752183477--
" |
||
} | ||
|
||
i++ | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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,24 @@ | ||
'use strict' | ||
|
||
const configure = require('../lib/configure') | ||
|
||
module.exports = configure(({ ky }) => { | ||
return function chmod (path, mode, options) { | ||
options = options || {} | ||
|
||
const searchParams = new URLSearchParams(options.searchParams) | ||
searchParams.append('arg', path) | ||
searchParams.append('mode', mode) | ||
if (options.format) searchParams.set('format', options.format) | ||
if (options.flush != null) searchParams.set('flush', options.flush) | ||
if (options.hashAlg) searchParams.set('hash', options.hashAlg) | ||
if (options.parents != null) searchParams.set('parents', options.parents) | ||
|
||
return ky.post('files/chmod', { | ||
timeout: options.timeout, | ||
signal: options.signal, | ||
headers: options.headers, | ||
searchParams | ||
}).text() | ||
} | ||
}) |
This file contains hidden or 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,29 @@ | ||
'use strict' | ||
|
||
const configure = require('../lib/configure') | ||
|
||
module.exports = configure(({ ky }) => { | ||
return function touch (path, mtime, options) { | ||
options = options || {} | ||
|
||
if (isNaN(mtime)) { | ||
options = mtime | ||
mtime = null | ||
} | ||
|
||
const searchParams = new URLSearchParams(options.searchParams) | ||
searchParams.append('arg', path) | ||
if (mtime) searchParams.set('mtime', mtime) | ||
if (options.format) searchParams.set('format', options.format) | ||
if (options.flush != null) searchParams.set('flush', options.flush) | ||
if (options.hashAlg) searchParams.set('hash', options.hashAlg) | ||
if (options.parents != null) searchParams.set('parents', options.parents) | ||
|
||
return ky.post('files/touch', { | ||
timeout: options.timeout, | ||
signal: options.signal, | ||
headers: options.headers, | ||
searchParams | ||
}).text() | ||
} | ||
}) |
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.
Uh oh!
There was an error while loading. Please reload this page.