π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Ref
Manav Rathic366d7e2824c
diff --git a/web/packages/gallery/components/viewer/FileViewer.tsx b/web/packages/gallery/components/viewer/FileViewer.tsxindex 207a55e801..054238e088 100644--- a/web/packages/gallery/components/viewer/FileViewer.tsx+++ b/web/packages/gallery/components/viewer/FileViewer.tsx@@ -53,6 +53,7 @@ import React, {useRef,useState,} from "react";+import { fileVisibility } from "../../services/magic-metadata";import {fileInfoExifForFile,updateItemDataAlt,@@ -687,11 +688,11 @@ export const FileViewer: React.FC<FileViewerProps> = ({[activeAnnotatedFile],);- const { visibility, isPendingVisibility, toggleVisibility } =+ const { isArchived, isPendingToggleArchive, toggleArchived } =useMemo(() => {- let visibility: "visible" | "archived" | undefined;- let isPendingVisibility: boolean | undefined;- let toggleVisibility: (() => void) | undefined;+ let isArchived: boolean | undefined;+ let isPendingToggleArchive: boolean | undefined;+ let toggleArchived: (() => void) | undefined;const file = activeAnnotatedFile?.file;@@ -703,30 +704,29 @@ export const FileViewer: React.FC<FileViewerProps> = ({) {switch (unsyncedVisibilityUpdates.get(file.id) ??- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition- file.magicMetadata?.data?.visibility+ fileVisibility(file)) {case undefined:case ItemVisibility.visible:- visibility = "visible";+ isArchived = false;break;case ItemVisibility.archived:- visibility = "archived";+ isArchived = true;break;}- isPendingVisibility = pendingVisibilityUpdates.has(file.id);+ isPendingToggleArchive = pendingVisibilityUpdates.has(file.id);- toggleVisibility = () =>+ toggleArchived = () =>void onFileVisibilityUpdate(file.id,- visibility == "archived"+ isArchived? ItemVisibility.visible: ItemVisibility.archived,);}- return { visibility, isPendingVisibility, toggleVisibility };+ return { isArchived, isPendingToggleArchive, toggleArchived };}, [pendingVisibilityUpdates,unsyncedVisibilityUpdates,@@ -890,17 +890,15 @@ export const FileViewer: React.FC<FileViewerProps> = ({<DeleteIcon /></MoreMenuItem>)}- {visibility && (+ {isArchived !== undefined && (<MoreMenuItem- onClick={toggleVisibility}- disabled={isPendingVisibility}+ onClick={toggleArchived}+ disabled={isPendingToggleArchive}><MoreMenuItemTitle>- {visibility == "archived"- ? t("unarchive")- : t("archive")}+ {isArchived ? t("unarchive") : t("archive")}</MoreMenuItemTitle>- {visibility == "archived" ? (+ {isArchived ? (<UnArchiveIcon />) : (<ArchiveOutlinedIcon />diff --git a/web/packages/gallery/services/magic-metadata.ts b/web/packages/gallery/services/magic-metadata.tsindex 5578b5c069..0d9b9fe134 100644--- a/web/packages/gallery/services/magic-metadata.ts+++ b/web/packages/gallery/services/magic-metadata.ts@@ -3,15 +3,41 @@/* eslint-disable @typescript-eslint/no-unnecessary-condition */import { sharedCryptoWorker } from "@/base/crypto";import type { Collection } from "@/media/collection";-import type { EnteFile, MagicMetadataCore } from "@/media/file";-import { ItemVisibility } from "@/media/file-metadata";+import { fileLogID, type EnteFile, type MagicMetadataCore } from "@/media/file";+import {+ ItemVisibility,+ type PrivateMagicMetadata,+} from "@/media/file-metadata";-export function isArchivedFile(item: EnteFile): boolean {- if (!item || !item.magicMetadata || !item.magicMetadata.data) {- return false;+/**+ * Return the magic metadata for an {@link EnteFile}.+ *+ * We are not expected to be in a scenario where the file gets to the UI without+ * having its magic metadata decrypted, so this function is a sanity+ * check and should be a no-op in usually. It'll throw if it finds its+ * assumptions broken. Once the types have been refactored this entire+ * check/cast shouldn't be needed, and this should become a trivial accessor.+ */+export const fileMagicMetadata = (file: EnteFile) => {+ if (!file.magicMetadata) return undefined;+ if (typeof file.magicMetadata.data == "string") {+ throw new Error(+ `Magic metadata for ${fileLogID(file)} had not been decrypted even when the file reached the UI layer`,+ );}- return item.magicMetadata.data.visibility === ItemVisibility.archived;-}+ // This cast is unavoidable in the current setup. We need to refactor the+ // types so that this cast in not needed.+ return file.magicMetadata.data as PrivateMagicMetadata;+};++/**+ * Return the {@link ItemVisibility} for the given {@link file}.+ */+export const fileVisibility = (file: EnteFile) =>+ fileMagicMetadata(file)?.visibility;++export const isArchivedFile = (item: EnteFile) =>+ fileVisibility(item) === ItemVisibility.archived;export const isArchivedCollection = (item: Collection) => {if (!item) {