-
Notifications
You must be signed in to change notification settings - Fork 501
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
feat(files): CAR Import #2323
feat(files): CAR Import #2323
Changes from all commits
bc3c29d
d97c867
a3d7418
9488c3d
f0b44df
742de35
e381d4e
40f58d0
5e324f3
ce09977
e7001ec
f1abecf
1eb486f
0e6bdd4
f2271cc
d234a60
ab8b11f
3820dad
e5b82d2
fb82d3c
0576322
20c87e9
23ab754
fb0f1c2
2b16988
9277e50
979eba8
f886da9
0ea5a82
8263556
9ef6095
b23ef89
a229aa9
5b35fec
a3abcce
bda1817
838aae0
d1ae76f
2b929fc
34f15dc
8c5ff77
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
"openWithLocalAndPublicGateway": "Try opening it instead with your <1>local gateway</1> or <3>public gateway</3>.", | ||
"cantBePreviewed": "Sorry, this file can’t be previewed", | ||
"addByPath": "From IPFS", | ||
"addByCar": "From CAR", | ||
"bulkImport": "Bulk import", | ||
"newFolder": "New folder", | ||
"generating": "Generating…", | ||
|
@@ -60,6 +61,13 @@ | |
"namePlaceholder": "Name (optional)", | ||
"examples": "Examples:" | ||
}, | ||
"addByCarModal": { | ||
"title": "CAR Import", | ||
"description": "Choose a CAR file to import a DAG from and specify a name for it to be imported into the current directory.", | ||
"selectCARButtonText": "Select CAR…", | ||
"namePlaceholder": "Name", | ||
"renameImportPath": "Rename import" | ||
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. new label for rename input |
||
}, | ||
"bulkImportModal": { | ||
"title": "Bulk import with text file", | ||
"description": "Upload a text file with a list of CIDs (names are optional). Example:", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -399,10 +399,56 @@ const actions = () => ({ | |
}), | ||
|
||
/** | ||
* Reads a text file containing CIDs and adds each one to IPFS at the given root path. | ||
* @param {FileStream[]} source - The text file containing CIDs | ||
* @param {string} root - Destination directory in IPFS | ||
*/ | ||
* Adds CAR file. On completion will trigger `doFilesFetch` to update the state. | ||
* @param {string} root | ||
* @param {FileStream} carFile | ||
* @param {string} name | ||
*/ | ||
doAddCarFile: (root, carFile, name = '') => perform(ACTIONS.ADD_CAR_FILE, async (/** @type {IPFSService} */ ipfs, { store }) => { | ||
ensureMFS(store) | ||
|
||
const stream = carFile.content.stream() | ||
try { | ||
// @ts-expect-error - https://github.com/ipfs/js-kubo-rpc-client/issues/278 | ||
const result = await all(ipfs.dag.import(stream, { | ||
Comment on lines
+412
to
+413
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. kubo-rpc-client types need updated. |
||
pinRoots: true | ||
})) | ||
const cid = result[0].root.cid | ||
const src = `/ipfs/${cid}` | ||
const dst = realMfsPath(join(root, name)) | ||
let dstExists = false | ||
|
||
// Check if destination path already exists | ||
await ipfs.files.stat(dst).then(() => { | ||
dstExists = true | ||
}).catch(() => { | ||
// Swallow error. We can add the file to the dst path | ||
SgtPooki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}) | ||
|
||
if (dstExists) { | ||
throw new Error(`The name "${name}" already exists in the current directory. Try importing with a different name.`) | ||
} | ||
SgtPooki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
try { | ||
await ipfs.files.cp(src, dst) | ||
} catch (/** @type {any} */ 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'), { | ||
Comment on lines
+435
to
+437
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. FYI we no longer use countly.. we need to strip it from this repo |
||
code: 'ERR_FILES_CP_FAILED' | ||
}) | ||
} | ||
return carFile | ||
} finally { | ||
await store.doFilesFetch() | ||
} | ||
}), | ||
|
||
/** | ||
* Reads a text file containing CIDs and adds each one to IPFS at the given root path. | ||
* @param {FileStream[]} source - The text file containing CIDs | ||
* @param {string} root - Destination directory in IPFS | ||
*/ | ||
doFilesBulkCidImport: (source, root) => perform(ACTIONS.BULK_CID_IMPORT, async function (ipfs, { store }) { | ||
ensureMFS(store) | ||
|
||
|
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.
note that I removed the custom defined types here so we don't have to manage them later. Ideally this whole IPFSService will be going away and we'll be using types from kubo-rpc-client going forward.