-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1282 from internxt/bugfix/PB-2375-check-duplicate…
…-items-before-uploading [PB-2375] bugfix/Check duplicated items before uploading on Drive web
- Loading branch information
Showing
30 changed files
with
985 additions
and
304 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export interface FileToUpload { | ||
name: string; | ||
size: number; | ||
type: string; | ||
content: File; | ||
parentFolderId: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/app/store/slices/storage/fileUtils/checkDuplicatedFiles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { items as itemUtils } from '@internxt/lib'; | ||
import { DriveFileData } from '@internxt/sdk/dist/drive/storage/types'; | ||
import newStorageService from '../../../../drive/services/new-storage.service'; | ||
|
||
export interface DuplicatedFilesResult { | ||
duplicatedFilesResponse: DriveFileData[]; | ||
filesWithDuplicates: (File | DriveFileData)[]; | ||
filesWithoutDuplicates: (File | DriveFileData)[]; | ||
} | ||
|
||
export const checkDuplicatedFiles = async ( | ||
files: (File | DriveFileData)[], | ||
parentFolderId: string, | ||
): Promise<DuplicatedFilesResult> => { | ||
if (files.length === 0) { | ||
return { | ||
duplicatedFilesResponse: [], | ||
filesWithDuplicates: [], | ||
filesWithoutDuplicates: files, | ||
} as DuplicatedFilesResult; | ||
} | ||
|
||
const parsedFiles = files.map(parseFile); | ||
const checkDuplicatedFileResponse = await newStorageService.checkDuplicatedFiles(parentFolderId, parsedFiles); | ||
|
||
const duplicatedFilesResponse = checkDuplicatedFileResponse.existentFiles; | ||
|
||
const { filesWithDuplicates, filesWithoutDuplicates } = parsedFiles.reduce( | ||
(acc, parsedFile) => { | ||
const isDuplicated = duplicatedFilesResponse.some( | ||
(duplicatedFile) => | ||
duplicatedFile.plainName === parsedFile.plainName && duplicatedFile.type === parsedFile.type, | ||
); | ||
|
||
if (isDuplicated) { | ||
acc.filesWithDuplicates.push(parsedFile.originalFile); | ||
} else { | ||
acc.filesWithoutDuplicates.push(parsedFile.originalFile); | ||
} | ||
|
||
return acc; | ||
}, | ||
{ filesWithDuplicates: [], filesWithoutDuplicates: [] } as { | ||
filesWithDuplicates: (File | DriveFileData)[]; | ||
filesWithoutDuplicates: (File | DriveFileData)[]; | ||
}, | ||
); | ||
|
||
return { duplicatedFilesResponse, filesWithoutDuplicates, filesWithDuplicates }; | ||
}; | ||
|
||
interface ParsedFile { | ||
plainName: string; | ||
type: string; | ||
originalFile: File | DriveFileData; | ||
} | ||
|
||
const parseFile = (file: File | DriveFileData): ParsedFile => { | ||
if (file instanceof File) { | ||
const { filename, extension } = itemUtils.getFilenameAndExt(file.name); | ||
return { plainName: filename, type: extension, originalFile: file }; | ||
} else { | ||
return { plainName: file.name, type: file.type, originalFile: file }; | ||
} | ||
}; |
Oops, something went wrong.