Skip to content

Commit

Permalink
Add parsing to auto add / for MFS paths (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsmedley authored Sep 17, 2024
1 parent 730ddba commit c88ec0a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
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

0 comments on commit c88ec0a

Please sign in to comment.