-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copy & Move API calls + Updated Commands Path in Release Workflow
- Loading branch information
1 parent
45c63ab
commit 0e87d3f
Showing
8 changed files
with
165 additions
and
71 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
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 |
---|---|---|
@@ -1,60 +1,11 @@ | ||
const getCopiedFiles = (file, pastePath) => { | ||
const children = file.children ?? []; | ||
return [ | ||
{ name: file.name, isDirectory: file.isDirectory, path: pastePath }, | ||
...children.flatMap((child) => getCopiedFiles(child, pastePath + "/" + file.name)), | ||
]; | ||
}; | ||
|
||
const handleDuplicateFile = (file, pastePath, pastePathFiles) => { | ||
if (file.path === pastePath || pastePathFiles.find((f) => f.name === file.name)) { | ||
const fileExtension = file.isDirectory ? "" : "." + file.name.split(".").pop(); | ||
const fileName = file.isDirectory ? file.name : file.name.split(".").slice(0, -1).join("."); | ||
|
||
// Generating new file name for duplicate file | ||
let maxFileNum = 0; | ||
// If there exists a file with name fileName (1), fileName (2), etc. | ||
// Check if the number is greater than the maxFileNum, then set it to that greater number | ||
const fileNameRegex = new RegExp(`${fileName} \\(\\d+\\)`); | ||
pastePathFiles.forEach((f) => { | ||
const fName = f.isDirectory ? f.name : f.name.split(".").slice(0, -1).join("."); | ||
if (fileNameRegex.test(fName)) { | ||
const fileNumStr = fName.split(`${fileName} (`).pop().slice(0, -1); | ||
const fileNum = parseInt(fileNumStr); | ||
if (!isNaN(fileNum) && fileNum > maxFileNum) { | ||
maxFileNum = fileNum; | ||
} | ||
} | ||
}); | ||
const appendNum = ` (${++maxFileNum})`; | ||
const newFileName = fileName + appendNum + fileExtension; | ||
// | ||
import { api } from "./api"; | ||
|
||
return { ...file, name: newFileName }; | ||
} else { | ||
return file; | ||
} | ||
export const copyItemAPI = async (sourceId, destinationId) => { | ||
const response = await api.post("/copy", { sourceId, destinationId }); | ||
return response; | ||
}; | ||
|
||
export const fileTransferAPI = (files, pastePath, clipBoard, filesCopied) => { | ||
return new Promise((resolve) => { | ||
setTimeout(() => { | ||
if (clipBoard.isMoving) { | ||
files = files.filter((f) => { | ||
return !filesCopied.find((cf) => cf.name === f.name && cf.path === f.path); | ||
}); | ||
} | ||
|
||
const response = [ | ||
...files, | ||
...clipBoard.files.flatMap((file) => { | ||
const pastePathFiles = files.filter((f) => f.path === pastePath); | ||
const nonDuplicateFile = handleDuplicateFile(file, pastePath, pastePathFiles); | ||
return getCopiedFiles(nonDuplicateFile, pastePath); | ||
}), | ||
]; | ||
|
||
resolve(response); | ||
}, 700); | ||
}); | ||
export const moveItemAPI = async (sourceId, destinationId) => { | ||
const response = await api.put("/move", { sourceId, destinationId }); | ||
return response; | ||
}; |