Skip to content

Commit

Permalink
Merge pull request #208 from internxt/feature/PB-2219-replace-id-for-…
Browse files Browse the repository at this point in the history
…uuid

[PB-2219] feature/replace id for UUID
  • Loading branch information
CandelR authored Jun 18, 2024
2 parents dc520ba + 042c5e2 commit 06181db
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@internxt/sdk",
"version": "1.4.84",
"version": "1.4.85",
"description": "An sdk for interacting with Internxt's services",
"repository": {
"type": "git",
Expand Down
60 changes: 60 additions & 0 deletions src/drive/storage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { HttpClient, RequestCanceler } from '../../shared/http/client';
import { UUID } from '../../shared/types/userSettings';
import {
AddItemsToTrashPayload,
CreateFolderByUuidPayload,
CreateFolderPayload,
CreateFolderResponse,
DeleteFilePayload,
Expand All @@ -15,6 +16,7 @@ import {
FetchPaginatedFolderContentResponse,
FetchPaginatedFoldersContent,
FileEntry,
FileEntryByUuid,
FileMeta,
FolderAncestor,
FolderMeta,
Expand Down Expand Up @@ -67,6 +69,23 @@ export class Storage {
return [promise, requestCanceler];
}

/**
* Creates a new folder
* @param payload
*/
public createFolderByUuid(payload: CreateFolderByUuidPayload): [Promise<CreateFolderResponse>, RequestCanceler] {
const { promise, requestCanceler } = this.client.postCancellable<CreateFolderResponse>(
'/folders',
{
plainName: payload.plainName,
parentFolderUuid: payload.parentFolderUuid,
},
this.headers(),
);

return [promise, requestCanceler];
}

/**
* Moves a specific folder to a new location
* @param payload
Expand Down Expand Up @@ -125,6 +144,26 @@ export class Storage {
return [promise, requestCanceler];
}

/**
* Fetches and returns the contents of a specific folder by its UUID.
*
* @param {string} folderUuid - The UUID of the folder.
* @param {boolean} [trash=false] - Whether to include trash items in the response.
* @return {[Promise<FetchFolderContentResponse>, RequestCanceler]} An array containing a promise to get the API response and a function to cancel the request.
*/
public getFolderContentByUuid(
folderUuid: string,
trash = false,
): [Promise<FetchFolderContentResponse>, RequestCanceler] {
const query = trash ? '/?trash=true' : '';

const { promise, requestCanceler } = this.client.getCancellable<FetchFolderContentResponse>(
`/folders/content/${folderUuid}${query}`,
this.headers(),
);

return [promise, requestCanceler];
}
/**
* Returns metadata of a specific file
* @param fileId
Expand Down Expand Up @@ -307,6 +346,27 @@ export class Storage {
);
}

/**
* Creates a new file entry
* @param fileEntry
*/
public createFileEntryByUuid(fileEntry: FileEntryByUuid): Promise<DriveFileData> {
return this.client.post(
'/files',
{
name: fileEntry.name,
bucket: fileEntry.bucket,
fileId: fileEntry.id,
encryptVersion: fileEntry.encrypt_version,
folderUuid: fileEntry.folder_id,
size: fileEntry.size,
plainName: fileEntry.plain_name,
type: fileEntry.type,
},
this.headers(),
);
}

/**
* Creates a new thumbnail entry
* @param thumbnailEntry
Expand Down
27 changes: 24 additions & 3 deletions src/drive/storage/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export interface DriveFolderData {
updatedAt: string;
userId: number;
user_id: number;
uuid: string;
}

export interface DriveFileData {
uuid: string;
bucket: string;
createdAt: string;
created_at: string;
Expand All @@ -30,15 +30,20 @@ export interface DriveFileData {
fileId: string;
folderId: number;
folder_id: number;
folderUuid: string;
id: number;
name: string;
plain_name: string;
plain_name: string | null;
plainName?: string | null;
size: number;
type: string;
updatedAt: string;
status: string;
thumbnails: Array<Thumbnail>;
currentThumbnail: Thumbnail | null;
shares?: Array<ShareLink>;
sharings?: { type: string; id: string }[];
uuid: string;
}

export interface Thumbnail {
Expand Down Expand Up @@ -101,6 +106,7 @@ export interface FileMeta {
fileId: string;
folderId: number;
folder_id: number;
folderUuid: string;
id: number;
name: string;
plain_name: string | null;
Expand All @@ -112,7 +118,7 @@ export interface FileMeta {
thumbnails: Array<Thumbnail>;
currentThumbnail: Thumbnail | null;
shares?: Array<ShareLink>;
uuid?: string;
uuid: string;
}

export interface ShareLink {
Expand Down Expand Up @@ -258,6 +264,17 @@ export interface FileEntry {
encrypt_version: EncryptionVersion;
}

export interface FileEntryByUuid {
id: string;
type: string;
size: number;
name: string;
plain_name: string;
bucket: string;
folder_id: string;
encrypt_version: EncryptionVersion;
}

export interface ThumbnailEntry {
file_id: number;
max_width: number;
Expand All @@ -273,6 +290,10 @@ export interface CreateFolderPayload {
parentFolderId: number;
folderName: string;
}
export interface CreateFolderByUuidPayload {
plainName: string;
parentFolderUuid: string;
}

export interface CreateFolderResponse {
bucket: string;
Expand Down
1 change: 1 addition & 0 deletions src/shared/types/userSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface UserSettings {
bucket: string;
backupsBucket: string | null;
root_folder_id: number;
rootFolderId: string;
sharedWorkspace: boolean;
credit: number;
mnemonic: string;
Expand Down
2 changes: 2 additions & 0 deletions src/workspaces/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('Workspaces service tests', () => {
freeSpace: '0',
isManager: false,
isOwner: false,
rootFolderId: 'asflaksfoau0su0fewnlsd',
member: {
avatar: null,
backupsBucket: null,
Expand Down Expand Up @@ -86,6 +87,7 @@ describe('Workspaces service tests', () => {
freeSpace: '0',
isManager: false,
isOwner: false,
rootFolderId: 'asflaksfoau0su0fewnlsd',
member: {
avatar: null,
backupsBucket: null,
Expand Down
93 changes: 91 additions & 2 deletions src/workspaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Token } from '../auth';
import { DriveFileData, FetchPaginatedFolderContentResponse, FileEntry } from '../drive/storage/types';
import { ApiSecurity, ApiUrl, AppDetails } from '../shared';
import { headersWithToken } from '../shared/headers';
import { HttpClient } from '../shared/http/client';
import { addResourcesTokenToHeaders, headersWithToken } from '../shared/headers';
import { HttpClient, RequestCanceler } from '../shared/http/client';
import {
CreateTeamData,
InviteMemberBody,
Expand Down Expand Up @@ -158,6 +160,93 @@ export class Workspaces {
public declineInvitation(inviteId: string, token: string): Promise<void> {
return this.client.delete<void>(`workspaces/invitations/${inviteId}`, this.getRequestHeaders(token));
}

public createFileEntry(fileEntry: FileEntry, workspaceId: string, resourcesToken?: Token): Promise<DriveFileData> {
return this.client.post(
`/workspaces/${workspaceId}/files`,
{
file: {
fileId: fileEntry.id,
type: fileEntry.type,
bucket: fileEntry.bucket,
size: fileEntry.size,
folder_id: fileEntry.folder_id,
name: fileEntry.name,
plain_name: fileEntry.plain_name,
encrypt_version: fileEntry.encrypt_version,
},
},
addResourcesTokenToHeaders(this.headers(), resourcesToken),
);
}

/**
* Retrieves a paginated list of folders within a specific folder in a workspace.
*
* @param {string} workspaceId - The ID of the workspace.
* @param {string} folderUUID - The UUID of the folder.
* @param {number} [offset=0] - The position of the first file to return.
* @param {number} [limit=50] - The max number of files to be returned.
* @param {string} [sort=''] - The reference column to sort it.
* @param {string} [order=''] - The order to be followed.
* @return {[Promise<FetchPaginatedFolderContentResponse>, RequestCanceler]} An array containing a promise to get the API response and a function to cancel the request.
*/
public getFolders(
workspaceId: string,
folderUUID: string,
offset = 0,
limit = 50,
sort = '',
order = '',
): [Promise<FetchPaginatedFolderContentResponse>, RequestCanceler] {
const offsetQuery = `?offset=${offset}`;
const limitQuery = `&limit=${limit}`;
const sortQuery = sort !== '' ? `&sort=${sort}` : '';
const orderQuery = order !== '' ? `&order=${order}` : '';

const query = `${offsetQuery}${limitQuery}${sortQuery}${orderQuery}`;

const { promise, requestCanceler } = this.client.getCancellable<FetchPaginatedFolderContentResponse>(
`workspaces/${workspaceId}/folders/${folderUUID}/folders/${query}`,
this.headers(),
);

return [promise, requestCanceler];
}

/**
* Retrieves a paginated list of files within a specific folder in a workspace.
*
* @param {string} workspaceId - The ID of the workspace.
* @param {string} folderUUID - The UUID of the folder.
* @param {number} [offset=0] - The position of the first file to return.
* @param {number} [limit=50] - The max number of files to be returned.
* @param {string} [sort=''] - The reference column to sort it.
* @param {string} [order=''] - The order to be followed.
* @return {[Promise<FetchPaginatedFolderContentResponse>, RequestCanceler]} An array containing a promise to get the API response and a function to cancel the request.
*/
public getFiles(
workspaceId: string,
folderUUID: string,
offset = 0,
limit = 50,
sort = '',
order = '',
): [Promise<FetchPaginatedFolderContentResponse>, RequestCanceler] {
const offsetQuery = `?offset=${offset}`;
const limitQuery = `&limit=${limit}`;
const sortQuery = sort !== '' ? `&sort=${sort}` : '';
const orderQuery = order !== '' ? `&order=${order}` : '';

const query = `${offsetQuery}${limitQuery}${sortQuery}${orderQuery}`;

const { promise, requestCanceler } = this.client.getCancellable<FetchPaginatedFolderContentResponse>(
`workspaces/${workspaceId}/folders/${folderUUID}/files/${query}`,
this.headers(),
);

return [promise, requestCanceler];
}
}

export * from './types';
1 change: 1 addition & 0 deletions src/workspaces/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface WorkspaceUser {
key: string;
member: Member;
memberId: string;
rootFolderId: string;
spaceLimit: string;
updatedAt: string;
usedSpace: string;
Expand Down

0 comments on commit 06181db

Please sign in to comment.