π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Merge branch 'refactor-download-manager' into refactor-in-memory-caching
Abhinav749427a432a3
diff --cc apps/photos/src/components/Collections/CollectionCard.tsxindex e4a1d2f0fb,1eec757058..3bee032b65--- a/apps/photos/src/components/Collections/CollectionCard.tsx+++ b/apps/photos/src/components/Collections/CollectionCard.tsx@@@ -1,5 -1,7 +1,5 @@@-import React from 'react';-import { GalleryContext } from 'pages/gallery';-import { useState, useContext, useEffect } from 'react';+import { useState, useEffect } from 'react';- import downloadManager from 'services/downloadManager';+ import downloadManager from 'services/download';import { EnteFile } from 'types/file';import { StaticThumbnail } from 'components/PlaceholderThumbnails';import { LoadingThumbnail } from 'components/PlaceholderThumbnails';diff --cc apps/photos/src/components/PhotoFrame.tsxindex 61dd802709,ddaa85d50b..a35cf126af--- a/apps/photos/src/components/PhotoFrame.tsx+++ b/apps/photos/src/components/PhotoFrame.tsx@@@ -3,20 -3,24 +3,23 @@@ import PreviewCard from './pages/gallerimport { useContext, useEffect, useState } from 'react';import { EnteFile } from 'types/file';import { styled } from '@mui/material';- import DownloadManager, { SourceURLs } from 'services/downloadManager';-import DownloadManager from 'services/download';++import DownloadManager, { SourceURLs } from 'services/download';import AutoSizer from 'react-virtualized-auto-sizer';import PhotoViewer from 'components/PhotoViewer';import { TRASH_SECTION } from 'constants/collection';import { updateFileMsrcProps, updateFileSrcProps } from 'utils/photoFrame';- import { PhotoList } from './PhotoList';-import { MergedSourceURL, SelectedState } from 'types/gallery';+import { SelectedState } from 'types/gallery';import { PublicCollectionGalleryContext } from 'utils/publicCollectionGallery';import { useRouter } from 'next/router';import { logError } from '@ente/shared/sentry';import { addLogLine } from '@ente/shared/logging';import PhotoSwipe from 'photoswipe';import useMemoSingleThreaded from '@ente/shared/hooks/useMemoSingleThreaded';-import { getPlayableVideo } from 'utils/file';import { FILE_TYPE } from 'constants/file';+ import { PHOTOS_PAGES } from '@ente/shared/constants/pages';+ import { PhotoList } from './PhotoList';+ import { DedupePhotoList } from './PhotoList/dedupe';+ import { Duplicate } from 'services/deduplicationService';const Container = styled('div')`display: block;diff --cc apps/photos/src/pages/shared-albums/index.tsxindex ca0ee46c18,d48625ad60..112f273e7d--- a/apps/photos/src/pages/shared-albums/index.tsx+++ b/apps/photos/src/pages/shared-albums/index.tsx@@@ -59,8 -59,11 +59,8 @@@ import OverflowMenu from '@ente/shared/import { OverflowMenuOption } from '@ente/shared/components/OverflowMenu/option';import { ENTE_WEBSITE_LINK } from '@ente/shared/constants/urls';import { APPS } from '@ente/shared/apps/constants';- import downloadManager from 'services/downloadManager';+ import downloadManager from 'services/download';-const defaultThumbStore = new Map();-const defaultFileStore = new Map();-export default function PublicCollectionGallery() {const token = useRef<string>(null);// passwordJWTToken refers to the jwt token which is used for album protected by password.diff --cc apps/photos/src/services/download/index.tsindex 54b62cd5e4,f9b719a008..9ffd454c10--- a/apps/photos/src/services/download/index.ts+++ b/apps/photos/src/services/download/index.ts@@@ -15,18 -15,12 +15,18 @@@ import { DedicatedCryptoWorker } from 'import { LimitedCache } from '@ente/shared/storage/cacheStorage/types';import { addLogLine } from '@ente/shared/logging';import { APPS } from '@ente/shared/apps/constants';- import { PhotosDownloadClient } from './downloadManagerClients/photos';- import { PublicAlbumsDownloadClient } from './downloadManagerClients/publicAlbums';+ import { PhotosDownloadClient } from './clients/photos';+ import { PublicAlbumsDownloadClient } from './clients/publicAlbums';export type SourceURLs = {- original: string[];- converted: string[];+ url:+ | {+ image: string;+ video: string;+ }+ | string;+ isOriginal: boolean;+ isRenderable: boolean;};export type OnDownloadProgress = (event: {@@@ -149,31 -165,20 +172,35 @@@ class DownloadManager}}- getFileForPreview = async (file: EnteFile): Promise<SourceURLs> => {+ getFileForPreview = async (+ file: EnteFile,+ forceConvert = false+ ): Promise<SourceURLs> => {try {+ if (!this.ready) {+ throw Error(CustomError.DOWNLOAD_MANAGER_NOT_READY);+ }- const getFilePromise = async () => {- const fileStream = await this.downloadFile(file);- const fileBlob = await new Response(fileStream).blob();- return await getRenderableFileURL(file, fileBlob);+ const getFileForPreviewPromise = async () => {+ const fileBlob = await new Response(+ await this.getFile(file, true)+ ).blob();+ const fileOriginalURL = URL.createObjectURL(fileBlob);++ const converted = await getRenderableFileURL(+ file,+ fileBlob,+ fileOriginalURL as string,+ forceConvert+ );+ return converted;};- if (!this.fileObjectURLPromises.get(file.id)) {- this.fileObjectURLPromises.set(file.id, getFilePromise());+ if (!this.fileConversionPromises.has(file.id)) {- const fileURLs =- getFileForPreviewPromise() as Promise<SourceURLs>;- this.fileConversionPromises.set(file.id, fileURLs);++ this.fileObjectURLPromises.set(++ file.id,++ getFileForPreviewPromise()++ );}- const fileURLs = await this.fileObjectURLPromises.get(file.id);+ const fileURLs = await this.fileConversionPromises.get(file.id);return fileURLs;} catch (e) {this.fileObjectURLPromises.delete(file.id);@@@ -182,42 -187,11 +209,45 @@@}};- getFile(file: EnteFile) {- if (!this.ready) {- throw Error(CustomError.DOWNLOAD_MANAGER_NOT_READY);+ async getFile(+ file: EnteFile,+ useCache = false+ ): Promise<ReadableStream<Uint8Array>> {+ try {++ if (!this.ready) {++ throw Error(CustomError.DOWNLOAD_MANAGER_NOT_READY);++ }+ if (!useCache) {+ return await this.downloadFile(file);+ }+ const getFilePromise = async (): Promise<SourceURLs> => {+ const fileStream = await this.downloadFile(file);+ const fileBlob = await new Response(fileStream).blob();+ return {+ url: URL.createObjectURL(fileBlob),+ isOriginal: true,+ isRenderable: false,+ };+ };++ if (this.fileObjectURLPromises.has(file.id)) {+ const fileURLs = await this.fileObjectURLPromises.get(file.id);+ if (fileURLs.isOriginal) {+ const fileStream = (await fetch(fileURLs.url as string))+ .body;+ return fileStream;+ } else {+ return await this.downloadFile(file);+ }+ } else {+ const fileURLs = getFilePromise();+ this.fileObjectURLPromises.set(file.id, fileURLs);+ }+ } catch (e) {+ this.fileObjectURLPromises.delete(file.id);+ logError(e, 'download manager getFile Failed');+ throw e;}- return this.downloadFile(file);}private async downloadFile(diff --cc apps/photos/src/utils/file/index.tsindex ca1ac22f54,39951578e7..7db1e63843--- a/apps/photos/src/utils/file/index.ts+++ b/apps/photos/src/utils/file/index.ts@@@ -10,7 -10,7 +10,7 @@@ import} from 'types/file';import { decodeLivePhoto } from 'services/livePhotoService';import { getFileType } from 'services/typeDetectionService';- import DownloadManager, { SourceURLs } from 'services/downloadManager';-import DownloadManager from 'services/download';++import DownloadManager, { SourceURLs } from 'services/download';import { logError } from '@ente/shared/sentry';import { User } from '@ente/shared/user/types';import { getData, LS_KEYS } from '@ente/shared/storage/localStorage';diff --cc apps/photos/src/utils/photoFrame/index.tsindex 0a303e3294,7637898f92..a6435fe5a6--- a/apps/photos/src/utils/photoFrame/index.ts+++ b/apps/photos/src/utils/photoFrame/index.ts@@@ -1,7 -1,7 +1,7 @@@import { FILE_TYPE } from 'constants/file';import { EnteFile } from 'types/file';-import { MergedSourceURL } from 'types/gallery';import { logError } from '@ente/shared/sentry';- import { SourceURLs } from 'services/downloadManager';++import { SourceURLs } from 'services/download';const WAIT_FOR_VIDEO_PLAYBACK = 1 * 1000;