From 8487bd4e8eb45c32d02f3d1d21b3b176fa1788b0 Mon Sep 17 00:00:00 2001 From: jzunigax2 <125698953+jzunigax2@users.noreply.github.com> Date: Thu, 8 May 2025 14:51:42 -0600 Subject: [PATCH 1/3] feat: add createThumbnailEntryWithUUID method and CreateThumbnailEntryPayload interface --- src/drive/storage/index.ts | 18 ++++++++++++++++++ src/drive/storage/types.ts | 24 ++++++++++++++++++------ 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/drive/storage/index.ts b/src/drive/storage/index.ts index 6882a2ce..499ecd1a 100644 --- a/src/drive/storage/index.ts +++ b/src/drive/storage/index.ts @@ -13,6 +13,7 @@ import { CreateFolderByUuidPayload, CreateFolderPayload, CreateFolderResponse, + CreateThumbnailEntryPayload, DeleteFilePayload, DriveFileData, FetchFolderContentResponse, @@ -443,6 +444,23 @@ export class Storage { ); } + /** + * Creates a new thumbnail entry using drive-server-wip + * @param CreateThumbnailEntryPayload + */ + public createThumbnailEntryWithUUID( + thumbnailEntry: CreateThumbnailEntryPayload, + resourcesToken?: string, + ): Promise { + return this.client.post( + '/files/thumbnail', + { + ...thumbnailEntry, + }, + addResourcesTokenToHeaders(this.headers(), resourcesToken), + ); + } + /** * Updates the details of a file entry * @param payload diff --git a/src/drive/storage/types.ts b/src/drive/storage/types.ts index 5f1f0ff7..fcccbbcc 100644 --- a/src/drive/storage/types.ts +++ b/src/drive/storage/types.ts @@ -291,6 +291,18 @@ export interface ThumbnailEntry { encrypt_version: EncryptionVersion; } +export interface CreateThumbnailEntryPayload { + fileId: number; + fileUuid: string; + type: string; + size: number; + maxWidth: number; + maxHeight: number; + bucketId: string; + bucketFile: string; + encryptVersion: EncryptionVersion; +} + export interface CreateFolderPayload { parentFolderId: number; folderName: string; @@ -447,8 +459,8 @@ export interface FolderMeta { bucket: string | null; parent_id: number | null; parentId: number | null; - parent_uuid: string | null; - parentUuid: string | null; + parent_uuid: string | null; + parentUuid: string | null; parent: string | null; created_at: string; createdAt: string; @@ -457,8 +469,8 @@ export interface FolderMeta { user: string | null; user_id: number; userId: number; - encrypt_version: string | null; - encryptVersion: string | null; + encrypt_version: string | null; + encryptVersion: string | null; deleted: boolean; deleted_at: string | null; deletedAt: string | null; @@ -467,8 +479,8 @@ export interface FolderMeta { removedAt: string | null; size: number; type: string; - creation_time: string; - modification_time: string; + creation_time: string; + modification_time: string; } export interface ReplaceFile { From 6608718e11b8675f2858f70af3c40fb14dff200a Mon Sep 17 00:00:00 2001 From: jzunigax2 <125698953+jzunigax2@users.noreply.github.com> Date: Fri, 9 May 2025 08:43:25 -0600 Subject: [PATCH 2/3] chore: add tests --- test/drive/storage/index.test.ts | 67 ++++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 11 deletions(-) diff --git a/test/drive/storage/index.test.ts b/test/drive/storage/index.test.ts index db5da617..9cdda228 100644 --- a/test/drive/storage/index.test.ts +++ b/test/drive/storage/index.test.ts @@ -387,7 +387,7 @@ describe('# storage service tests', () => { // Arrange const workspaceId = v4(); const itemType = 'folder'; - const itemUuid = v4() + const itemUuid = v4(); const resourceToken = 'resource-token-workspace'; const mockResponse: FolderAncestorWorkspace[] = [ { @@ -411,12 +411,7 @@ describe('# storage service tests', () => { }); // Act - const body = await client.getFolderAncestorsInWorkspace( - workspaceId, - itemType, - itemUuid, - resourceToken, - ); + const body = await client.getFolderAncestorsInWorkspace(workspaceId, itemType, itemUuid, resourceToken); // Assert expect(callStub.firstCall.args).toEqual([ @@ -657,8 +652,8 @@ describe('# storage service tests', () => { }); }); - describe('getFile',() => { - it('When a fileId is provided without a workspaceToken then it should call getCancellable with the correct URL and headers', async () => { + describe('getFile', () => { + it('When a fileId is provided without a workspaceToken then it should call getCancellable with the correct URL and headers', async () => { // Arrange const fileUUID = v4(); const response = randomFileData() as FileMeta; @@ -674,13 +669,13 @@ describe('# storage service tests', () => { // Act const [promise, _] = client.getFile(fileUUID, workspaceToken); const body = await promise; - + // Assert expect(callStub.firstCall.args).toEqual([`/files/${fileUUID}/meta`, headers]); expect(body).toEqual(response); }); - it('When a fileId is provided with a workspaceToken then it should call getCancellable with the correct URL and custom headers', async() => { + it('When a fileId is provided with a workspaceToken then it should call getCancellable with the correct URL and custom headers', async () => { // Arrange const fileUUID = v4(); const response = randomFileData() as FileMeta; @@ -797,6 +792,56 @@ describe('# storage service tests', () => { }); }); }); + + describe('-> thumbnails', () => { + describe('createThumbnailEntryWithUUID', () => { + it('Should create a thumbnail entry with UUID and handle resourcesToken', async () => { + const thumbnailEntryPayload: StorageTypes.CreateThumbnailEntryPayload = { + fileId: 123, + fileUuid: v4(), + type: 'image/jpeg', + size: 1024, + maxWidth: 200, + maxHeight: 200, + bucketId: 'bucket123', + bucketFile: 'file123', + encryptVersion: StorageTypes.EncryptionVersion.Aes03, + }; + + const resourcesToken = 'resources-token-123'; + + const expectedResponse: StorageTypes.Thumbnail = { + id: 456, + file_id: 123, + max_width: 200, + max_height: 200, + type: 'image/jpeg', + size: 1024, + bucket_id: 'bucket123', + bucket_file: 'file123', + encrypt_version: StorageTypes.EncryptionVersion.Aes03, + }; + + const { client, headers } = clientAndHeaders({}); + const headersWithResourceToken = { + ...headers, + 'internxt-resources-token': resourcesToken, + }; + + const postStub = sinon.stub(httpClient, 'post').resolves(expectedResponse); + + const response = await client.createThumbnailEntryWithUUID(thumbnailEntryPayload, resourcesToken); + + expect(postStub.calledOnce).toBeTruthy(); + expect(postStub.firstCall.args[0]).toEqual('/files/thumbnail'); + expect(postStub.firstCall.args[1]).toEqual({ + ...thumbnailEntryPayload, + }); + expect(postStub.firstCall.args[2]).toEqual(headersWithResourceToken); + expect(response).toEqual(expectedResponse); + }); + }); + }); }); function clientAndHeaders({ From 2ce2385f2c113c32295bafbf689e4bbd1e719067 Mon Sep 17 00:00:00 2001 From: jzunigax2 <125698953+jzunigax2@users.noreply.github.com> Date: Mon, 12 May 2025 12:23:40 -0600 Subject: [PATCH 3/3] chore: bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b937c252..477595fe 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@internxt/sdk", "author": "Internxt ", - "version": "1.9.13", + "version": "1.9.14", "description": "An sdk for interacting with Internxt's services", "repository": { "type": "git",