Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PB-2375]: Check duplicated items before uploading on Drive web #243

Merged
merged 2 commits into from
Sep 18, 2024
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,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[];
}
Loading