From 18013095b2cc576b707e30823890267ea31e3941 Mon Sep 17 00:00:00 2001 From: Steve Date: Fri, 6 Sep 2024 14:04:25 -0400 Subject: [PATCH 1/2] feat: Add pageToken method --- src/core/pinataSDK.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/core/pinataSDK.ts b/src/core/pinataSDK.ts index e230bb5..77236d8 100644 --- a/src/core/pinataSDK.ts +++ b/src/core/pinataSDK.ts @@ -284,6 +284,11 @@ class FilterFiles { return this; } + pageToken(pageToken: string): FilterFiles { + this.query.pageToken = pageToken; + return this; + } + then(onfulfilled?: ((value: FileListItem[]) => any) | null): Promise { return this.fetchPage().then(onfulfilled); } From ed8300d2989382c8a03bf0c9f36b0d2858ac0156 Mon Sep 17 00:00:00 2001 From: Steve Date: Fri, 6 Sep 2024 14:36:04 -0400 Subject: [PATCH 2/2] feat: Added page token to groups --- src/core/pinataSDK.ts | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/core/pinataSDK.ts b/src/core/pinataSDK.ts index 77236d8..d987146 100644 --- a/src/core/pinataSDK.ts +++ b/src/core/pinataSDK.ts @@ -35,6 +35,7 @@ import type { OptimizeImageOptions, GroupListResponse, SignedUrlOptions, + FileListResponse, } from "./types"; import { testAuthentication } from "./authentication/testAuthentication"; import { uploadFile } from "./uploads/file"; @@ -289,17 +290,17 @@ class FilterFiles { return this; } - then(onfulfilled?: ((value: FileListItem[]) => any) | null): Promise { + then(onfulfilled?: ((value: FileListResponse) => any) | null): Promise { return this.fetchPage().then(onfulfilled); } - private async fetchPage(): Promise { + private async fetchPage(): Promise { if (this.currentPageToken) { this.query.pageToken = this.currentPageToken; } const response = await listFiles(this.config, this.query); this.currentPageToken = response.next_page_token; - return response.files; + return response; } // // rate limit, hopefully temporary? @@ -320,7 +321,7 @@ class FilterFiles { async *[Symbol.asyncIterator](): AsyncGenerator { while (true) { const items = await this.fetchPage(); - for (const item of items) { + for (const item of items.files) { yield item; } if (!this.currentPageToken) { @@ -640,13 +641,18 @@ class FilterGroups { return this; } + pageToken(pageToken: string): FilterGroups { + this.query.pageToken = pageToken; + return this; + } + then( - onfulfilled?: ((value: GroupResponseItem[]) => any) | null, - ): Promise { + onfulfilled?: ((value: GroupListResponse) => any) | null, + ): Promise { return this.fetchPage() .then((response) => { this.nextPageToken = response.next_page_token; - return response.groups; + return response; }) .then(onfulfilled); }