This commit is contained in:
Manav Rathi 2024-04-16 15:29:56 +05:30
parent cf889b24af
commit 96ea996401
No known key found for this signature in database
2 changed files with 24 additions and 27 deletions

View file

@ -12,7 +12,7 @@ import {
WatchMappingSyncedFile,
} from "types/watchFolder";
import { groupFilesBasedOnCollectionID } from "utils/file";
import { getValidFilesToUpload } from "utils/watch";
import { isSystemFile } from "utils/upload";
import { removeFromCollection } from "../collectionService";
import { getLocalFiles } from "../fileService";
@ -713,3 +713,26 @@ async function diskFolderRemovedCallback(folderPath: string) {
log.error("error while calling diskFolderRemovedCallback", e);
}
}
export function getValidFilesToUpload(
files: ElectronFile[],
mapping: WatchMapping,
) {
const uniqueFilePaths = new Set<string>();
return files.filter((file) => {
if (!isSystemFile(file) && !isSyncedOrIgnoredFile(file, mapping)) {
if (!uniqueFilePaths.has(file.path)) {
uniqueFilePaths.add(file.path);
return true;
}
}
return false;
});
}
function isSyncedOrIgnoredFile(file: ElectronFile, mapping: WatchMapping) {
return (
mapping.ignoredFiles.includes(file.path) ||
mapping.syncedFiles.find((f) => f.path === file.path)
);
}

View file

@ -1,26 +0,0 @@
import { ElectronFile } from "types/upload";
import { WatchMapping } from "types/watchFolder";
import { isSystemFile } from "utils/upload";
function isSyncedOrIgnoredFile(file: ElectronFile, mapping: WatchMapping) {
return (
mapping.ignoredFiles.includes(file.path) ||
mapping.syncedFiles.find((f) => f.path === file.path)
);
}
export function getValidFilesToUpload(
files: ElectronFile[],
mapping: WatchMapping,
) {
const uniqueFilePaths = new Set<string>();
return files.filter((file) => {
if (!isSystemFile(file) && !isSyncedOrIgnoredFile(file, mapping)) {
if (!uniqueFilePaths.has(file.path)) {
uniqueFilePaths.add(file.path);
return true;
}
}
return false;
});
}