Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@internxt/sdk",
"author": "Internxt <[email protected]>",
"version": "1.9.13",
"version": "1.9.14",
"description": "An sdk for interacting with Internxt's services",
"repository": {
"type": "git",
Expand Down
18 changes: 18 additions & 0 deletions src/drive/storage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
CreateFolderByUuidPayload,
CreateFolderPayload,
CreateFolderResponse,
CreateThumbnailEntryPayload,
DeleteFilePayload,
DriveFileData,
FetchFolderContentResponse,
Expand Down Expand Up @@ -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<Thumbnail> {
return this.client.post(
'/files/thumbnail',
{
...thumbnailEntry,
},
addResourcesTokenToHeaders(this.headers(), resourcesToken),
);
}

/**
* Updates the details of a file entry
* @param payload
Expand Down
24 changes: 18 additions & 6 deletions src/drive/storage/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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 {
Expand Down
67 changes: 56 additions & 11 deletions test/drive/storage/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [
{
Expand All @@ -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([
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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({
Expand Down