Skip to content

Commit

Permalink
fix: add folder and error on adding folder with same name (#924)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsdiogo authored and olizilla committed Jan 4, 2019
1 parent c491557 commit e06d340
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
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) {
// 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

0 comments on commit e06d340

Please sign in to comment.