From 7c4b1d3952ad70f525badfb53286aebd432a23f0 Mon Sep 17 00:00:00 2001 From: Xavier Abad <77491413+masterprog-cmd@users.noreply.github.com> Date: Fri, 20 Sep 2024 07:57:51 +0200 Subject: [PATCH] feat: add pagination to getFoldercontentByUuid endpoint --- package.json | 2 +- src/drive/storage/index.ts | 27 +++++++++++++++++++++------ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 7572863..64c4fcb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@internxt/sdk", - "version": "1.5.16", + "version": "1.5.17", "description": "An sdk for interacting with Internxt's services", "repository": { "type": "git", diff --git a/src/drive/storage/index.ts b/src/drive/storage/index.ts index 5273d11..e2754a9 100644 --- a/src/drive/storage/index.ts +++ b/src/drive/storage/index.ts @@ -177,21 +177,36 @@ export class Storage { * * @param {string} folderUuid - The UUID of the folder. * @param {boolean} [trash=false] - Whether to include trash items in the response. + * @param {boolean} [offset] - The position of the first file to return. + * @param {boolean} [limit] - The max number of files to be returned. + * @param {boolean} [workspacesToken] - Token for accessing workspaces. * @return {[Promise, RequestCanceler]} An array containing a promise to get the API response and a function to cancel the request. */ - public getFolderContentByUuid( - folderUuid: string, + public getFolderContentByUuid({ + folderUuid, trash = false, - workspacesToken?: string, - ): [Promise, RequestCanceler] { - const query = trash ? '/?trash=true' : ''; + offset, + limit, + workspacesToken, + }: { + folderUuid: string; + trash?: boolean; + limit?: number; + offset?: number; + workspacesToken?: string; + }): [Promise, RequestCanceler] { + const query = new URLSearchParams(); + if (offset !== undefined) query.set('offset', String(offset)); + if (limit !== undefined) query.set('limit', String(limit)); + if (trash) query.set('trash', 'true'); + const customHeaders = workspacesToken ? { 'x-internxt-workspace': workspacesToken, } : undefined; const { promise, requestCanceler } = this.client.getCancellable( - `/folders/content/${folderUuid}${query}`, + `/folders/content/${folderUuid}?${query}`, this.headers(customHeaders), );