Skip to content

Commit

Permalink
feat: add import car file
Browse files Browse the repository at this point in the history
  • Loading branch information
badgooooor committed Feb 3, 2025
1 parent 742de35 commit e381d4e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
23 changes: 21 additions & 2 deletions src/bundles/files/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 +403,29 @@ const actions = () => ({
* @param {File} file
* @param {string} name
*/
doAddCarFile: (file, name = '') => perform(ACTIONS.ADD_CAR_FILE, async (ipfs, { store }) => {
doAddCarFile: (file, name = '', root = '') => perform(ACTIONS.ADD_CAR_FILE, async (ipfs, { store }) => {
ensureMFS(store)

console.log('todo: implement upload to ipfs', file, name)
try {
const result = await ipfs.add(file, {
pin: false,
wrapWithDirectory: false
})
const src = `/ipfs/${result.cid}`
const dst = join(realMfsPath(root || '/files'), result.path)
try {
await ipfs.files.cp(src, dst)
} catch (err) {
// TODO: Not sure why we do this. Perhaps a generic error is used
// to avoid leaking private information via Countly?
throw Object.assign(new Error('ipfs.files.cp call failed'), {
code: 'ERR_FILES_CP_FAILED'
})
}
return file
} finally {
await store.doFilesFetch()
}
}),

/**
Expand Down
6 changes: 5 additions & 1 deletion src/files/FilesPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ const FilesPage = ({
}

const onAddByPath = (path, name) => doFilesAddPath(files.path, path, name)
const onAddByCar = (file, name) => doAddCarFile(file, name)
const onAddByCar = (file, name, root = '') => {
if (root === '') root = files.path

doAddCarFile(file, name, root)
}
const onInspect = (cid) => doUpdateHash(`/explore/${cid}`)
const showModal = (modal, files = null) => setModals({ show: modal, files })
const hideModal = () => setModals({})
Expand Down

0 comments on commit e381d4e

Please sign in to comment.