π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Sep
Manav Rathia91626aa89cb
diff --git a/web/apps/photos/src/components/PhotoFrame.tsx b/web/apps/photos/src/components/PhotoFrame.tsxindex 5d10b26037..330d67cb35 100644--- a/web/apps/photos/src/components/PhotoFrame.tsx+++ b/web/apps/photos/src/components/PhotoFrame.tsx@@ -1,10 +1,12 @@import log from "@/base/log";-import type { LivePhotoSourceURL, SourceURLs } from "@/media/file";import { EnteFile } from "@/media/file";import { FileType } from "@/media/file-type";import type { GalleryBarMode } from "@/new/photos/components/gallery/reducer";import { TRASH_SECTION } from "@/new/photos/services/collection";-import DownloadManager from "@/new/photos/services/download";+import DownloadManager, {+ type LivePhotoSourceURL,+ type SourceURLs,+} from "@/new/photos/services/download";import { PHOTOS_PAGES } from "@ente/shared/constants/pages";import useMemoSingleThreaded from "@ente/shared/hooks/useMemoSingleThreaded";import { styled } from "@mui/material";@@ -39,6 +41,23 @@ const Container = styled("div")`const PHOTOSWIPE_HASH_SUFFIX = "&opened";+/**+ * An {@link EnteFile} augmented with various in-memory state used for+ * displaying it in the photo viewer.+ */+export type DisplayFile = EnteFile & {+ src?: string;+ srcURLs?: SourceURLs;+ msrc?: string;+ html?: string;+ w?: number;+ h?: number;+ title?: string;+ isSourceLoaded?: boolean;+ conversionFailed?: boolean;+ canForceConvert?: boolean;+};+export interface PhotoFrameProps {page:| PHOTOS_PAGES.GALLERY@@ -118,7 +137,7 @@ const PhotoFrame = ({h: window.innerHeight,title: item.pubMagicMetadata?.data.caption,};- return filteredItem;+ return filteredItem as DisplayFile;});}, [files]);@@ -288,7 +307,7 @@ const PhotoFrame = ({};const getThumbnail = (- item: EnteFile,+ item: DisplayFile,index: number,isScrolling: boolean,) => (@@ -329,7 +348,7 @@ const PhotoFrame = ({const getSlideData = async (instance: PhotoSwipe<PhotoSwipe.Options>,index: number,- item: EnteFile,+ item: DisplayFile,) => {log.info(`[${item.id}] getSlideData called for thumbnail: ${!!item.msrc} sourceLoaded: ${!!item.isSourceLoaded} fetching: ${!!fetching[item.id]}`,@@ -442,7 +461,7 @@ const PhotoFrame = ({const updateThumb = (instance: PhotoSwipe<PhotoSwipe.Options>,index: number,- item: EnteFile,+ item: DisplayFile,url: string,forceUpdate?: boolean,) => {@@ -465,7 +484,7 @@ const PhotoFrame = ({const updateOrig = async (instance: PhotoSwipe<PhotoSwipe.Options>,index: number,- item: EnteFile,+ item: DisplayFile,srcURL: SourceURLs,forceUpdate?: boolean,) => {@@ -488,7 +507,7 @@ const PhotoFrame = ({const forceConvertItem = async (instance: PhotoSwipe<PhotoSwipe.Options>,index: number,- item: EnteFile,+ item: DisplayFile,) => {updateThumb(instance, index, item, item.msrc, true);@@ -563,7 +582,7 @@ const PhotoFrame = ({export default PhotoFrame;-function updateFileMsrcProps(file: EnteFile, url: string) {+function updateFileMsrcProps(file: DisplayFile, url: string) {file.w = window.innerWidth;file.h = window.innerHeight;file.msrc = url;@@ -582,7 +601,7 @@ function updateFileMsrcProps(file: EnteFile, url: string) {}async function updateFileSrcProps(- file: EnteFile,+ file: DisplayFile,srcURLs: SourceURLs,enableDownload: boolean,) {diff --git a/web/apps/photos/src/components/PhotoViewer/FileInfo/RenderCaption.tsx b/web/apps/photos/src/components/PhotoViewer/FileInfo/RenderCaption.tsxindex dd7080f7b1..71bbf9233f 100644--- a/web/apps/photos/src/components/PhotoViewer/FileInfo/RenderCaption.tsx+++ b/web/apps/photos/src/components/PhotoViewer/FileInfo/RenderCaption.tsx@@ -1,9 +1,9 @@import log from "@/base/log";-import { EnteFile } from "@/media/file";import { FlexWrapper } from "@ente/shared/components/Container";import Close from "@mui/icons-material/Close";import Done from "@mui/icons-material/Done";import { Box, CircularProgress, IconButton, TextField } from "@mui/material";+import type { DisplayFile } from "components/PhotoFrame";import { Formik } from "formik";import { t } from "i18next";import { useState } from "react";@@ -23,7 +23,7 @@ export function RenderCaption({shouldDisableEdits,}: {shouldDisableEdits: boolean;- file: EnteFile;+ file: DisplayFile;scheduleUpdate: () => void;refreshPhotoswipe: () => void;}) {diff --git a/web/apps/photos/src/components/PhotoViewer/index.tsx b/web/apps/photos/src/components/PhotoViewer/index.tsxindex 1e36ac7e4d..85dce94eab 100644--- a/web/apps/photos/src/components/PhotoViewer/index.tsx+++ b/web/apps/photos/src/components/PhotoViewer/index.tsx@@ -5,11 +5,12 @@ import { Overlay } from "@/base/components/mui/Container";import { type ModalVisibilityProps } from "@/base/components/utils/modal";import { lowercaseExtension } from "@/base/file-name";import log from "@/base/log";-import type { LoadedLivePhotoSourceURL } from "@/media/file";import { fileLogID, type EnteFile } from "@/media/file";import { FileType } from "@/media/file-type";import { isHEICExtension, needsJPEGConversion } from "@/media/formats";-import downloadManager from "@/new/photos/services/download";+import downloadManager, {+ type LoadedLivePhotoSourceURL,+} from "@/new/photos/services/download";import { extractRawExif, parseExif } from "@/new/photos/services/exif";import { AppContext } from "@/new/photos/types/context";import { FlexWrapper } from "@ente/shared/components/Container";@@ -39,6 +40,7 @@ import {type ButtonProps,type CircularProgressProps,} from "@mui/material";+import type { DisplayFile } from "components/PhotoFrame";import { t } from "i18next";import { GalleryContext } from "pages/gallery";import Photoswipe from "photoswipe";@@ -343,7 +345,7 @@ function PhotoViewer(props: PhotoViewerProps) {setIsOwnFile(isOwnFile);}- function updateExif(file: EnteFile) {+ function updateExif(file: DisplayFile) {if (file.metadata.fileType === FileType.video) {setExif({key: file.src,@@ -366,15 +368,15 @@ function PhotoViewer(props: PhotoViewerProps) {checkExifAvailable(file);}- function updateShowConvertBtn(file: EnteFile) {+ function updateShowConvertBtn(file: DisplayFile) {setShowConvertButton(!!file.canForceConvert);}- function updateConversionFailedNotification(file: EnteFile) {+ function updateConversionFailedNotification(file: DisplayFile) {setConversionFailedNotificationOpen(file.conversionFailed);}- function updateIsSourceLoaded(file: EnteFile) {+ function updateIsSourceLoaded(file: DisplayFile) {setIsSourceLoaded(file.isSourceLoaded);}@@ -505,7 +507,7 @@ function PhotoViewer(props: PhotoViewerProps) {}handleCloseInfo();};- const isInFav = (file: EnteFile) => {+ const isInFav = (file: DisplayFile) => {const { favItemIds } = props;if (favItemIds && file) {return favItemIds.has(file.id);@@ -513,7 +515,7 @@ function PhotoViewer(props: PhotoViewerProps) {return false;};- const onFavClick = async (file: EnteFile) => {+ const onFavClick = async (file: DisplayFile) => {try {if (!file ||@@ -539,7 +541,7 @@ function PhotoViewer(props: PhotoViewerProps) {}};- const trashFile = async (file: EnteFile) => {+ const trashFile = async (file: DisplayFile) => {try {showLoadingBar();try {@@ -589,7 +591,7 @@ function PhotoViewer(props: PhotoViewerProps) {}};- const updateItems = (items: EnteFile[]) => {+ const updateItems = (items: DisplayFile[]) => {try {if (photoSwipe) {if (items.length === 0) {@@ -626,7 +628,7 @@ function PhotoViewer(props: PhotoViewerProps) {}};- const checkExifAvailable = async (enteFile: EnteFile) => {+ const checkExifAvailable = async (enteFile: DisplayFile) => {if (exifExtractionInProgress.current === enteFile.src) return;try {@@ -697,7 +699,7 @@ function PhotoViewer(props: PhotoViewerProps) {}};- const copyToClipboardHelper = async (file: EnteFile) => {+ const copyToClipboardHelper = async (file: DisplayFile) => {if (file && props.enableDownload && shouldShowCopyOption) {showLoadingBar();await copyFileToClipboard(file.src);diff --git a/web/apps/photos/src/components/pages/gallery/PreviewCard.tsx b/web/apps/photos/src/components/pages/gallery/PreviewCard.tsxindex 6817ce7b17..936152561e 100644--- a/web/apps/photos/src/components/pages/gallery/PreviewCard.tsx+++ b/web/apps/photos/src/components/pages/gallery/PreviewCard.tsx@@ -1,6 +1,5 @@import { Overlay } from "@/base/components/mui/Container";import log from "@/base/log";-import { EnteFile } from "@/media/file";import { FileType } from "@/media/file-type";import {GAP_BTW_TILES,@@ -17,6 +16,7 @@ import AlbumOutlined from "@mui/icons-material/AlbumOutlined";import Favorite from "@mui/icons-material/FavoriteRounded";import PlayCircleOutlineOutlinedIcon from "@mui/icons-material/PlayCircleOutlineOutlined";import { Tooltip, styled } from "@mui/material";+import type { DisplayFile } from "components/PhotoFrame";import i18n from "i18next";import { DeduplicateContext } from "pages/deduplicate";import { GalleryContext } from "pages/gallery";@@ -25,7 +25,7 @@ import { shouldShowAvatar } from "utils/file";import Avatar from "./Avatar";interface IProps {- file: EnteFile;+ file: DisplayFile;updateURL: (id: number, url: string) => void;onClick: () => void;selectable: boolean;diff --git a/web/packages/media/file.ts b/web/packages/media/file.tsindex 23cb4274be..9f07d250b5 100644--- a/web/packages/media/file.ts+++ b/web/packages/media/file.ts@@ -75,6 +75,7 @@ export interface EnteFile*/pubMagicMetadata?: FilePublicMagicMetadata;isTrashed?: boolean;+ deleteBy?: number;/*** The base64 encoded encryption key associated with this file.*@@ -82,52 +83,6 @@ export interface EnteFile* data (e.g., metadatum, thumbnail) for the file.*/key: string;- src?: string;- srcURLs?: SourceURLs;- msrc?: string;- html?: string;- w?: number;- h?: number;- title?: string;- deleteBy?: number;- isSourceLoaded?: boolean;- conversionFailed?: boolean;- canForceConvert?: boolean;-}--export interface LivePhotoSourceURL {- image: () => Promise<string | undefined>;- video: () => Promise<string | undefined>;-}--export interface LoadedLivePhotoSourceURL {- image: string;- video: string;-}--export interface SourceURLs {- url: string | LivePhotoSourceURL | LoadedLivePhotoSourceURL;- isOriginal: boolean;- isRenderable: boolean;- type: "normal" | "livePhoto";- /**- * `true` if there is potential conversion that can still be applied.- *- * See: [Note: Forcing conversion of playable videos]- */- canForceConvert?: boolean;- /**- * Best effort attempt at obtaining the MIME type.- *- * It will only be present for images generally, which is also the only- * scenario where it is needed currently (by the image editor).- *- * Known cases where it is missing:- *- * - Live photos (these have a different code path for obtaining the URL).- * - A video that is passes the isPlayable test in the browser.- */- mimeType?: string;}export interface TrashRequest {diff --git a/web/packages/new/photos/services/download.ts b/web/packages/new/photos/services/download.tsindex bf9c182156..2fcb7489f3 100644--- a/web/packages/new/photos/services/download.ts+++ b/web/packages/new/photos/services/download.ts@@ -16,12 +16,47 @@ import {renderableImageBlob,} from "@/gallery/utils/convert";import { retryAsyncOperation } from "@/gallery/utils/retry-async";-import type { EnteFile, LivePhotoSourceURL, SourceURLs } from "@/media/file";+import type { EnteFile } from "@/media/file";import { FileType } from "@/media/file-type";import { decodeLivePhoto } from "@/media/live-photo";import { CustomError } from "@ente/shared/error";import HTTPService from "@ente/shared/network/HTTPService";+export interface LivePhotoSourceURL {+ image: () => Promise<string | undefined>;+ video: () => Promise<string | undefined>;+}++export interface LoadedLivePhotoSourceURL {+ image: string;+ video: string;+}++export interface SourceURLs {+ url: string | LivePhotoSourceURL | LoadedLivePhotoSourceURL;+ isOriginal: boolean;+ isRenderable: boolean;+ type: "normal" | "livePhoto";+ /**+ * `true` if there is potential conversion that can still be applied.+ *+ * See: [Note: Forcing conversion of playable videos]+ */+ canForceConvert?: boolean;+ /**+ * Best effort attempt at obtaining the MIME type.+ *+ * It will only be present for images generally, which is also the only+ * scenario where it is needed currently (by the image editor).+ *+ * Known cases where it is missing:+ *+ * - Live photos (these have a different code path for obtaining the URL).+ * - A video that is passes the isPlayable test in the browser.+ */+ mimeType?: string;+}+export type OnDownloadProgress = (event: {loaded: number;total: number;