Skip to content

Commit

Permalink
Update generateIpfsLink method, add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitrov-d committed May 7, 2024
1 parent 508cf3d commit 2864641
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 4 additions & 0 deletions packages/sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
7 changes: 4 additions & 3 deletions packages/sdk/src/modules/storage/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>} 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<string> {
const { link } = await ApillonApi.get<{ link: string }>(
`${this.API_PREFIX}/link-on-ipfs/${cid}`,
);
return link;
}
}
2 changes: 1 addition & 1 deletion packages/sdk/src/tests/storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down

0 comments on commit 2864641

Please sign in to comment.