π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
conv
Manav Rathi05b0e84a2a43
diff --git a/web/apps/photos/src/components/pages/gallery/SelectedFileOptions.tsx b/web/apps/photos/src/components/pages/gallery/SelectedFileOptions.tsxindex ca8f740fc6..6e75c9e93c 100644--- a/web/apps/photos/src/components/pages/gallery/SelectedFileOptions.tsx+++ b/web/apps/photos/src/components/pages/gallery/SelectedFileOptions.tsx@@ -24,11 +24,11 @@ import VisibilityOutlinedIcon from "@mui/icons-material/VisibilityOutlined";import { IconButton, Tooltip, Typography } from "@mui/material";import { t } from "i18next";import { type CollectionOp } from "utils/collection";-import { FILE_OPS_TYPE } from "utils/file";+import { type FileOp } from "utils/file";interface Props {- handleCollectionOp: (opsType: CollectionOp) => (...args: any[]) => void;- handleFileOps: (opsType: FILE_OPS_TYPE) => (...args: any[]) => void;+ handleCollectionOp: (op: CollectionOp) => (...args: any[]) => void;+ handleFileOp: (op: FileOp) => (...args: any[]) => void;showCreateCollectionModal: (op: CollectionOp) => () => void;/*** Callback to open a dialog where the user can choose a collection.@@ -77,7 +77,7 @@ const SelectedFileOptions = ({showCreateCollectionModal,onOpenCollectionSelector,handleCollectionOp,- handleFileOps,+ handleFileOp,selectedCollection,count,ownCount,@@ -110,7 +110,7 @@ const SelectedFileOptions = ({continue: {text: t("move_to_trash"),color: "critical",- action: handleFileOps(FILE_OPS_TYPE.TRASH),+ action: handleFileOp("trash"),},});@@ -121,7 +121,7 @@ const SelectedFileOptions = ({continue: {text: t("delete"),color: "critical",- action: handleFileOps(FILE_OPS_TYPE.DELETE_PERMANENTLY),+ action: handleFileOp("deletePermanently"),},});@@ -194,16 +194,12 @@ const SelectedFileOptions = ({{isInSearchMode ? (<><Tooltip title={t("fix_creation_time")}>- <IconButton- onClick={handleFileOps(FILE_OPS_TYPE.FIX_TIME)}- >+ <IconButton onClick={handleFileOp("fixTime")}><ClockIcon /></IconButton></Tooltip><Tooltip title={t("download")}>- <IconButton- onClick={handleFileOps(FILE_OPS_TYPE.DOWNLOAD)}- >+ <IconButton onClick={handleFileOp("download")}><DownloadIcon /></IconButton></Tooltip>@@ -213,14 +209,12 @@ const SelectedFileOptions = ({</IconButton></Tooltip><Tooltip title={t("archive")}>- <IconButton- onClick={handleFileOps(FILE_OPS_TYPE.ARCHIVE)}- >+ <IconButton onClick={handleFileOp("archive")}><ArchiveIcon /></IconButton></Tooltip><Tooltip title={t("hide")}>- <IconButton onClick={handleFileOps(FILE_OPS_TYPE.HIDE)}>+ <IconButton onClick={handleFileOp("hide")}><VisibilityOffOutlinedIcon /></IconButton></Tooltip>@@ -233,9 +227,7 @@ const SelectedFileOptions = ({) : peopleMode ? (<><Tooltip title={t("download")}>- <IconButton- onClick={handleFileOps(FILE_OPS_TYPE.DOWNLOAD)}- >+ <IconButton onClick={handleFileOp("download")}><DownloadIcon /></IconButton></Tooltip>@@ -245,14 +237,12 @@ const SelectedFileOptions = ({</IconButton></Tooltip><Tooltip title={t("archive")}>- <IconButton- onClick={handleFileOps(FILE_OPS_TYPE.ARCHIVE)}- >+ <IconButton onClick={handleFileOp("archive")}><ArchiveIcon /></IconButton></Tooltip><Tooltip title={t("hide")}>- <IconButton onClick={handleFileOps(FILE_OPS_TYPE.HIDE)}>+ <IconButton onClick={handleFileOp("hide")}><VisibilityOffOutlinedIcon /></IconButton></Tooltip>@@ -278,9 +268,7 @@ const SelectedFileOptions = ({) : isUncategorizedCollection ? (<><Tooltip title={t("download")}>- <IconButton- onClick={handleFileOps(FILE_OPS_TYPE.DOWNLOAD)}- >+ <IconButton onClick={handleFileOp("download")}><DownloadIcon /></IconButton></Tooltip>@@ -297,7 +285,7 @@ const SelectedFileOptions = ({</>) : isIncomingSharedCollection ? (<Tooltip title={t("download")}>- <IconButton onClick={handleFileOps(FILE_OPS_TYPE.DOWNLOAD)}>+ <IconButton onClick={handleFileOp("download")}><DownloadIcon /></IconButton></Tooltip>@@ -309,9 +297,7 @@ const SelectedFileOptions = ({</IconButton></Tooltip><Tooltip title={t("download")}>- <IconButton- onClick={handleFileOps(FILE_OPS_TYPE.DOWNLOAD)}- >+ <IconButton onClick={handleFileOp("download")}><DownloadIcon /></IconButton></Tooltip>@@ -325,28 +311,20 @@ const SelectedFileOptions = ({) : (<><Tooltip title={t("fix_creation_time")}>- <IconButton- onClick={handleFileOps(FILE_OPS_TYPE.FIX_TIME)}- >+ <IconButton onClick={handleFileOp("fixTime")}><ClockIcon /></IconButton></Tooltip>{!isFavoriteCollection &&activeCollectionID != ARCHIVE_SECTION && (<Tooltip title={t("favorite")}>- <IconButton- onClick={handleFileOps(- FILE_OPS_TYPE.SET_FAVORITE,- )}- >+ <IconButton onClick={handleFileOp("favorite")}><FavoriteBorderIcon /></IconButton></Tooltip>)}<Tooltip title={t("download")}>- <IconButton- onClick={handleFileOps(FILE_OPS_TYPE.DOWNLOAD)}- >+ <IconButton onClick={handleFileOp("download")}><DownloadIcon /></IconButton></Tooltip>@@ -357,18 +335,14 @@ const SelectedFileOptions = ({</Tooltip>{activeCollectionID === ARCHIVE_SECTION && (<Tooltip title={t("unarchive")}>- <IconButton- onClick={handleFileOps(FILE_OPS_TYPE.UNARCHIVE)}- >+ <IconButton onClick={handleFileOp("unarchive")}><UnArchiveIcon /></IconButton></Tooltip>)}{activeCollectionID === ALL_SECTION && (<Tooltip title={t("archive")}>- <IconButton- onClick={handleFileOps(FILE_OPS_TYPE.ARCHIVE)}- >+ <IconButton onClick={handleFileOp("archive")}><ArchiveIcon /></IconButton></Tooltip>@@ -393,7 +367,7 @@ const SelectedFileOptions = ({</>)}<Tooltip title={t("hide")}>- <IconButton onClick={handleFileOps(FILE_OPS_TYPE.HIDE)}>+ <IconButton onClick={handleFileOp("hide")}><VisibilityOffOutlinedIcon /></IconButton></Tooltip>diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsxindex 832179bf28..51bdcfab75 100644--- a/web/apps/photos/src/pages/gallery.tsx+++ b/web/apps/photos/src/pages/gallery.tsx@@ -132,7 +132,7 @@ import {handleCollectionOp,type CollectionOp,} from "utils/collection";-import { FILE_OPS_TYPE, getSelectedFiles, handleFileOps } from "utils/file";+import { type FileOp, getSelectedFiles, handleFileOp } from "utils/file";const defaultGalleryContext: GalleryContextType = {setActiveCollectionID: () => null,@@ -712,21 +712,21 @@ const Page: React.FC = () => {}};- const fileOpsHelper = (ops: FILE_OPS_TYPE) => async () => {+ const fileOpHelper = (op: FileOp) => async () => {showLoadingBar();try {// passing files here instead of filteredData for hide ops because we want to move all files copies to hidden collectionconst selectedFiles = getSelectedFiles(selected,- ops === FILE_OPS_TYPE.HIDE ? normalFiles : filteredFiles,+ op == "hide" ? normalFiles : filteredFiles,);const toProcessFiles =- ops === FILE_OPS_TYPE.DOWNLOAD+ op == "download"? selectedFiles: selectedFiles.filter((file) => file.ownerID === user.id);if (toProcessFiles.length > 0) {- await handleFileOps(- ops,+ await handleFileOp(+ op,toProcessFiles,handleMarkTempDeleted,() => dispatch({ type: "clearTempDeleted" }),@@ -977,7 +977,7 @@ const Page: React.FC = () => {{showSelectionBar ? (<SelectedFileOptionshandleCollectionOp={collectionOpsHelper}- handleFileOps={fileOpsHelper}+ handleFileOp={fileOpHelper}showCreateCollectionModal={showCreateCollectionModal}diff --git a/web/apps/photos/src/utils/file/index.ts b/web/apps/photos/src/utils/file/index.tsindex 8e92807c97..cc552ba792 100644--- a/web/apps/photos/src/utils/file/index.ts+++ b/web/apps/photos/src/utils/file/index.ts@@ -30,16 +30,15 @@ import {SetFilesDownloadProgressAttributesCreator,} from "types/gallery";-export enum FILE_OPS_TYPE {- DOWNLOAD,- FIX_TIME,- ARCHIVE,- UNARCHIVE,- HIDE,- TRASH,- DELETE_PERMANENTLY,- SET_FAVORITE,-}+export type FileOp =+ | "download"+ | "fixTime"+ | "favorite"+ | "archive"+ | "unarchive"+ | "hide"+ | "trash"+ | "deletePermanently";export async function downloadFile(file: EnteFile) {try {@@ -375,8 +374,8 @@ export const shouldShowAvatar = (file: EnteFile, user: User) => {}};-export const handleFileOps = async (- ops: FILE_OPS_TYPE,+export const handleFileOp = async (+ op: FileOp,files: EnteFile[],markTempDeleted: (files: EnteFile[]) => void,clearTempDeleted: () => void,@@ -385,35 +384,8 @@ export const handleFileOps = async (fixCreationTime: (files: EnteFile[]) => void,setFilesDownloadProgressAttributesCreator: SetFilesDownloadProgressAttributesCreator,) => {- switch (ops) {- case FILE_OPS_TYPE.TRASH:- try {- markTempDeleted(files);- await moveToTrash(files);- } catch (e) {- clearTempDeleted();- throw e;- }- break;- case FILE_OPS_TYPE.DELETE_PERMANENTLY:- try {- markTempDeleted(files);- await deleteFromTrash(files.map((file) => file.id));- } catch (e) {- clearTempDeleted();- throw e;- }- break;- case FILE_OPS_TYPE.HIDE:- try {- markTempHidden(files);- await moveToHiddenCollection(files);- } catch (e) {- clearTempHidden();- throw e;- }- break;- case FILE_OPS_TYPE.DOWNLOAD: {+ switch (op) {+ case "download": {const setSelectedFileDownloadProgressAttributes =setFilesDownloadProgressAttributesCreator(t("files_count", { count: files.length }),@@ -424,17 +396,44 @@ export const handleFileOps = async ();break;}- case FILE_OPS_TYPE.FIX_TIME:+ case "fixTime":fixCreationTime(files);break;- case FILE_OPS_TYPE.ARCHIVE:+ case "favorite":+ await addMultipleToFavorites(files);+ break;+ case "archive":await changeFilesVisibility(files, ItemVisibility.archived);break;- case FILE_OPS_TYPE.UNARCHIVE:+ case "unarchive":await changeFilesVisibility(files, ItemVisibility.visible);break;- case FILE_OPS_TYPE.SET_FAVORITE:- await addMultipleToFavorites(files);+ case "hide":+ try {+ markTempHidden(files);+ await moveToHiddenCollection(files);+ } catch (e) {+ clearTempHidden();+ throw e;+ }+ break;+ case "trash":+ try {+ markTempDeleted(files);+ await moveToTrash(files);+ } catch (e) {+ clearTempDeleted();+ throw e;+ }+ break;+ case "deletePermanently":+ try {+ markTempDeleted(files);+ await deleteFromTrash(files.map((file) => file.id));+ } catch (e) {+ clearTempDeleted();+ throw e;+ }break;}};