Skip to content

Commit

Permalink
Handle filename conflicts in trash folder
Browse files Browse the repository at this point in the history
  • Loading branch information
yinanazhou committed Nov 27, 2023
1 parent b446fb6 commit 0cebf83
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Dashboard/Dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,12 @@ function putBackDocsHandler() {
const targetFolder = state.getFolderPathByNames(folderPathNames);
if (targetFolder) {
entry = FileSystemTools.removeMetadata(entry, ['removed_on', 'recover_folder']);
const dateTimePattern = / - \d{1,2}\/\d{1,2}\/\d{4}, \d{1,2}:\d{2}:\d{2} [APMapm]{2}$/;

// Check if the filename ends with the date time pattern
if (dateTimePattern.test(entry.name)) {
entry.name = entry.name.replace(dateTimePattern, '');
}
moveToFolder([entry], parentFolder, targetFolder);
}
}
Expand Down Expand Up @@ -804,6 +810,10 @@ function createHandleDrop(currentFolder: IFolder, destinationFolder: IFolder) {
function moveToFolder(entries: IEntry[], parentFolder: IFolder, newFolder: IFolder) {
const errorMessages = [];
entries.forEach((entry) => {
// Handle name conflicts for trash folder
if (newFolder.type === 'trash' && newFolder.children.some((e) => e.name === entry.name)) {
entry.name = trashFNConflictHandler(entry.name);
}
const response = FileSystemTools.canMoveEntry(entry, parentFolder, newFolder);
if (!response.succeeded) errorMessages.push(response.error);
else FileSystemTools.moveEntry(entry, parentFolder, newFolder);
Expand All @@ -815,6 +825,11 @@ function moveToFolder(entries: IEntry[], parentFolder: IFolder, newFolder: IFold
updateDashboard();
}

function trashFNConflictHandler(filename: string): string {
const datetime = new Date().toLocaleString();
return filename + ' - ' + datetime;
}

/**
* Opens Move-To menu modal window with UI for moving selected entries to a new folder.
*/
Expand Down

0 comments on commit 0cebf83

Please sign in to comment.