From de783b61583138d8b01e1e30cd3e1c559c280216 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Fri, 19 Apr 2024 15:31:35 +0530 Subject: [PATCH] Seep in paths --- .../photos/src/components/Upload/Uploader.tsx | 54 +++++++++++++------ web/apps/photos/src/utils/upload/index.ts | 9 +++- 2 files changed, 47 insertions(+), 16 deletions(-) diff --git a/web/apps/photos/src/components/Upload/Uploader.tsx b/web/apps/photos/src/components/Upload/Uploader.tsx index 752b729a0e..c909aff662 100644 --- a/web/apps/photos/src/components/Upload/Uploader.tsx +++ b/web/apps/photos/src/components/Upload/Uploader.tsx @@ -112,11 +112,28 @@ export default function Uploader(props: Props) { const [importSuggestion, setImportSuggestion] = useState( DEFAULT_IMPORT_SUGGESTION, ); + /** + * Paths of file to upload that we've received over the IPC bridge from the + * code running in the Node.js layer of our desktop app. + */ + const [desktopFilePaths, setDesktopFilePaths] = useState< + string[] | undefined + >(); const [electronFiles, setElectronFiles] = useState(null); const [webFiles, setWebFiles] = useState([]); - const toUploadFiles = useRef(null); + const toUploadFiles = useRef< + File[] | ElectronFile[] | string[] | undefined | null + >(null); + /** + * If true, then the next upload we'll be processing was initiated by our + * desktop app. + */ const isPendingDesktopUpload = useRef(false); + /** + * If set, this will be the name of the collection that our desktop app + * wishes for us to upload into. + */ const pendingDesktopUploadCollectionName = useRef(""); // This is set when the user choses a type to upload from the upload type selector dialog const pickedUploadType = useRef(null); @@ -181,13 +198,10 @@ export default function Uploader(props: Props) { } }); - // eslint-disable-next-line @typescript-eslint/no-unused-vars const upload = (collectionName: string, filePaths: string[]) => { isPendingDesktopUpload.current = true; pendingDesktopUploadCollectionName.current = collectionName; - - // TODO (MR): - // setElectronFiles(filePaths); + setDesktopFilePaths(filePaths); }; const requestSyncWithRemote = () => { @@ -284,18 +298,22 @@ export default function Uploader(props: Props) { useEffect(() => { if ( + desktopFilePaths?.length > 0 || electronFiles?.length > 0 || webFiles?.length > 0 || appContext.sharedFiles?.length > 0 ) { log.info( - `upload request type:${ - electronFiles?.length > 0 - ? "electronFiles" - : webFiles?.length > 0 - ? "webFiles" - : "sharedFiles" + `upload request type: ${ + desktopFilePaths?.length > 0 + ? "desktopFilePaths" + : electronFiles?.length > 0 + ? "electronFiles" + : webFiles?.length > 0 + ? "webFiles" + : "sharedFiles" } count ${ + desktopFilePaths?.length ?? electronFiles?.length ?? webFiles?.length ?? appContext?.sharedFiles.length @@ -326,9 +344,13 @@ export default function Uploader(props: Props) { toUploadFiles.current = appContext.sharedFiles; appContext.resetSharedFiles(); } else if (electronFiles?.length > 0) { - // File selection from desktop app + // File selection from desktop app - deprecated toUploadFiles.current = electronFiles; setElectronFiles([]); + } else if (desktopFilePaths && desktopFilePaths.length > 0) { + // File selection from our desktop app + toUploadFiles.current = desktopFilePaths; + setDesktopFilePaths(undefined); } toUploadFiles.current = filterOutSystemFiles(toUploadFiles.current); @@ -339,7 +361,9 @@ export default function Uploader(props: Props) { const importSuggestion = getImportSuggestion( pickedUploadType.current, - toUploadFiles.current.map((file) => file["path"]), + toUploadFiles.current.map((file) => + typeof file == "string" ? file : file["path"], + ), ); setImportSuggestion(importSuggestion); @@ -352,7 +376,7 @@ export default function Uploader(props: Props) { pickedUploadType.current = null; props.setLoading(false); } - }, [webFiles, appContext.sharedFiles, electronFiles]); + }, [webFiles, appContext.sharedFiles, electronFiles, desktopFilePaths]); const resumeDesktopUpload = async ( type: PICKED_UPLOAD_TYPE, @@ -636,7 +660,7 @@ export default function Uploader(props: Props) { try { if (accessedThroughSharedURL) { log.info( - `uploading files to pulbic collection - ${props.uploadCollection.name} - ${props.uploadCollection.id}`, + `uploading files to public collection - ${props.uploadCollection.name} - ${props.uploadCollection.id}`, ); const uploaderName = await getPublicCollectionUploaderName( getPublicCollectionUID( diff --git a/web/apps/photos/src/utils/upload/index.ts b/web/apps/photos/src/utils/upload/index.ts index 4e6d216cf0..e7474697b3 100644 --- a/web/apps/photos/src/utils/upload/index.ts +++ b/web/apps/photos/src/utils/upload/index.ts @@ -205,12 +205,19 @@ export function groupFilesBasedOnParentFolder( return collectionNameToFilesMap; } -export function filterOutSystemFiles(files: File[] | ElectronFile[]) { +export function filterOutSystemFiles( + files: File[] | ElectronFile[] | string[] | undefined | null, +) { + if (!files) return files; + if (files[0] instanceof File) { const browserFiles = files as File[]; return browserFiles.filter((file) => { return !isSystemFile(file); }); + } else if (typeof files[0] == "string") { + const filePaths = files as string[]; + return filePaths.filter((path) => !isHiddenFile(path)); } else { const electronFiles = files as ElectronFile[]; return electronFiles.filter((file) => {