diff --git a/packages/cli/README.md b/packages/cli/README.md index 95d69b2..7b34828 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -373,7 +373,6 @@ Upload contents of a local folder to specified bucket. - `-b, --bucket-uuid `: UUID of the bucket to upload files to. - `-w, --wrap`: Wrap uploaded files to an IPFS directory - `-p, --path `: Path to upload files to (e.g. main/subdir). Required when --wrap is supplied. -- `--await`: await file CIDs to be resolved **Example** diff --git a/packages/cli/package.json b/packages/cli/package.json index b720d6e..91f02eb 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,7 +1,7 @@ { "name": "@apillon/cli", "description": "▶◀ Apillon CLI tools ▶◀", - "version": "1.5.0", + "version": "1.6.0", "author": "Apillon", "license": "MIT", "main": "./dist/index.js", diff --git a/packages/cli/src/modules/storage/storage.commands.ts b/packages/cli/src/modules/storage/storage.commands.ts index e461502..2968106 100644 --- a/packages/cli/src/modules/storage/storage.commands.ts +++ b/packages/cli/src/modules/storage/storage.commands.ts @@ -67,7 +67,10 @@ export function createStorageCommands(cli: Command) { .requiredOption('-b, --bucket-uuid ', 'UUID of destination bucket') .option('-w, --wrap', 'Wrap uploaded files to an IPFS directory') .option('-p, --path ', 'Path to upload files to') - .option('--await', 'await file CIDs to be resolved') + .option( + '--await', + 'await file CIDs to be resolved (DEPRECATED - CIDs are now resolved automatically)', + ) .option('--ignore', 'ignore files from .gitignore file') .action(async function (path: string) { await uploadFromFolder(path, this.optsWithGlobals()); diff --git a/packages/sdk/package.json b/packages/sdk/package.json index e868f18..421aa48 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -1,7 +1,7 @@ { "name": "@apillon/sdk", "description": "▶◀ Apillon SDK for NodeJS ▶◀", - "version": "3.6.0", + "version": "3.7.0", "author": "Apillon", "license": "MIT", "main": "./dist/index.js", diff --git a/packages/sdk/src/modules/rpc/rpc-api-key.ts b/packages/sdk/src/modules/rpc/rpc-api-key.ts index f158edf..4a63294 100644 --- a/packages/sdk/src/modules/rpc/rpc-api-key.ts +++ b/packages/sdk/src/modules/rpc/rpc-api-key.ts @@ -29,7 +29,7 @@ export class RpcApiKey extends ApillonModel { /** * Array of favorite URLs for the RPC API key. */ - public urls: string[] = []; + public urls: string[] = null; /** * Constructor which should only be called via Rpc class. diff --git a/packages/sdk/src/tests/rpc.test.ts b/packages/sdk/src/tests/rpc.test.ts index cf24be0..2e178ec 100644 --- a/packages/sdk/src/tests/rpc.test.ts +++ b/packages/sdk/src/tests/rpc.test.ts @@ -43,6 +43,7 @@ describe('Rpc Module tests', () => { expect(apiKey).toBeInstanceOf(RpcApiKey); expect(apiKey.id).toEqual(apiKeyId); + expect(apiKey.urls.length).toBeGreaterThan(0); }); test('List endpoints', async () => { diff --git a/packages/sdk/src/tests/storage.test.ts b/packages/sdk/src/tests/storage.test.ts index f2654dd..4b37974 100644 --- a/packages/sdk/src/tests/storage.test.ts +++ b/packages/sdk/src/tests/storage.test.ts @@ -86,22 +86,10 @@ describe('Storage tests', () => { console.timeEnd('File upload complete'); expect(files.every((f) => !!f.fileUuid)).toBeTruthy(); - }); - - test('upload files from folder with awaitCid', async () => { - const uploadDir = resolve(__dirname, './helpers/website/'); - - console.time('File upload complete'); - const files = await storage - .bucket(bucketUuid) - .uploadFromFolder(uploadDir, { awaitCid: true }); - console.timeEnd('File upload complete'); - - expect(files.length).toBeGreaterThan(0); expect(files.every((f) => !!f.CID)).toBeTruthy(); }); - test('upload files from folder with ignoreFiles = false', async () => { + test('upload files from folder with ignoreFiles=false', async () => { const uploadDir = resolve(__dirname, './helpers/website/'); // .gitignore and index.html are not ignored @@ -114,9 +102,6 @@ describe('Storage tests', () => { }); test('upload files from buffer', async () => { - // const html = fs.readFileSync( - // resolve(__dirname, './helpers/website/index.html'), - // ); const css = fs.readFileSync( resolve(__dirname, './helpers/website/style.css'), ); @@ -130,7 +115,7 @@ describe('Storage tests', () => { content: css, }, ], - { wrapWithDirectory: true, directoryPath: 'main/subdir' }, + { directoryPath: 'main/subdir' }, ); expect(files.length).toBe(1); @@ -142,6 +127,32 @@ describe('Storage tests', () => { console.timeEnd('File upload complete'); }); + test('upload files from buffer with wrapWithDirectory=true', async () => { + const css = fs.readFileSync( + resolve(__dirname, './helpers/website/style.css'), + ); + console.time('File upload complete'); + const files = await storage.bucket(bucketUuid).uploadFiles( + [ + { + fileName: 'style.css', + contentType: 'text/css', + path: null, + content: css, + }, + ], + { wrapWithDirectory: true, directoryPath: 'main/subdir-wrapped' }, + ); + + expect(files.length).toBe(1); + expect(files[0].fileUuid).toBeDefined(); + expect(files[0].CID).toBeUndefined(); + expect(files[0].path).toBeNull(); + expect(files[0].url).toBeUndefined(); + + console.timeEnd('File upload complete'); + }); + describe.skip('File detail tests', () => { test('get file details', async () => { const file = await storage.bucket(bucketUuid).file(fileUuid).get(); diff --git a/packages/sdk/src/util/file-utils.ts b/packages/sdk/src/util/file-utils.ts index 35cd753..9b69cd6 100644 --- a/packages/sdk/src/util/file-utils.ts +++ b/packages/sdk/src/util/file-utils.ts @@ -53,30 +53,22 @@ export async function uploadFiles(uploadParams: { const uploadedFiles = []; for (const fileGroup of chunkify(files, fileChunkSize)) { - if (params.wrapWithDirectory) { + if (params?.wrapWithDirectory) { for (const fg of fileGroup) { - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const { content, ...rest } = fg; - - const readContent = fg.index ? fs.readFileSync(fg.index) : fg.content; - - fg.content = readContent; + fg.content = fg.index ? fs.readFileSync(fg.index) : fg.content; } const { files } = await ApillonApi.post( `${apiPrefix}/upload`, { - files: fileGroup.map((fg) => { - // Remove content property from the payload - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const { content, ...rest } = fg; - return rest; - }), + // eslint-disable-next-line @typescript-eslint/no-unused-vars + files: fileGroup.map(({ content, ...rest }) => rest), sessionUuid, }, ); await uploadFilesToS3(files, fileGroup); + files.forEach((file: any) => delete file.url); uploadedFiles.push(files); } else { @@ -105,9 +97,7 @@ export async function uploadFiles(uploadParams: { const { links } = await ApillonApi.post<{ links: string[] }>( `/storage/link-on-ipfs-multiple`, - { - cids: metadata.cids, - }, + { cids: metadata.cids }, ); metadata.urls = links; @@ -120,19 +110,17 @@ export async function uploadFiles(uploadParams: { ); // Upload doesn't return files in the same order as sent - const sortedFiles = metadata.files.map((metaFile) => { - return files.find((file) => file.fileName === metaFile.fileName); - }); + const sortedFiles = metadata.files.map((metaFile) => + files.find((file) => file.fileName === metaFile.fileName), + ); await uploadFilesToS3(sortedFiles, fileGroup); - const filesWithUrl = sortedFiles.map((file, index) => { - return { - ...file, - CID: metadata.cids[index], - url: metadata.urls[index], - }; - }); + const filesWithUrl = sortedFiles.map((file, index) => ({ + ...file, + CID: metadata.cids[index], + url: metadata.urls[index], + })); uploadedFiles.push(filesWithUrl); } }