|
@@ -57,11 +57,12 @@ class FolderWatcher {
|
|
|
*/
|
|
|
private upload: (collectionName: string, filePaths: string[]) => void;
|
|
|
/**
|
|
|
- * A function to call when we want to sync with the backend.
|
|
|
+ * A function to call when we want to sync with the backend. It will
|
|
|
+ * initiate the sync but will not await its completion.
|
|
|
*
|
|
|
* This is passed as a param to {@link init}.
|
|
|
*/
|
|
|
- private syncWithRemote: () => void;
|
|
|
+ private requestSyncWithRemote: () => void;
|
|
|
|
|
|
/** A helper function that debounces invocations of {@link runNextEvent}. */
|
|
|
private debouncedRunNextEvent: () => void;
|
|
@@ -80,10 +81,10 @@ class FolderWatcher {
|
|
|
*/
|
|
|
init(
|
|
|
upload: (collectionName: string, filePaths: string[]) => void,
|
|
|
- syncWithRemote: () => void,
|
|
|
+ requestSyncWithRemote: () => void,
|
|
|
) {
|
|
|
this.upload = upload;
|
|
|
- this.syncWithRemote = syncWithRemote;
|
|
|
+ this.requestSyncWithRemote = requestSyncWithRemote;
|
|
|
this.registerListeners();
|
|
|
this.syncWithDisk();
|
|
|
}
|
|
@@ -504,33 +505,30 @@ class FolderWatcher {
|
|
|
}
|
|
|
|
|
|
private async moveToTrash(syncedFiles: FolderWatch["syncedFiles"]) {
|
|
|
- try {
|
|
|
- const files = await getLocalFiles();
|
|
|
- const toTrashFilesMap = new Map<number, FolderWatchSyncedFile>();
|
|
|
- for (const file of syncedFiles) {
|
|
|
- toTrashFilesMap.set(file.uploadedFileID, file);
|
|
|
- }
|
|
|
- const filesToTrash = files.filter((file) => {
|
|
|
- if (toTrashFilesMap.has(file.id)) {
|
|
|
- const fileToTrash = toTrashFilesMap.get(file.id);
|
|
|
- if (fileToTrash.collectionID === file.collectionID) {
|
|
|
- return true;
|
|
|
- }
|
|
|
+ const files = await getLocalFiles();
|
|
|
+ const toTrashFilesMap = new Map<number, FolderWatchSyncedFile>();
|
|
|
+ for (const file of syncedFiles) {
|
|
|
+ toTrashFilesMap.set(file.uploadedFileID, file);
|
|
|
+ }
|
|
|
+ const filesToTrash = files.filter((file) => {
|
|
|
+ if (toTrashFilesMap.has(file.id)) {
|
|
|
+ const fileToTrash = toTrashFilesMap.get(file.id);
|
|
|
+ if (fileToTrash.collectionID === file.collectionID) {
|
|
|
+ return true;
|
|
|
}
|
|
|
- });
|
|
|
- const groupFilesByCollectionId =
|
|
|
- groupFilesBasedOnCollectionID(filesToTrash);
|
|
|
-
|
|
|
- for (const [
|
|
|
- collectionID,
|
|
|
- filesToTrash,
|
|
|
- ] of groupFilesByCollectionId.entries()) {
|
|
|
- await removeFromCollection(collectionID, filesToTrash);
|
|
|
}
|
|
|
- this.syncWithRemote();
|
|
|
- } catch (e) {
|
|
|
- log.error("error while trashing by IDs", e);
|
|
|
+ });
|
|
|
+ const groupFilesByCollectionId =
|
|
|
+ groupFilesBasedOnCollectionID(filesToTrash);
|
|
|
+
|
|
|
+ for (const [
|
|
|
+ collectionID,
|
|
|
+ filesToTrash,
|
|
|
+ ] of groupFilesByCollectionId.entries()) {
|
|
|
+ await removeFromCollection(collectionID, filesToTrash);
|
|
|
}
|
|
|
+
|
|
|
+ this.requestSyncWithRemote();
|
|
|
}
|
|
|
}
|
|
|
|