Manav Rathi před 1 rokem
rodič
revize
c90cd258ec

+ 0 - 7
web/apps/cast/src/types/upload/index.ts

@@ -95,13 +95,6 @@ export interface ParsedExtractedMetadata {
     height: number;
 }
 
-// This is used to prompt the user the make upload strategy choice
-export interface ImportSuggestion {
-    rootFolderName: string;
-    hasNestedFolders: boolean;
-    hasRootLevelFileWithFolder: boolean;
-}
-
 export interface PublicUploadProps {
     token: string;
     passwordToken: string;

+ 4 - 10
web/apps/photos/src/components/Upload/Uploader.tsx

@@ -5,11 +5,7 @@ import { CustomError } from "@ente/shared/error";
 import { isPromise } from "@ente/shared/utils";
 import DiscFullIcon from "@mui/icons-material/DiscFull";
 import UserNameInputDialog from "components/UserNameInputDialog";
-import {
-    DEFAULT_IMPORT_SUGGESTION,
-    PICKED_UPLOAD_TYPE,
-    UPLOAD_STAGES,
-} from "constants/upload";
+import { PICKED_UPLOAD_TYPE, UPLOAD_STAGES } from "constants/upload";
 import { t } from "i18next";
 import isElectron from "is-electron";
 import { AppContext } from "pages/_app";
@@ -35,11 +31,7 @@ import {
     SetLoading,
     UploadTypeSelectorIntent,
 } from "types/gallery";
-import {
-    ElectronFile,
-    FileWithCollection,
-    ImportSuggestion,
-} from "types/upload";
+import { ElectronFile, FileWithCollection } from "types/upload";
 import {
     InProgressUpload,
     SegregatedFinishedUploads,
@@ -53,9 +45,11 @@ import {
     getRootLevelFileWithFolderNotAllowMessage,
 } from "utils/ui";
 import {
+    DEFAULT_IMPORT_SUGGESTION,
     filterOutSystemFiles,
     getImportSuggestion,
     groupFilesBasedOnParentFolder,
+    type ImportSuggestion,
 } from "utils/upload";
 import { SetCollectionNamerAttributes } from "../Collections/CollectionNamer";
 import { CollectionMappingChoiceModal } from "./CollectionMappingChoiceModal";

+ 3 - 2
web/apps/photos/src/components/WatchFolder.tsx

@@ -1,4 +1,5 @@
 import { ensureElectron } from "@/next/electron";
+import { basename } from "@/next/file";
 import type { CollectionMapping, FolderWatch } from "@/next/types/ipc";
 import { ensure } from "@/utils/ensure";
 import {
@@ -166,7 +167,7 @@ const WatchList: React.FC<WatchList> = ({ watches, removeWatch }) => {
             {watches.map((watch) => {
                 return (
                     <WatchEntry
-                        key={watch.rootFolderName}
+                        key={watch.folderPath}
                         watch={watch}
                         removeWatch={removeWatch}
                     />
@@ -292,7 +293,7 @@ const EntryHeading: React.FC<EntryHeadingProps> = ({ watch }) => {
     const appContext = useContext(AppContext);
     return (
         <FlexWrapper gap={1}>
-            <Typography>{watch.rootFolderName}</Typography>
+            <Typography>{basename(watch.folderPath)}</Typography>
             {appContext.isFolderSyncRunning &&
                 watcher.isSyncingWatch(watch) && <CircularProgress size={12} />}
         </FlexWrapper>

+ 1 - 12
web/apps/photos/src/constants/upload.ts

@@ -1,11 +1,6 @@
 import { ENCRYPTION_CHUNK_SIZE } from "@ente/shared/crypto/constants";
 import { FILE_TYPE } from "constants/file";
-import {
-    FileTypeInfo,
-    ImportSuggestion,
-    Location,
-    ParsedExtractedMetadata,
-} from "types/upload";
+import { FileTypeInfo, Location, ParsedExtractedMetadata } from "types/upload";
 
 // list of format that were missed by type-detection for some files.
 export const WHITELISTED_FILE_FORMATS: FileTypeInfo[] = [
@@ -111,12 +106,6 @@ export const NULL_EXTRACTED_METADATA: ParsedExtractedMetadata = {
 
 export const A_SEC_IN_MICROSECONDS = 1e6;
 
-export const DEFAULT_IMPORT_SUGGESTION: ImportSuggestion = {
-    rootFolderName: "",
-    hasNestedFolders: false,
-    hasRootLevelFileWithFolder: false,
-};
-
 export const BLACK_THUMBNAIL_BASE64 =
     "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEB" +
     "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQ" +

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

@@ -115,9 +115,7 @@ class FolderWatcher {
      * collection do files belonging to nested directories go to.
      */
     async addWatch(folderPath: string, mapping: CollectionMapping) {
-        const rootFolderName = folderPath.substring(
-            folderPath.lastIndexOf("/") + 1,
-        );
+        const rootFolderName = basename(folderPath)
         await ensureElectron().addWatchMapping(
             rootFolderName,
             folderPath,

+ 0 - 7
web/apps/photos/src/types/upload/index.ts

@@ -156,13 +156,6 @@ export interface ParsedExtractedMetadata {
     height: number;
 }
 
-// This is used to prompt the user the make upload strategy choice
-export interface ImportSuggestion {
-    rootFolderName: string;
-    hasNestedFolders: boolean;
-    hasRootLevelFileWithFolder: boolean;
-}
-
 export interface PublicUploadProps {
     token: string;
     passwordToken: string;

+ 15 - 11
web/apps/photos/src/utils/upload/index.ts

@@ -1,19 +1,10 @@
 import { basename, dirname } from "@/next/file";
 import { FILE_TYPE } from "constants/file";
-import {
-    A_SEC_IN_MICROSECONDS,
-    DEFAULT_IMPORT_SUGGESTION,
-    PICKED_UPLOAD_TYPE,
-} from "constants/upload";
+import { A_SEC_IN_MICROSECONDS, PICKED_UPLOAD_TYPE } from "constants/upload";
 import isElectron from "is-electron";
 import { exportMetadataDirectoryName } from "services/export";
 import { EnteFile } from "types/file";
-import {
-    ElectronFile,
-    FileWithCollection,
-    ImportSuggestion,
-    Metadata,
-} from "types/upload";
+import { ElectronFile, FileWithCollection, Metadata } from "types/upload";
 
 const TYPE_JSON = "json";
 const DEDUPE_COLLECTION = new Set(["icloud library", "icloudlibrary"]);
@@ -120,6 +111,19 @@ export function areFileWithCollectionsSame(
 export const areAllInSameDirectory = (paths: string[]) =>
     new Set(paths.map(dirname)).size == 1;
 
+// This is used to prompt the user the make upload strategy choice
+export interface ImportSuggestion {
+    rootFolderName: string;
+    hasNestedFolders: boolean;
+    hasRootLevelFileWithFolder: boolean;
+}
+
+export const DEFAULT_IMPORT_SUGGESTION: ImportSuggestion = {
+    rootFolderName: "",
+    hasNestedFolders: false,
+    hasRootLevelFileWithFolder: false,
+};
+
 export function getImportSuggestion(
     uploadType: PICKED_UPLOAD_TYPE,
     toUploadFiles: File[] | ElectronFile[],

+ 30 - 0
web/packages/next/types/ipc.ts

@@ -300,6 +300,21 @@ export interface Electron {
          * The returned paths are guaranteed to use POSIX separators ('/').
          */
         findFiles: (folderPath: string) => Promise<string[]>;
+
+        /**
+         * Add a new folder watch for the given {@link folderPath}.
+         *
+         * This adds a new entry in the list of watches (persisting them on
+         * disk), and also starts immediately observing for file system events
+         * that happen within {@link folderPath}.
+         *
+         * @param collectionMapping Determines how nested directories (if any)
+         * get mapped to Ente collections.
+         */
+        add: (
+            folderPath: string,
+            collectionMapping: CollectionMapping,
+        ) => Promise<void>;
     };
 
     registerWatcherFunctions: (
@@ -394,6 +409,12 @@ export interface AppUpdate {
  * side.
  */
 export interface FolderWatch {
+    /**
+     * Name of the root folder.
+     *
+     * This is just `basename(folderPath)`, but is retained as a precomputed
+     * property for convenience instead of needing to recompute it every time.
+     */
     rootFolderName: string;
     /**
      * Specify if nested files should all be mapped to the same single root
@@ -401,8 +422,17 @@ export interface FolderWatch {
      * files. @see {@link CollectionMapping}.
      */
     collectionMapping: CollectionMapping;
+    /**
+     * The path to the (root) folder we are watching.
+     */
     folderPath: string;
+    /**
+     * Files that have already been uploaded.
+     */
     syncedFiles: FolderWatchSyncedFile[];
+    /**
+     * Files (paths) that should be ignored when uploading.
+     */
     ignoredFiles: string[];
 }