diff --git a/src/core/pinataSDK.ts b/src/core/pinataSDK.ts index e230bb5..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"; @@ -284,17 +285,22 @@ class FilterFiles { return this; } - then(onfulfilled?: ((value: FileListItem[]) => any) | null): Promise { + pageToken(pageToken: string): FilterFiles { + this.query.pageToken = pageToken; + return this; + } + + 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? @@ -315,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) { @@ -635,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); }