Skip to content

Commit

Permalink
Merge pull request #47 from dimitrov-d/master
Browse files Browse the repository at this point in the history
Update storage upload and tests
  • Loading branch information
dimitrov-d authored Feb 12, 2025
2 parents 93ae418 + d17b4c2 commit 169484d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@apillon/cli",
"description": "▶◀ Apillon CLI tools ▶◀",
"version": "1.6.0",
"version": "1.7.1",
"author": "Apillon",
"license": "MIT",
"main": "./dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@apillon/sdk",
"description": "▶◀ Apillon SDK for NodeJS ▶◀",
"version": "3.8.3",
"version": "3.8.4",
"author": "Apillon",
"license": "MIT",
"main": "./dist/index.js",
Expand Down
4 changes: 4 additions & 0 deletions packages/sdk/src/tests/helpers/website/style2.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
h2 {
color: blue;
text-align: center;
}
29 changes: 26 additions & 3 deletions packages/sdk/src/tests/storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ describe('Storage tests', () => {
const css = fs.readFileSync(
resolve(__dirname, './helpers/website/style.css'),
);
const css2 = fs.readFileSync(
resolve(__dirname, './helpers/website/style2.css'),
);
console.time('File upload complete');
const files = await storage.bucket(bucketUuid).uploadFiles(
[
Expand All @@ -114,15 +117,34 @@ describe('Storage tests', () => {
path: null,
content: css,
},
{
fileName: 'style2.css',
contentType: 'text/css',
path: null,
content: css2,
},
],
{ directoryPath: 'main/subdir' },
);

expect(files.length).toBe(1);
expect(files[0].CID).toBeDefined();
expect(files.length).toBe(2);
expect(files[0].CID).toBe(
'bafybeibjawzowog5hmybfo6i7yaowsgwnmgdy6m3665da7xxpu2lwqjmia',
);
expect(files[0].fileUuid).toBeDefined();
expect(files[0].path).toBeNull();
expect(files[0].url).toBeDefined();
expect(files[0].url).toContain(
'https://bafybeibjawzowog5hmybfo6i7yaowsgwnmgdy6m3665da7xxpu2lwqjmia',
);

expect(files[1].CID).toBe(
'bafybeihvpgcpq4cvhuhx7lobnv4zirzhk2ftgbf7hoqsphszabz7dxvwkq',
);
expect(files[1].fileUuid).toBeDefined();
expect(files[1].path).toBeNull();
expect(files[1].url).toContain(
'https://bafybeihvpgcpq4cvhuhx7lobnv4zirzhk2ftgbf7hoqsphszabz7dxvwkq',
);

console.timeEnd('File upload complete');
});
Expand All @@ -131,6 +153,7 @@ describe('Storage tests', () => {
const css = fs.readFileSync(
resolve(__dirname, './helpers/website/style.css'),
);

console.time('File upload complete');
const files = await storage.bucket(bucketUuid).uploadFiles(
[
Expand Down
13 changes: 2 additions & 11 deletions packages/sdk/src/util/file-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,9 @@ export async function uploadFiles(uploadParams: {
},
);

// Upload doesn't return files in the same order as sent
const sortedFiles = metadata.files.map((metaFile) =>
files.find(
(file) =>
file.fileName === metaFile.fileName &&
(!file.path || file.path === metaFile.path),
),
);

await uploadFilesToS3(sortedFiles, fileGroup);
await uploadFilesToS3(files, fileGroup);

const filesWithUrl = sortedFiles.map((file, index) => ({
const filesWithUrl = files.map((file, index) => ({
...file,
CID: metadata.cids[index],
url: metadata.urls[index],
Expand Down

0 comments on commit 169484d

Please sign in to comment.