π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[web][photos] Stop export from treating sanitized album names as renames
Sriram-PR6913a9ae4594
diff --git a/web/apps/photos/src/services/export.ts b/web/apps/photos/src/services/export.tsindex 8258183b41..0d4c97283e 100644--- a/web/apps/photos/src/services/export.ts+++ b/web/apps/photos/src/services/export.ts@@ -1,7 +1,11 @@// Export records are unvalidated disk input, so runtime guards which the// types deem unnecessary are load-bearing./* eslint-disable @typescript-eslint/no-unnecessary-condition */-import { safeDirectoryName, safeFileName } from "@/utils/native-fs";+import {+ safeDirectoryName,+ safeFileName,+ sanitizeFilename,+} from "@/utils/native-fs";import {ensureElectron,suppressMainWindowBlurForTrustedPrompt,@@ -1186,7 +1190,7 @@ const convertFileIDExportNameObjectToMap = ();};-const getRenamedExportedCollections = (+export const getRenamedExportedCollections = (collections: Collection[],exportRecord: ExportRecord,) => {@@ -1202,7 +1206,11 @@ const getRenamedExportedCollections = (collection.id,)!;- const collectionExportName = collectionUserFacingName(collection);+ // Export folder names are sanitized, so compare against the+ // sanitized form of the album name.+ const collectionExportName = sanitizeFilename(+ collectionUserFacingName(collection),+ );if (currentExportName === collectionExportName) {return false;diff --git a/web/apps/photos/src/utils/native-fs.ts b/web/apps/photos/src/utils/native-fs.tsindex 13773275db..f5da4ffe6b 100644--- a/web/apps/photos/src/utils/native-fs.ts+++ b/web/apps/photos/src/utils/native-fs.ts@@ -5,7 +5,8 @@ import {} from "ente-gallery/export-dirs";import sanitize from "sanitize-filename";-const sanitizeFilename = (s: string) => sanitize(s, { replacement: "_" });+export const sanitizeFilename = (s: string) =>+ sanitize(s, { replacement: "_" });export const safeDirectoryName = async (directoryPath: string,diff --git a/web/apps/photos/tests/export.test.ts b/web/apps/photos/tests/export.test.tsindex 6b468b17ab..901d2548f1 100644--- a/web/apps/photos/tests/export.test.ts+++ b/web/apps/photos/tests/export.test.ts@@ -1,8 +1,11 @@import { tryParseTakeoutMetadataJSON } from "ente-gallery/services/upload/metadata-json";+import type { Collection } from "ente-media/collection";import type { EnteFile } from "ente-media/file";import { FileType } from "ente-media/file-type";import { afterEach, beforeEach, expect, test, vi } from "vitest";-import exportService from "../src/services/export";+import exportService, {+ getRenamedExportedCollections,+} from "../src/services/export";const { writeFile } = vi.hoisted(() => ({writeFile: vi.fn<(path: string, contents: string) => Promise<void>>(),@@ -18,7 +21,9 @@ vi.mock("ente-gallery/services/download", () => ({downloadManager: { fileStream: vi.fn() },}));vi.mock("ente-gallery/utils/native-stream", () => ({ writeStream: vi.fn() }));-vi.mock("ente-new/photos/services/collection", () => ({}));+vi.mock("ente-new/photos/services/collection", () => ({+ collectionUserFacingName: (collection: Collection) => collection.name,+}));vi.mock("ente-new/photos/services/photos-fdb", () => ({}));const file = {@@ -86,3 +91,20 @@ test.each([expect(metadata.geoData).toEqual(expected);},);++test.each([+ ["Project: Alpha", "Project_ Alpha", false],+ ["Project: Alpha", "Project_ Alpha(1)", false],+ ["Trip?", "Trip_", false],+ ["Architecture", "Architecture", false],+ ["New name", "Old name", true],+ ["Project: Beta", "Project_ Alpha", true],+])("album %j exported as %j is renamed: %s", (name, exportName, renamed) => {+ const collection = { id: 1, name } as Collection;+ const exportRecord = {+ collectionExportNames: { 1: exportName },+ } as unknown as Parameters<typeof getRenamedExportedCollections>[1];+ expect(getRenamedExportedCollections([collection], exportRecord)).toEqual(+ renamed ? [collection] : [],+ );+});