diff --git a/packages/sdk/README.md b/packages/sdk/README.md index 47e1901..0588dce 100644 --- a/packages/sdk/README.md +++ b/packages/sdk/README.md @@ -175,6 +175,10 @@ await bucket.listObjects({ // list all files in a bucket no matter if they are in a folder or not await bucket.listFiles({ fileStatus: FileStatus.UPLOADED }); +// generate an IPFS link for a CID +const cid = 'bafybeigjhyc2tpvqfqsuvf3byo4e4a4v6spi6jk4qqvvtlpca6rsaf2cqi'; +const link = await storage.generateIpfsLink(cid); + // gets a specific file in a bucket directly through uuid const file = await bucket.file('2195521d-15cc-4f6e-abf2-13866f9c6e03').get(); diff --git a/packages/sdk/src/modules/storage/storage.ts b/packages/sdk/src/modules/storage/storage.ts index 6bcda0c..8a21bf5 100644 --- a/packages/sdk/src/modules/storage/storage.ts +++ b/packages/sdk/src/modules/storage/storage.ts @@ -71,11 +71,12 @@ export class Storage extends ApillonModule { * Apillon IPFS gateways are private and can only be accessible with a token. * @docs [Generate an IPFS link](https://wiki.apillon.io/build/2-storage-api.html#get-or-generate-link-for-ipfs) * @param {string} cid The CID or IPNS address of the fie - * @returns {Promise<{ link: string }>} Link where the requested content can be accessed. + * @returns {Promise} The IPFS link where the requested content can be accessed. */ - public async generateIpfsLink(cid: string): Promise<{ link: string }> { - return await ApillonApi.get<{ link: string }>( + public async generateIpfsLink(cid: string): Promise { + const { link } = await ApillonApi.get<{ link: string }>( `${this.API_PREFIX}/link-on-ipfs/${cid}`, ); + return link; } } diff --git a/packages/sdk/src/tests/storage.test.ts b/packages/sdk/src/tests/storage.test.ts index 551e2df..e334935 100644 --- a/packages/sdk/src/tests/storage.test.ts +++ b/packages/sdk/src/tests/storage.test.ts @@ -173,7 +173,7 @@ describe('Storage tests', () => { test('Generate IPFS link', async () => { const cid = 'bafybeigjhyc2tpvqfqsuvf3byo4e4a4v6spi6jk4qqvvtlpca6rsaf2cqi'; - const { link } = await storage.generateIpfsLink(cid); + const link = await storage.generateIpfsLink(cid); expect(link).toBeDefined(); expect(link).toContain(cid); });