Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add folder #924

Merged
merged 1 commit into from
Jan 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion public/locales/en/notify.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"ipfsApiRequestFailed": "IPFS request failed. Please check if your daemon is running.",
"windowIpfsRequestFailed": "IPFS request failed. Please check your IPFS Companion settings.",
"ipfsIsBack": "Normal IPFS service has resumed. Enjoy!",
"filesEventFailed": "Failed to add files to IPFS. Please try again."
"filesEventFailed": "Failed to add files to IPFS. Please try again.",
"folderExists": "A folder with that name already exists. Please choose another."
}
11 changes: 8 additions & 3 deletions src/bundles/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,17 +241,22 @@ export default (opts = {}) => {
progress: updateProgress
})

if (res.length !== streams.length + 1) {
if (res.length !== streams.length + 2) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure when this changed, but it was always failing because of this!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting, it's returning an entry for the folder, and the parent of the folder. This fixes our logic around it, so +1

// See https://github.com/ipfs/js-ipfs-api/issues/797
throw new Error('Unable to finish upload: IPFS API returned a partial response. Try adding a smaller tree.')
throw Object.assign(new Error(`API returned a partial response.`), { code: 'ERR_API_RESPONSE' })
}

for (const { path, hash } of res) {
// Only go for direct children
if (path.indexOf('/') === -1 && path !== '') {
const src = `/ipfs/${hash}`
const dst = join(root, path)
await ipfs.files.cp([src, dst])

try {
await ipfs.files.cp([src, dst])
} catch (err) {
throw Object.assign(new Error(`Folder already exists.`), { code: 'ERR_FOLDER_EXISTS' })
}
}
}

Expand Down
12 changes: 7 additions & 5 deletions src/bundles/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import { createSelector } from 'redux-bundler'
# Notify
- show error when ipfs goes away.
- show ok when it comes back.
- dismiss the the ok after 3s
- dismiss the ok after 3s
*/

const defaultState = {
show: false,
error: false,
eventId: null
eventId: null,
code: null
}

const notify = {
Expand All @@ -35,7 +36,8 @@ const notify = {
...state,
show: true,
error: true,
eventId: 'FILES_EVENT_FAILED'
eventId: 'FILES_EVENT_FAILED',
code: action.payload.error.code
}
}

Expand All @@ -57,14 +59,14 @@ const notify = {
'selectNotify',
'selectIpfsProvider',
(notify, provider) => {
const { eventId } = notify
const { eventId, code } = notify

if (eventId === 'STATS_FETCH_FAILED') {
return provider === 'window.ipfs' ? 'windowIpfsRequestFailed' : 'ipfsApiRequestFailed'
}

if (eventId === 'FILES_EVENT_FAILED') {
return 'filesEventFailed'
return code === 'ERR_FOLDER_EXISTS' ? 'folderExists' : 'filesEventFailed'
}

if (eventId === 'STATS_FETCH_FINISHED') {
Expand Down