π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Move
Manav Rathi785f54e0436d
diff --git a/web/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/index.tsx b/web/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/index.tsxindex ea265f4b33..ba730f320a 100644--- a/web/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/index.tsx+++ b/web/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/index.tsx@@ -7,11 +7,11 @@ import {import type { MiniDialogAttributes } from "@/base/components/MiniDialog";import { nameAndExtension } from "@/base/file";import log from "@/base/log";+import { downloadAndRevokeObjectURL } from "@/base/utils/web";import { EnteFile } from "@/media/file";import { photosDialogZIndex } from "@/new/photos/components/z-index";import downloadManager from "@/new/photos/services/download";import { AppContext } from "@/new/photos/types/context";-import { downloadAndRevokeObjectURL } from "@/new/photos/utils/web";import { ensure } from "@/utils/ensure";import {CenteredFlex,diff --git a/web/apps/photos/src/components/Sidebar/index.tsx b/web/apps/photos/src/components/Sidebar/index.tsxindex 6e0c22f7c4..2d00329143 100644--- a/web/apps/photos/src/components/Sidebar/index.tsx+++ b/web/apps/photos/src/components/Sidebar/index.tsx@@ -7,11 +7,12 @@ import { useModalVisibility } from "@/base/components/utils/modal";import log from "@/base/log";import { savedLogs } from "@/base/log-web";import { customAPIHost } from "@/base/origins";+import { downloadString } from "@/base/utils/web";import { RecoveryKey } from "@/new/photos/components/RecoveryKey";import { downloadAppDialogAttributes } from "@/new/photos/components/utils/download";import type { CollectionSummaries } from "@/new/photos/services/collection/ui";import { AppContext, useAppContext } from "@/new/photos/types/context";-import { downloadString, initiateEmail, openURL } from "@/new/photos/utils/web";+import { initiateEmail, openURL } from "@/new/photos/utils/web";import { SpaceBetweenFlex } from "@ente/shared/components/Container";import { EnteMenuItem } from "@ente/shared/components/Menu/EnteMenuItem";import ThemeSwitcher from "@ente/shared/components/ThemeSwitcher";diff --git a/web/apps/photos/src/utils/file/index.ts b/web/apps/photos/src/utils/file/index.tsindex 38603effe6..9fffe73d50 100644--- a/web/apps/photos/src/utils/file/index.ts+++ b/web/apps/photos/src/utils/file/index.ts@@ -1,6 +1,7 @@import { sharedCryptoWorker } from "@/base/crypto";import log from "@/base/log";import { type Electron } from "@/base/types/ipc";+import { downloadAndRevokeObjectURL } from "@/base/utils/web";import {EncryptedEnteFile,EnteFile,@@ -19,7 +20,6 @@ import { updateExifIfNeededAndPossible } from "@/new/photos/services/exif-updateimport { detectFileTypeInfo } from "@/new/photos/utils/detect-type";import { safeFileName } from "@/new/photos/utils/native-fs";import { writeStream } from "@/new/photos/utils/native-stream";-import { downloadAndRevokeObjectURL } from "@/new/photos/utils/web";import { withTimeout } from "@/utils/promise";import { LS_KEYS, getData } from "@ente/shared/storage/localStorage";import type { User } from "@ente/shared/user/types";diff --git a/web/packages/base/utils/web.ts b/web/packages/base/utils/web.tsnew file mode 100644index 0000000000..f51583ae11--- /dev/null+++ b/web/packages/base/utils/web.ts@@ -0,0 +1,41 @@+/**+ * Download the asset at the given {@link url} to a file on the user's download+ * folder by appending a temporary <a> element to the DOM.+ *+ * @param url The URL that we want to download. See also+ * {@link downloadAndRevokeObjectURL} and {@link downloadString}.+ *+ * @param fileName The name of downloaded file.+ */+export const downloadURL = (url: string, fileName: string) => {+ const a = document.createElement("a");+ a.style.display = "none";+ a.href = url;+ a.download = fileName;+ document.body.appendChild(a);+ a.click();+ URL.revokeObjectURL(url);+ a.remove();+};++/**+ * A variant of {@link downloadURL} that also revokes the provided+ * {@link objectURL} after initiating the download.+ */+export const downloadAndRevokeObjectURL = (url: string, fileName: string) => {+ downloadURL(url, fileName);+ URL.revokeObjectURL(url);+};++/**+ * Save the given string {@link s} as a file in the user's download folder.+ *+ * @param s The string to save.+ *+ * @param fileName The name of the file that gets saved.+ */+export const downloadString = (s: string, fileName: string) => {+ const file = new Blob([s], { type: "text/plain" });+ const fileURL = URL.createObjectURL(file);+ downloadAndRevokeObjectURL(fileURL, fileName);+};diff --git a/web/packages/new/photos/components/RecoveryKey.tsx b/web/packages/new/photos/components/RecoveryKey.tsxindex d0f0d49697..0f024e5315 100644--- a/web/packages/new/photos/components/RecoveryKey.tsx+++ b/web/packages/new/photos/components/RecoveryKey.tsx@@ -4,6 +4,7 @@ import { errorDialogAttributes } from "@/base/components/utils/dialog";import type { ModalVisibilityProps } from "@/base/components/utils/modal";import { useIsSmallWidth } from "@/base/hooks";import log from "@/base/log";+import { downloadString } from "@/base/utils/web";import { ensure } from "@/utils/ensure";import CodeBlock from "@ente/shared/components/CodeBlock";import DialogTitleWithCloseButton from "@ente/shared/components/DialogBox/TitleWithCloseButton";@@ -19,7 +20,6 @@ import {import * as bip39 from "bip39";import { t } from "i18next";import { useCallback, useEffect, useState } from "react";-import { downloadString } from "../utils/web";// mobile client library only supports english.bip39.setDefaultWordlist("english");diff --git a/web/packages/new/photos/utils/web.ts b/web/packages/new/photos/utils/web.tsindex 92ba90a4ac..7236cab798 100644--- a/web/packages/new/photos/utils/web.ts+++ b/web/packages/new/photos/utils/web.ts@@ -21,45 +21,3 @@ export const initiateEmail = (email: string) => {a.rel = "noopener";a.click();};--/**- * Download the asset at the given {@link url} to a file on the user's download- * folder by appending a temporary <a> element to the DOM.- *- * @param url The URL that we want to download. See also- * {@link downloadAndRevokeObjectURL} and {@link downloadString}.- *- * @param fileName The name of downloaded file.- */-export const downloadURL = (url: string, fileName: string) => {- const a = document.createElement("a");- a.style.display = "none";- a.href = url;- a.download = fileName;- document.body.appendChild(a);- a.click();- URL.revokeObjectURL(url);- a.remove();-};--/**- * A variant of {@link downloadURL} that also revokes the provided- * {@link objectURL} after initiating the download.- */-export const downloadAndRevokeObjectURL = (url: string, fileName: string) => {- downloadURL(url, fileName);- URL.revokeObjectURL(url);-};--/**- * Save the given string {@link s} as a file in the user's download folder.- *- * @param s The string to save.- *- * @param fileName The name of the file that gets saved.- */-export const downloadString = (s: string, fileName: string) => {- const file = new Blob([s], { type: "text/plain" });- const fileURL = URL.createObjectURL(file);- downloadAndRevokeObjectURL(fileURL, fileName);-};