π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Cleanup
Manav Rathi4fbfbf0aa089
diff --git a/web/apps/photos/src/services/export/index.ts b/web/apps/photos/src/services/export/index.tsindex 419db15876..c53448885b 100644--- a/web/apps/photos/src/services/export/index.ts+++ b/web/apps/photos/src/services/export/index.ts@@ -36,8 +36,8 @@ import {} from "utils/file";import {ENTE_TRASH_FOLDER,- getUniqueCollectionExportName,- getUniqueFileExportName,+ sanitizedUniqueFileName,+ santizedUniqueDirectoryName,} from "utils/native-fs";import { getAllLocalCollections } from "../collectionService";import downloadManager from "../download";@@ -485,7 +485,7 @@ class ExportService {collectionIDExportNameMap.get(collection.id);const oldCollectionExportPath = `${exportFolder}/${oldCollectionExportName}`;const newCollectionExportName =- await getUniqueCollectionExportName(+ await santizedUniqueDirectoryName(exportFolder,getCollectionUserFacingName(collection),);@@ -1009,7 +1009,7 @@ class ExportService {) {await this.verifyExportFolderExists(exportFolder);const collectionName = collectionIDNameMap.get(collectionID);- const collectionExportName = await getUniqueCollectionExportName(+ const collectionExportName = await santizedUniqueDirectoryName(exportFolder,collectionName,);@@ -1047,7 +1047,7 @@ class ExportService {file,);} else {- const fileExportName = await getUniqueFileExportName(+ const fileExportName = await sanitizedUniqueFileName(collectionExportPath,file.metadata.title,);@@ -1086,11 +1086,11 @@ class ExportService {) {const fileBlob = await new Response(fileStream).blob();const livePhoto = await decodeLivePhoto(file, fileBlob);- const imageExportName = await getUniqueFileExportName(+ const imageExportName = await sanitizedUniqueFileName(collectionExportPath,livePhoto.imageNameTitle,);- const videoExportName = await getUniqueFileExportName(+ const videoExportName = await sanitizedUniqueFileName(collectionExportPath,livePhoto.videoNameTitle,);diff --git a/web/apps/photos/src/utils/collection/index.ts b/web/apps/photos/src/utils/collection/index.tsindex 581523828d..5b4525341c 100644--- a/web/apps/photos/src/utils/collection/index.ts+++ b/web/apps/photos/src/utils/collection/index.ts@@ -44,7 +44,7 @@ import { SetFilesDownloadProgressAttributes } from "types/gallery";import { SUB_TYPE, VISIBILITY_STATE } from "types/magicMetadata";import { downloadFilesWithProgress } from "utils/file";import { isArchivedCollection, updateMagicMetadata } from "utils/magicMetadata";-import { getUniqueCollectionExportName } from "utils/native-fs";+import { santizedUniqueDirectoryName } from "utils/native-fs";export enum COLLECTION_OPS_TYPE {ADD,@@ -169,7 +169,7 @@ async function createCollectionDownloadFolder(downloadDirPath: string,collectionName: string,) {- const collectionDownloadName = await getUniqueCollectionExportName(+ const collectionDownloadName = await santizedUniqueDirectoryName(downloadDirPath,collectionName,);diff --git a/web/apps/photos/src/utils/file/index.ts b/web/apps/photos/src/utils/file/index.tsindex cd432ecbe0..fac27b825f 100644--- a/web/apps/photos/src/utils/file/index.ts+++ b/web/apps/photos/src/utils/file/index.ts@@ -52,7 +52,7 @@ import {import { VISIBILITY_STATE } from "types/magicMetadata";import { FileTypeInfo } from "types/upload";import { isArchivedFile, updateMagicMetadata } from "utils/magicMetadata";-import { getUniqueFileExportName } from "utils/native-fs";+import { sanitizedUniqueFileName } from "utils/native-fs";const WAIT_TIME_IMAGE_CONVERSION = 30 * 1000;@@ -812,7 +812,7 @@ async function downloadFileDesktop(if (file.metadata.fileType === FILE_TYPE.LIVE_PHOTO) {const fileBlob = await new Response(updatedFileStream).blob();const livePhoto = await decodeLivePhoto(file, fileBlob);- const imageExportName = await getUniqueFileExportName(+ const imageExportName = await sanitizedUniqueFileName(downloadPath,livePhoto.imageNameTitle,);@@ -822,7 +822,7 @@ async function downloadFileDesktop(imageStream,);try {- const videoExportName = await getUniqueFileExportName(+ const videoExportName = await sanitizedUniqueFileName(downloadPath,livePhoto.videoNameTitle,);@@ -836,7 +836,7 @@ async function downloadFileDesktop(throw e;}} else {- const fileExportName = await getUniqueFileExportName(+ const fileExportName = await sanitizedUniqueFileName(downloadPath,file.metadata.title,);diff --git a/web/apps/photos/src/utils/native-fs.ts b/web/apps/photos/src/utils/native-fs.tsindex 22aba96e48..b6c20594e8 100644--- a/web/apps/photos/src/utils/native-fs.ts+++ b/web/apps/photos/src/utils/native-fs.ts@@ -14,34 +14,47 @@ export const ENTE_TRASH_FOLDER = "Trash";export const sanitizeFilename = (s: string) =>sanitize(s, { replacement: "_" });-const exists = (path: string) => ensureElectron().fs.exists(path);--export const getUniqueCollectionExportName = async (- dir: string,- collectionName: string,+/**+ * Return a new unique directory name based on {@link name} that is not the same+ * as any existing directory in the given {@link directoryPath}.+ *+ * This function only works when we are running inside an electron app (since it+ * requires permissionless access to the native filesystem to find a new+ * filename that doesn't conflict with any existing items).+ *+ * See also: {@link santizedUniqueFileName}+ */+export const santizedUniqueDirectoryName = async (+ directoryPath: string,+ name: string,): Promise<string> => {- let collectionExportName = sanitizeFilename(collectionName);+ let result = sanitizeFilename(name);let count = 1;while (- (await exists(`${dir}/${collectionExportName}`)) ||- collectionExportName === ENTE_TRASH_FOLDER+ (await exists(`${directoryPath}/${result}`)) ||+ result === ENTE_TRASH_FOLDER) {- collectionExportName = `${sanitizeFilename(collectionName)}(${count})`;+ result = `${sanitizeFilename(name)}(${count})`;count++;}- return collectionExportName;+ return result;};-export const getUniqueFileExportName = async (- collectionExportPath: string,- filename: string,+/**+ * Return a new unique file name based on {@link name} that is not the same as+ * any existing directory in the given {@link directoryPath}.+ *+ * This function only works when we are running inside an electron app.+ * @see {@link santizedUniqueDirectoryName}.+ */+export const sanitizedUniqueFileName = async (+ directoryPath: string,+ name: string,) => {- let fileExportName = sanitizeFilename(filename);+ let fileExportName = sanitizeFilename(name);let count = 1;- while (await exists(`${collectionExportPath}/${fileExportName}`)) {- const filenameParts = splitFilenameAndExtension(- sanitizeFilename(filename),- );+ while (await exists(`${directoryPath}/${fileExportName}`)) {+ const filenameParts = splitFilenameAndExtension(sanitizeFilename(name));if (filenameParts[1]) {fileExportName = `${filenameParts[0]}(${count}).${filenameParts[1]}`;} else {@@ -51,3 +64,5 @@ export const getUniqueFileExportName = async (}return fileExportName;};++const exists = (path: string) => ensureElectron().fs.exists(path);diff --git a/web/packages/next/types/ipc.ts b/web/packages/next/types/ipc.tsindex 5b0979eaa2..82e4c2eb11 100644--- a/web/packages/next/types/ipc.ts+++ b/web/packages/next/types/ipc.ts@@ -80,7 +80,7 @@ export interface Electron {** If no such key is found, return `undefined`.*- * @see {@link saveEncryptionKey}.+ * See also: {@link saveEncryptionKey}.*/encryptionKey: () => Promise<string | undefined>;