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

Add parsing to auto add / for MFS paths #10

Merged
merged 4 commits into from
Sep 17, 2024
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
5 changes: 3 additions & 2 deletions src/objectManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class ObjectManager {
* // Upload Directory
* await objectManager.upload("my-first-directory", [
* {
* path: "/testObjects/1.txt",
* path: "/testObjects/1.txt", // Virtual Path to store contents at within IPFS Folder/Directory
* content: Buffer.from("upload test object", "utf-8"),
* },
* {
Expand Down Expand Up @@ -206,7 +206,8 @@ class ObjectManager {
});
let createFilePromises = [];
const queue = new PQueue({ concurrency: 50 });
for (const entry of source) {
for (let entry of source) {
entry.path = entry.path.startsWith("/") ? entry.path : `/${entry.path}`;
if (entry.content === null) {
continue;
}
Expand Down
32 changes: 32 additions & 0 deletions test/objectManager.spec.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,38 @@ test("upload directory", async () => {
}
});

test("upload directory relative paths", async () => {
// Create Bucket `create-object-test-pass
const uploadDirectoryTestBucket = `${TEST_PREFIX}-create-directory-relative-test-pass`;
await createBucket(uploadDirectoryTestBucket);

try {
// Upload object `create-object-test`
const uploaded = await uploadObject(
uploadDirectoryTestBucket,
`create-directory-relative-test`,
[
{
path: "testObjects/1.txt",
content: Buffer.from("upload test object", "utf-8"),
},
{
path: "testObjects/deep/1.txt",
content: Buffer.from("upload deep test object", "utf-8"),
},
{
path: "topLevel.txt",
content: Buffer.from("upload top level test object", "utf-8"),
},
],
);
assert.strictEqual(uploaded, true);
await deleteObject(uploadDirectoryTestBucket, `create-directory-relative-test`);
} finally {
await deleteBucket(uploadDirectoryTestBucket);
}
});

test("download object", async () => {
// Create bucket `download-object-test-pass`
const downloadTestBucket = `${TEST_PREFIX}-download-object-test-pass`;
Expand Down
Loading