Skip to content

Commit

Permalink
Merge pull request #243 from internxt/bugfix/PB-2375-check-duplicate-…
Browse files Browse the repository at this point in the history
…items-before-uploading

[PB-2375]: Check duplicated items before uploading on Drive web
  • Loading branch information
CandelR authored Sep 18, 2024
2 parents ffb2976 + b3191de commit ed90920
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
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.5.15",
"version": "1.5.16",
"description": "An sdk for interacting with Internxt's services",
"repository": {
"type": "git",
Expand Down
42 changes: 42 additions & 0 deletions src/drive/storage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { HttpClient, RequestCanceler } from '../../shared/http/client';
import { UUID } from '../../shared/types/userSettings';
import {
AddItemsToTrashPayload,
CheckDuplicatedFilesPayload,
CheckDuplicatedFilesResponse,
CheckDuplicatedFolderPayload,
CheckDuplicatedFoldersResponse,
CreateFolderByUuidPayload,
CreateFolderPayload,
CreateFolderResponse,
Expand Down Expand Up @@ -658,4 +662,42 @@ export class Storage {
public getFolderTree(uuid: string): Promise<FolderTreeResponse> {
return this.client.get(`/folders/${uuid}/tree`, this.headers());
}

/**
* Checks if the given files already exist in the given folder.
*
* @param {CheckDuplicatedFilesPayload} payload - Payload containing the folder UUID and the list of files to check.
* @return {Promise<CheckDuplicatedFilesResponse>} - Promise that contains the duplicated files in a list.
*/
public checkDuplicatedFiles({
folderUuid,
filesList,
}: CheckDuplicatedFilesPayload): Promise<CheckDuplicatedFilesResponse> {
return this.client.post(
`/folders/content/${folderUuid}/files/existence`,
{
files: filesList,
},
this.headers(),
);
}

/**
* Checks if the given folders names already exist in the given folder
*
* @param {CheckDuplicatedFolderPayload} payload - Payload containing the folder UUID and the list of folders to check.
* @return {Promise<CheckDuplicatedFoldersResponse>} - Promise that contains the duplicated folders in a list.
*/
public checkDuplicatedFolders({
folderUuid,
folderNamesList,
}: CheckDuplicatedFolderPayload): Promise<CheckDuplicatedFoldersResponse> {
return this.client.post(
`/folders/content/${folderUuid}/folders/existence`,
{
plainNames: folderNamesList,
},
this.headers(),
);
}
}
23 changes: 23 additions & 0 deletions src/drive/storage/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,3 +473,26 @@ export interface FolderTree {
export interface FolderTreeResponse {
tree: FolderTree;
}

export interface CheckDuplicatedFilesPayload {
folderUuid: string;
filesList: FileStructure[];
}

export interface FileStructure {
plainName: string;
type: string;
}

export interface CheckDuplicatedFilesResponse {
existentFiles: DriveFileData[];
}

export interface CheckDuplicatedFolderPayload {
folderUuid: string;
folderNamesList: string[];
}

export interface CheckDuplicatedFoldersResponse {
existentFolders: DriveFolderData[];
}

0 comments on commit ed90920

Please sign in to comment.