Browse Source

Abstraction

Manav Rathi 1 year ago
parent
commit
4fd9ecba56

+ 2 - 3
web/apps/photos/src/services/watch.ts

@@ -4,7 +4,6 @@
  */
  */
 
 
 import { ensureElectron } from "@/next/electron";
 import { ensureElectron } from "@/next/electron";
-import { nameAndExtension } from "@/next/file";
 import log from "@/next/log";
 import log from "@/next/log";
 import type {
 import type {
     CollectionMapping,
     CollectionMapping,
@@ -18,7 +17,7 @@ import { Collection } from "types/collection";
 import { EncryptedEnteFile } from "types/file";
 import { EncryptedEnteFile } from "types/file";
 import { ElectronFile, FileWithCollection } from "types/upload";
 import { ElectronFile, FileWithCollection } from "types/upload";
 import { groupFilesBasedOnCollectionID } from "utils/file";
 import { groupFilesBasedOnCollectionID } from "utils/file";
-import { isSystemFile } from "utils/upload";
+import { isHiddenFile, isSystemFile } from "utils/upload";
 import { removeFromCollection } from "./collectionService";
 import { removeFromCollection } from "./collectionService";
 import { getLocalFiles } from "./fileService";
 import { getLocalFiles } from "./fileService";
 
 
@@ -711,7 +710,7 @@ const deduceEvents = async (
 
 
         const paths = (await electron.watch.findFiles(folderPath))
         const paths = (await electron.watch.findFiles(folderPath))
             // Filter out hidden files (files whose names begins with a dot)
             // Filter out hidden files (files whose names begins with a dot)
-            .filter((path) => !nameAndExtension(path)[0].startsWith("."));
+            .filter((path) => !isHiddenFile(path));
 
 
         // Files that are on disk but not yet synced.
         // Files that are on disk but not yet synced.
         const pathsToUpload = paths.filter(
         const pathsToUpload = paths.filter(

+ 9 - 1
web/apps/photos/src/utils/upload/index.ts

@@ -1,4 +1,4 @@
-import { directoryNameFromPOSIXPath } from "@/next/file";
+import { directoryNameFromPOSIXPath, fileNameFromPOSIXPath } from "@/next/file";
 import { FILE_TYPE } from "constants/file";
 import { FILE_TYPE } from "constants/file";
 import {
 import {
     A_SEC_IN_MICROSECONDS,
     A_SEC_IN_MICROSECONDS,
@@ -219,3 +219,11 @@ export function filterOutSystemFiles(files: File[] | ElectronFile[]) {
 export function isSystemFile(file: File | ElectronFile) {
 export function isSystemFile(file: File | ElectronFile) {
     return file.name.startsWith(".");
     return file.name.startsWith(".");
 }
 }
+
+/**
+ * Return true if the file at the given {@link path} is hidden.
+ *
+ * Hidden files are those whose names begin with a "." (dot).
+ */
+export const isHiddenFile = (path: string) =>
+    fileNameFromPOSIXPath(path).startsWith(".");