π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Prune
Manav Rathiffb19c3a6507
diff --git a/web/packages/accounts/components/VerifyMasterPasswordForm.tsx b/web/packages/accounts/components/VerifyMasterPasswordForm.tsxindex 73d0b529ba..f5ed68553a 100644--- a/web/packages/accounts/components/VerifyMasterPasswordForm.tsx+++ b/web/packages/accounts/components/VerifyMasterPasswordForm.tsx@@ -8,10 +8,10 @@ import { LoadingButton } from "ente-base/components/mui/LoadingButton";import { ShowHidePasswordInputAdornment } from "ente-base/components/mui/PasswordInputAdornment";import { sharedCryptoWorker } from "ente-base/crypto";import log from "ente-base/log";-import { CustomError } from "ente-shared/error";import { useFormik } from "formik";import { t } from "i18next";import { useCallback, useState } from "react";+import { twoFactorEnabledErrorMessage } from "./utils/second-factor-choice";export interface VerifyMasterPasswordFormProps {/**@@ -30,9 +30,9 @@ export interface VerifyMasterPasswordFormProps {* used for reauthenticating the user after they've already logged in, then* this function will not be provided.*- * This function can throw an `CustomError.TWO_FACTOR_ENABLED` to signal to- * the form that some other form of second factor is enabled and the user- * has been redirected to a two factor verification page.+ * @throws A Error with message {@link twoFactorEnabledErrorMessage} to+ * signal to the form that some other form of second factor is enabled and+ * the user has been redirected to a two factor verification page.** @throws A Error with message* {@link srpVerificationUnauthorizedErrorMessage} to signal that either@@ -154,7 +154,7 @@ export const VerifyMasterPasswordForm: React.FC<} catch (e) {if (e instanceof Error) {switch (e.message) {- case CustomError.TWO_FACTOR_ENABLED:+ case twoFactorEnabledErrorMessage:// Two factor enabled, user has been redirected to// the two-factor verification page.return;diff --git a/web/packages/accounts/components/utils/second-factor-choice.ts b/web/packages/accounts/components/utils/second-factor-choice.tsindex 1557255ae3..e2e2ca19a3 100644--- a/web/packages/accounts/components/utils/second-factor-choice.ts+++ b/web/packages/accounts/components/utils/second-factor-choice.ts@@ -8,6 +8,15 @@ import { useModalVisibility } from "ente-base/components/utils/modal";import { useCallback, useMemo, useRef } from "react";import type { SecondFactorType } from "../SecondFactorChoice";+/**+ * The message of the {@link Error} that is thrown when the user has enabled a+ * second factor so further authentication is needed during the login sequence.+ *+ * TODO: This is not really an error but rather is a code flow flag; consider+ * not using exceptions for flow control.+ */+export const twoFactorEnabledErrorMessage = "two factor enabled";+/*** A convenience hook for keeping track of the state and logic that is needed* after password verification to determine which second factor (if any) wediff --git a/web/packages/accounts/pages/credentials.tsx b/web/packages/accounts/pages/credentials.tsxindex c03b269ae0..975437b049 100644--- a/web/packages/accounts/pages/credentials.tsx+++ b/web/packages/accounts/pages/credentials.tsx@@ -6,7 +6,10 @@ import {} from "ente-accounts/components/LoginComponents";import { SecondFactorChoice } from "ente-accounts/components/SecondFactorChoice";import { sessionExpiredDialogAttributes } from "ente-accounts/components/utils/dialog";-import { useSecondFactorChoiceIfNeeded } from "ente-accounts/components/utils/second-factor-choice";+import {+ twoFactorEnabledErrorMessage,+ useSecondFactorChoiceIfNeeded,+} from "ente-accounts/components/utils/second-factor-choice";import {VerifyMasterPasswordForm,type VerifyMasterPasswordFormProps,@@ -47,7 +50,6 @@ import {unstashKeyEncryptionKeyFromSession,updateSessionFromElectronSafeStorageIfNeeded,} from "ente-base/session";-import { CustomError } from "ente-shared/error";import { getData, setData, setLSUser } from "ente-shared/storage/localStorage";import {getToken,@@ -205,7 +207,7 @@ const Page: React.FC = () => {);setPasskeyVerificationData({ passkeySessionID, url });openPasskeyVerificationURL({ passkeySessionID, url });- throw Error(CustomError.TWO_FACTOR_ENABLED);+ throw new Error(twoFactorEnabledErrorMessage);} else if (twoFactorSessionID) {await stashKeyEncryptionKeyInSessionStore(kek);const user = getData("user");@@ -215,7 +217,7 @@ const Page: React.FC = () => {isTwoFactorEnabled: true,});void router.push("/two-factor/verify");- throw Error(CustomError.TWO_FACTOR_ENABLED);+ throw new Error(twoFactorEnabledErrorMessage);} else {const user = getData("user");await setLSUser({@@ -231,7 +233,7 @@ const Page: React.FC = () => {} catch (e) {if (e instanceof Error &&- e.message != CustomError.TWO_FACTOR_ENABLED+ e.message != twoFactorEnabledErrorMessage) {log.error("getKeyAttributes failed", e);}diff --git a/web/packages/new/photos/components/Export.tsx b/web/packages/new/photos/components/Export.tsxindex d008f00289..2fa2f6d42f 100644--- a/web/packages/new/photos/components/Export.tsx+++ b/web/packages/new/photos/components/Export.tsx@@ -39,7 +39,6 @@ import log from "ente-base/log";import { type EnteFile } from "ente-media/file";import { fileFileName } from "ente-media/file-metadata";import { ItemCard, PreviewItemTile } from "ente-new/photos/components/Tiles";-import { CustomError } from "ente-shared/error";import { t } from "i18next";import React, { memo, useCallback, useEffect, useState } from "react";import { Trans } from "react-i18next";@@ -50,6 +49,7 @@ import {type ListItemKeySelector,} from "react-window";import exportService, {+ CustomError,ExportStage,selectAndPrepareExportDirectory,type ExportOpts,diff --git a/web/packages/new/photos/services/export.ts b/web/packages/new/photos/services/export.tsindex c8df22cedb..aef25fb6e3 100644--- a/web/packages/new/photos/services/export.ts+++ b/web/packages/new/photos/services/export.ts@@ -31,13 +31,19 @@ import {safeDirectoryName,safeFileName,} from "ente-new/photos/utils/native-fs";-import { CustomError } from "ente-shared/error";import { getData, setData } from "ente-shared/storage/localStorage";import { PromiseQueue } from "ente-utils/promise";import i18n from "i18next";import { migrateExport, type ExportRecord } from "./export-migration";import { savedCollectionFiles, savedCollections } from "./photos-fdb";+// TODO: Audit the uses of these constants+export const CustomError = {+ UPDATE_EXPORTED_RECORD_FAILED: "update file exported record failed",+ EXPORT_STOPPED: "export stopped",+ EXPORT_FOLDER_DOES_NOT_EXIST: "export folder does not exist",+};+/** Name of the JSON file in which we keep the state of the export. */const exportRecordFileName = "export_status.json";diff --git a/web/packages/shared/error/index.ts b/web/packages/shared/error/index.tsdeleted file mode 100644index f776ae6056..0000000000--- a/web/packages/shared/error/index.ts+++ /dev/null@@ -1,11 +0,0 @@-export const CustomError = {- TOKEN_EXPIRED: "token expired",- TOO_MANY_REQUESTS: "too many requests",- BAD_REQUEST: "bad request",- SUBSCRIPTION_NEEDED: "subscription not present",- NOT_FOUND: "not found ",- UPDATE_EXPORTED_RECORD_FAILED: "update file exported record failed",- EXPORT_STOPPED: "export stopped",- EXPORT_FOLDER_DOES_NOT_EXIST: "export folder does not exist",- TWO_FACTOR_ENABLED: "two factor enabled",-};