Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

update to use the new download manager

Abhinave36ba1345a57
diff --git a/apps/photos/src/components/Collections/CollectionCard.tsx b/apps/photos/src/components/Collections/CollectionCard.tsx
index d7c48b384c..62c4efb6a6 100644
--- a/apps/photos/src/components/Collections/CollectionCard.tsx
+++ b/apps/photos/src/components/Collections/CollectionCard.tsx
@@ -41,7 +41,7 @@ export default function CollectionCard(props: {
if (isScrolling) {
return;
}
- const url = await downloadManager.getThumbnail(file);
+ const url = await downloadManager.getThumbnailForPreview(file);
thumbsStore.set(file.id, url);
}
setCoverImageURL(thumbsStore.get(file.id));
diff --git a/apps/photos/src/components/PhotoFrame.tsx b/apps/photos/src/components/PhotoFrame.tsx
index de0a032361..118faea309 100644
--- a/apps/photos/src/components/PhotoFrame.tsx
+++ b/apps/photos/src/components/PhotoFrame.tsx
@@ -10,7 +10,6 @@ import { TRASH_SECTION } from 'constants/collection';
import { updateFileMsrcProps, updateFileSrcProps } from 'utils/photoFrame';
import { PhotoList } from './PhotoList';
import { MergedSourceURL, SelectedState } from 'types/gallery';
-import PublicCollectionDownloadManager from 'services/publicCollectionDownloadManager';
import { PublicCollectionGalleryContext } from 'utils/publicCollectionGallery';
import { useRouter } from 'next/router';
import { logError } from '@ente/shared/sentry';
@@ -383,30 +382,7 @@ const PhotoFrame = ({
if (!item.msrc) {
addLogLine(`[${item.id}] doesn't have thumbnail`);
try {
- let url: string;
- if (thumbsStore.has(item.id)) {
- addLogLine(
- `[${item.id}] gallery context cache hit, using cached thumb`
- );
- url = thumbsStore.get(item.id);
- } else {
- addLogLine(
- `[${item.id}] gallery context cache miss, calling downloadManager to get thumb`
- );
- if (
- publicCollectionGalleryContext.accessedThroughSharedURL
- ) {
- url =
- await PublicCollectionDownloadManager.getThumbnail(
- item,
- publicCollectionGalleryContext.token,
- publicCollectionGalleryContext.passwordToken
- );
- } else {
- url = await DownloadManager.getThumbnail(item);
- }
- thumbsStore.set(item.id, url);
- }
+ const url = await DownloadManager.getThumbnailForPreview(item);
updateURL(index)(item.id, url);
try {
addLogLine(
@@ -457,21 +433,9 @@ const PhotoFrame = ({
addLogLine(
`[${item.id}] gallery context cache miss, calling downloadManager to get file`
);
- let downloadedURL: {
- original: string[];
- converted: string[];
- };
- if (publicCollectionGalleryContext.accessedThroughSharedURL) {
- downloadedURL =
- await PublicCollectionDownloadManager.getFile(
- item,
- publicCollectionGalleryContext.token,
- publicCollectionGalleryContext.passwordToken,
- true
- );
- } else {
- downloadedURL = await DownloadManager.getFile(item, true);
- }
+ const downloadedURL = await DownloadManager.getFileForPreview(
+ item
+ );
const mergedURL: MergedSourceURL = {
original: downloadedURL.original.join(','),
converted: downloadedURL.converted.join(','),
diff --git a/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/index.tsx b/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/index.tsx
index 5d320028e9..5c22889619 100644
--- a/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/index.tsx
+++ b/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/index.tsx
@@ -210,9 +210,8 @@ const ImageEditorOverlay = (props: IProps) => {
const ctx = canvasRef.current.getContext('2d');
ctx.imageSmoothingEnabled = false;
if (!fileURL) {
- const { converted } = await downloadManager.getFile(
- props.file,
- true
+ const { converted } = await downloadManager.getFileForPreview(
+ props.file
);
img.src = converted[0];
setFileURL(converted[0]);
diff --git a/apps/photos/src/components/PhotoViewer/index.tsx b/apps/photos/src/components/PhotoViewer/index.tsx
index b0756d3f3a..4428890973 100644
--- a/apps/photos/src/components/PhotoViewer/index.tsx
+++ b/apps/photos/src/components/PhotoViewer/index.tsx
@@ -50,7 +50,6 @@ import { getFileType } from 'services/typeDetectionService';
import { ConversionFailedNotification } from './styledComponents/ConversionFailedNotification';
import { GalleryContext } from 'pages/gallery';
import downloadManager from 'services/downloadManager';
-import publicCollectionDownloadManager from 'services/publicCollectionDownloadManager';
import CircularProgressWithLabel from './styledComponents/CircularProgressWithLabel';
import EnteSpinner from '@ente/shared/components/EnteSpinner';
import AlbumOutlined from '@mui/icons-material/AlbumOutlined';
@@ -138,13 +137,7 @@ function PhotoViewer(props: Iprops) {
const [showEditButton, setShowEditButton] = useState(false);
useEffect(() => {
- if (publicCollectionGalleryContext.accessedThroughSharedURL) {
- publicCollectionDownloadManager.setProgressUpdater(
- setFileDownloadProgress
- );
- } else {
- downloadManager.setProgressUpdater(setFileDownloadProgress);
- }
+ downloadManager.setProgressUpdater(setFileDownloadProgress);
}, []);
useEffect(() => {
@@ -589,12 +582,7 @@ function PhotoViewer(props: Iprops) {
if (file && props.enableDownload) {
appContext.startLoading();
try {
- await downloadFile(
- file,
- publicCollectionGalleryContext.accessedThroughSharedURL,
- publicCollectionGalleryContext.token,
- publicCollectionGalleryContext.passwordToken
- );
+ await downloadFile(file);
} catch (e) {
// do nothing
}
diff --git a/apps/photos/src/components/pages/gallery/PreviewCard.tsx b/apps/photos/src/components/pages/gallery/PreviewCard.tsx
index cbdae568ca..3d45330df4 100644
--- a/apps/photos/src/components/pages/gallery/PreviewCard.tsx
+++ b/apps/photos/src/components/pages/gallery/PreviewCard.tsx
@@ -6,8 +6,6 @@ import DownloadManager from 'services/downloadManager';
import useLongPress from '@ente/shared/hooks/useLongPress';
import { GalleryContext } from 'pages/gallery';
import { GAP_BTW_TILES, IMAGE_CONTAINER_MAX_WIDTH } from 'constants/gallery';
-import { PublicCollectionGalleryContext } from 'utils/publicCollectionGallery';
-import PublicCollectionDownloadManager from 'services/publicCollectionDownloadManager';
import { DeduplicateContext } from 'pages/deduplicate';
import { logError } from '@ente/shared/sentry';
import { Overlay } from '@ente/shared/components/Container';
@@ -217,15 +215,8 @@ const Cont = styled('div')<{ disabled: boolean }>`
export default function PreviewCard(props: IProps) {
const galleryContext = useContext(GalleryContext);
- const publicCollectionGalleryContext = useContext(
- PublicCollectionGalleryContext
- );
const deduplicateContext = useContext(DeduplicateContext);
- const thumbsStore = publicCollectionGalleryContext?.accessedThroughSharedURL
- ? publicCollectionGalleryContext.thumbs
- : galleryContext.thumbs;
-
const {
file,
onClick,
@@ -256,44 +247,9 @@ export default function PreviewCard(props: IProps) {
if (file.msrc) {
return;
}
- let url: string;
- // check in in-memory cache
- if (thumbsStore.has(file.id)) {
- url = thumbsStore.get(file.id);
- } else {
- // check in cacheStorage
- if (
- publicCollectionGalleryContext.accessedThroughSharedURL
- ) {
- url =
- await PublicCollectionDownloadManager.getCachedThumbnail(
- file
- );
- } else {
- url = await DownloadManager.getCachedThumbnail(file);
- }
- if (url) {
- thumbsStore.set(file.id, url);
- } else {
- // download thumbnail
- if (props.showPlaceholder) {
- return;
- }
- if (
- publicCollectionGalleryContext.accessedThroughSharedURL
- ) {
- url =
- await PublicCollectionDownloadManager.getThumbnail(
- file,
- publicCollectionGalleryContext.token,
- publicCollectionGalleryContext.passwordToken
- );
- } else {
- url = await DownloadManager.getThumbnail(file);
- }
- thumbsStore.set(file.id, url);
- }
- }
+ const url: string =
+ await DownloadManager.getThumbnailForPreview(file);
+
if (!isMounted.current) {
return;
}
diff --git a/apps/photos/src/pages/shared-albums/index.tsx b/apps/photos/src/pages/shared-albums/index.tsx
index 22b37fc818..4a521a0ace 100644
--- a/apps/photos/src/pages/shared-albums/index.tsx
+++ b/apps/photos/src/pages/shared-albums/index.tsx
@@ -218,12 +218,7 @@ export default function PublicCollectionGallery() {
appContext.startLoading();
for (const file of publicFiles) {
try {
- await downloadFile(
- file,
- true,
- token.current,
- passwordJWTToken.current
- );
+ await downloadFile(file);
} catch (e) {
// do nothing
}
diff --git a/apps/photos/src/services/clipService.ts b/apps/photos/src/services/clipService.ts
index dd2dc9ee09..0493d475d3 100644
--- a/apps/photos/src/services/clipService.ts
+++ b/apps/photos/src/services/clipService.ts
@@ -17,7 +17,6 @@ import { getPersonalFiles } from 'utils/file';
import { FILE_TYPE } from 'constants/file';
import ComlinkCryptoWorker from '@ente/shared/crypto';
import { Embedding, Model } from 'types/embedding';
-import { getToken } from '@ente/shared/storage/localStorage/helpers';
const CLIP_EMBEDDING_LENGTH = 512;
@@ -294,19 +293,11 @@ class ClipServiceImpl {
};
private extractFileClipImageEmbedding = async (file: EnteFile) => {
- const token = getToken();
- if (!token) {
- return;
- }
- let thumb: Uint8Array;
- const thumbURL = await downloadManager.getCachedThumbnail(file);
- if (thumbURL) {
- thumb = await fetch(thumbURL)
- .then((response) => response.arrayBuffer())
- .then((buffer) => new Uint8Array(buffer));
- } else {
- thumb = await downloadManager.downloadThumb(token, file);
- }
+ const thumb = await downloadManager
+ .getThumbnail(file)
+ .then((fileBlob) =>
+ fileBlob.arrayBuffer().then((buffer) => new Uint8Array(buffer))
+ );
const embedding = await ElectronAPIs.computeImageEmbedding(thumb);
return embedding;
};
diff --git a/apps/photos/src/services/downloadManager.ts b/apps/photos/src/services/downloadManager.ts
index d6f5d2724f..cb0cf87a5a 100644
--- a/apps/photos/src/services/downloadManager.ts
+++ b/apps/photos/src/services/downloadManager.ts
@@ -1,7 +1,6 @@
import {
generateStreamFromArrayBuffer,
getRenderableFileURL,
- createTypedObjectURL,
} from 'utils/file';
import { EnteFile } from 'types/file';
@@ -48,8 +47,8 @@ class DownloadManager {
private thumbnailCache: LimitedCache;
private cryptoWorker: Remote<DedicatedCryptoWorker>;
- private fileObjectURLPromise = new Map<string, Promise<SourceURLs>>();
- private thumbnailObjectURLPromise = new Map<number, Promise<string>>();
+ private fileObjectURLPromises = new Map<number, Promise<SourceURLs>>();
+ private thumbnailObjectURLPromises = new Map<number, Promise<string>>();
private fileDownloadProgress = new Map<number, number>();
@@ -87,100 +86,95 @@ class DownloadManager {
this.progressUpdater = progressUpdater;
}
- public async getInMemoryCachedThumbnailURL(fileID: number) {
- return this.thumbnailObjectURLPromise.get(fileID);
- }
-
- public async getInMemoryCachedFileURL(fileID: number) {
- return this.fileObjectURLPromise.get(fileID.toString());
- }
-
- public async getCachedThumbnail(fileID: number) {
+ private async getCachedThumbnail(fileID: number) {
try {
const cacheResp: Response = await this.thumbnailCache?.match(
fileID.toString()
);
-
- if (cacheResp) {
- return URL.createObjectURL(await cacheResp.blob());
- }
- return null;
+ return await cacheResp.blob();
} catch (e) {
logError(e, 'failed to get cached thumbnail');
throw e;
}
}
+ private downloadThumb = async (file: EnteFile) => {
+ const encrypted = await this.downloadClient.downloadThumbnail(file);
+ const decrypted = await this.cryptoWorker.decryptThumbnail(
+ encrypted,
+ await this.cryptoWorker.fromB64(file.thumbnail.decryptionHeader),
+ file.key
+ );
+ return decrypted;
+ };
+
public async getThumbnail(file: EnteFile) {
try {
- if (!this.thumbnailObjectURLPromise.has(file.id)) {
- const downloadPromise = async () => {
- const cachedThumb = await this.getCachedThumbnail(file.id);
- if (cachedThumb) {
- return cachedThumb;
- }
- const thumb = await this.downloadThumb(file);
- const thumbBlob = new Blob([thumb]);
-
- this.thumbnailCache
- ?.put(file.id.toString(), new Response(thumbBlob))
- .catch((e) => {
- logError(e, 'cache put failed');
- // TODO: handle storage full exception.
- });
- return URL.createObjectURL(thumbBlob);
- };
- this.thumbnailObjectURLPromise.set(file.id, downloadPromise());
+ const cachedThumb = await this.getCachedThumbnail(file.id);
+ if (cachedThumb) {
+ return cachedThumb;
}
-
- return await this.thumbnailObjectURLPromise.get(file.id);
+ const thumb = await this.downloadThumb(file);
+ const thumbBlob = new Blob([thumb]);
+
+ this.thumbnailCache
+ ?.put(file.id.toString(), new Response(thumbBlob))
+ .catch((e) => {
+ logError(e, 'cache put failed');
+ // TODO: handle storage full exception.
+ });
+ return thumbBlob;
} catch (e) {
- this.thumbnailObjectURLPromise.delete(file.id);
logError(e, 'get DownloadManager preview Failed');
throw e;
}
}
- downloadThumb = async (file: EnteFile) => {
- const encrypted = await this.downloadClient.downloadThumbnail(file);
-
- const decrypted = await this.cryptoWorker.decryptThumbnail(
- encrypted,
- await this.cryptoWorker.fromB64(file.thumbnail.decryptionHeader),
- file.key
- );
- return decrypted;
- };
+ public async getThumbnailForPreview(file: EnteFile) {
+ try {
+ if (!this.thumbnailObjectURLPromises.has(file.id)) {
+ await this.thumbnailObjectURLPromises.get(file.id);
+ const thumbBlobPromise = this.getThumbnail(file);
+ const thumbURLPromise = thumbBlobPromise.then((blob) =>
+ URL.createObjectURL(blob)
+ );
+ this.thumbnailObjectURLPromises.set(file.id, thumbURLPromise);
+ }
+ return await this.thumbnailObjectURLPromises.get(file.id);
+ } catch (e) {
+ this.thumbnailObjectURLPromises.delete(file.id);
+ logError(e, 'get DownloadManager preview Failed');
+ throw e;
+ }
+ }
- getFile = async (file: EnteFile, forPreview = false) => {
- const fileKey = forPreview ? `${file.id}_preview` : `${file.id}`;
+ getFileForPreview = async (file: EnteFile): Promise<SourceURLs> => {
try {
const getFilePromise = async () => {
const fileStream = await this.downloadFile(file);
const fileBlob = await new Response(fileStream).blob();
- if (forPreview) {
- return await getRenderableFileURL(file, fileBlob);
- } else {
- const fileURL = await createTypedObjectURL(
- fileBlob,
- file.metadata.title
- );
- return { converted: [fileURL], original: [fileURL] };
- }
+ return await getRenderableFileURL(file, fileBlob);
};
- if (!this.fileObjectURLPromise.get(fileKey)) {
- this.fileObjectURLPromise.set(fileKey, getFilePromise());
+ if (!this.fileObjectURLPromises.get(file.id)) {
+ const fileURLs = getFilePromise() as Promise<SourceURLs>;
+ this.fileObjectURLPromises.set(file.id, fileURLs);
}
- const fileURLs = await this.fileObjectURLPromise.get(fileKey);
+ const fileURLs = await this.fileObjectURLPromises.get(file.id);
return fileURLs;
} catch (e) {
- this.fileObjectURLPromise.delete(fileKey);
+ this.fileObjectURLPromises.delete(file.id);
logError(e, 'download manager Failed to get File');
throw e;
}
};
- async downloadFile(file: EnteFile) {
+ getFile(file: EnteFile) {
+ return this.downloadFile(file);
+ }
+
+ private async downloadFile(
+ file: EnteFile
+ ): Promise<ReadableStream<Uint8Array>> {
try {
const onDownloadProgress = this.trackDownloadProgress(
file.id,
diff --git a/apps/photos/src/services/export/index.ts b/apps/photos/src/services/export/index.ts
index cc31106703..05f39455e8 100644
--- a/apps/photos/src/services/export/index.ts
+++ b/apps/photos/src/services/export/index.ts
@@ -1061,7 +1061,7 @@ class ExportService {
): Promise<void> {
try {
const fileUID = getExportRecordFileUID(file);
- const originalFileStream = await downloadManager.downloadFile(file);
+ const originalFileStream = await downloadManager.getFile(file);
if (!this.fileReader) {
this.fileReader = new FileReader();
}
diff --git a/apps/photos/src/services/export/migration.ts b/apps/photos/src/services/export/migration.ts
index 842e09cde8..f0d5df62a4 100644
--- a/apps/photos/src/services/export/migration.ts
+++ b/apps/photos/src/services/export/migration.ts
@@ -343,7 +343,7 @@ async function getFileExportNamesFromExportedFiles(
For Live Photos we need to download the file to get the image and video name
*/
if (file.metadata.fileType === FILE_TYPE.LIVE_PHOTO) {
- const fileStream = await downloadManager.downloadFile(file);
+ const fileStream = await downloadManager.getFile(file);
const fileBlob = await new Response(fileStream).blob();
const livePhoto = await decodeLivePhoto(file, fileBlob);
const imageExportName = getUniqueFileExportNameForMigration(
diff --git a/apps/photos/src/services/machineLearning/peopleService.ts b/apps/photos/src/services/machineLearning/peopleService.ts
index 59dc5d4b92..e89e51e298 100644
--- a/apps/photos/src/services/machineLearning/peopleService.ts
+++ b/apps/photos/src/services/machineLearning/peopleService.ts
@@ -64,10 +64,7 @@ class PeopleService {
if (personFace && !personFace.crop?.imageUrl) {
const file = await getLocalFile(personFace.fileId);
- const imageBitmap = await getOriginalImageBitmap(
- file,
- syncContext.token
- );
+ const imageBitmap = await getOriginalImageBitmap(file);
await FaceService.saveFaceCrop(
imageBitmap,
personFace,
diff --git a/apps/photos/src/services/machineLearning/readerService.ts b/apps/photos/src/services/machineLearning/readerService.ts
index 499eef3557..7b6534bc0c 100644
--- a/apps/photos/src/services/machineLearning/readerService.ts
+++ b/apps/photos/src/services/machineLearning/readerService.ts
@@ -36,15 +36,11 @@ class ReaderService {
)
) {
fileContext.imageBitmap = await getOriginalImageBitmap(
- fileContext.enteFile,
- syncContext.token,
- await syncContext.getEnteWorker(fileContext.enteFile.id)
+ fileContext.enteFile
);
} else {
fileContext.imageBitmap = await getThumbnailImageBitmap(
- fileContext.enteFile,
- syncContext.token,
- await syncContext.getEnteWorker(fileContext.enteFile.id)
+ fileContext.enteFile
);
}
diff --git a/apps/photos/src/services/migrateThumbnailService.ts b/apps/photos/src/services/migrateThumbnailService.ts
index 06830ff749..a405473397 100644
--- a/apps/photos/src/services/migrateThumbnailService.ts
+++ b/apps/photos/src/services/migrateThumbnailService.ts
@@ -44,7 +44,6 @@ export async function replaceThumbnail(
) {
let completedWithError = false;
try {
- const token = getToken();
const cryptoWorker = await ComlinkCryptoWorker.getInstance();
const files = await getLocalFiles();
const trashFiles = await getLocalTrashedFiles();
@@ -69,8 +68,7 @@ export async function replaceThumbnail(
current: idx,
total: largeThumbnailFiles.length,
});
- const originalThumbnail = await downloadManager.downloadThumb(
- token,
+ const originalThumbnail = await downloadManager.getThumbnail(
file
);
const dummyImageFile = new File(
diff --git a/apps/photos/src/services/updateCreationTimeWithExif.ts b/apps/photos/src/services/updateCreationTimeWithExif.ts
index a4945afc5d..a18f861294 100644
--- a/apps/photos/src/services/updateCreationTimeWithExif.ts
+++ b/apps/photos/src/services/updateCreationTimeWithExif.ts
@@ -2,7 +2,6 @@ import { FIX_OPTIONS } from 'components/FixCreationTime';
import { SetProgressTracker } from 'components/FixLargeThumbnail';
import {
changeFileCreationTime,
- getFileFromURL,
updateExistingFilePubMetadata,
} from 'utils/file';
import { logError } from '@ente/shared/sentry';
@@ -43,9 +42,12 @@ export async function updateCreationTimeWithExif(
if (file.metadata.fileType !== FILE_TYPE.IMAGE) {
continue;
}
- const fileURL = (await downloadManager.getFile(file))
- .original[0];
- const fileObject = await getFileFromURL(fileURL);
+ const fileStream = await downloadManager.getFile(file);
+ const fileBlob = await new Response(fileStream).blob();
+ const fileObject = new File(
+ [fileBlob],
+ file.metadata.title
+ );
const fileTypeInfo = await getFileType(fileObject);
const exifData = await getParsedExifData(
fileObject,
diff --git a/apps/photos/src/utils/file/index.ts b/apps/photos/src/utils/file/index.ts
index 935e35cfc1..8007f93361 100644
--- a/apps/photos/src/utils/file/index.ts
+++ b/apps/photos/src/utils/file/index.ts
@@ -24,7 +24,6 @@ import {
SUPPORTED_RAW_FORMATS,
RAW_FORMATS,
} from 'constants/file';
-import PublicCollectionDownloadManager from 'services/publicCollectionDownloadManager';
import heicConversionService from 'services/heicConversionService';
import * as ffmpegService from 'services/ffmpeg/ffmpegService';
import { VISIBILITY_STATE } from 'types/magicMetadata';
@@ -86,44 +85,12 @@ export async function getUpdatedEXIFFileForDownload(
}
}
-export async function downloadFile(
- file: EnteFile,
- accessedThroughSharedURL: boolean,
- token?: string,
- passwordToken?: string
-) {
+export async function downloadFile(file: EnteFile) {
try {
- let fileBlob: Blob;
const fileReader = new FileReader();
- if (accessedThroughSharedURL) {
- const fileURL =
- await PublicCollectionDownloadManager.getCachedOriginalFile(
- file
- )[0];
- if (!fileURL) {
- fileBlob = await new Response(
- await PublicCollectionDownloadManager.downloadFile(
- token,
- passwordToken,
- file
- )
- ).blob();
- } else {
- fileBlob = await (await fetch(fileURL)).blob();
- }
- } else {
- const fileURL = await DownloadManager.getCachedOriginalFile(
- file
- )[0];
- if (!fileURL) {
- fileBlob = await new Response(
- await DownloadManager.downloadFile(file)
- ).blob();
- } else {
- fileBlob = await (await fetch(fileURL)).blob();
- }
- }
-
+ let fileBlob = await new Response(
+ await DownloadManager.getFile(file)
+ ).blob();
if (file.metadata.fileType === FILE_TYPE.LIVE_PHOTO) {
const livePhoto = await decodeLivePhoto(file, fileBlob);
const image = new File([livePhoto.image], livePhoto.imageNameTitle);
@@ -627,7 +594,7 @@ export async function downloadFiles(
if (progressBarUpdater?.isCancelled()) {
return;
}
- await downloadFile(file, false);
+ await downloadFile(file);
progressBarUpdater?.increaseSuccess();
} catch (e) {
logError(e, 'download fail for file');
@@ -665,13 +632,7 @@ export async function downloadFileDesktop(
file: EnteFile,
downloadPath: string
) {
- let fileStream: ReadableStream<Uint8Array>;
- const fileURL = await DownloadManager.getCachedOriginalFile(file)[0];
- if (!fileURL) {
- fileStream = await DownloadManager.downloadFile(file);
- } else {
- fileStream = await fetch(fileURL).then((res) => res.body);
- }
+ const fileStream = await DownloadManager.getFile(file);
const updatedFileStream = await getUpdatedEXIFFileForDownload(
fileReader,
file,
diff --git a/apps/photos/src/utils/machineLearning/index.ts b/apps/photos/src/utils/machineLearning/index.ts
index 065f8c00b8..a0b94d2e2d 100644
--- a/apps/photos/src/utils/machineLearning/index.ts
+++ b/apps/photos/src/utils/machineLearning/index.ts
@@ -1,9 +1,6 @@
import { NormalizedFace } from 'blazeface-back';
import * as tf from '@tensorflow/tfjs-core';
-import {
- BLAZEFACE_FACE_SIZE,
- ML_SYNC_DOWNLOAD_TIMEOUT_MS,
-} from 'constants/mlConfig';
+import { BLAZEFACE_FACE_SIZE } from 'constants/mlConfig';
import { euclidean } from 'hdbscan';
import PQueue from 'p-queue';
import DownloadManager from 'services/downloadManager';
@@ -40,8 +37,6 @@ import { CACHES } from '@ente/shared/storage/cacheStorage/constants';
import { FILE_TYPE } from 'constants/file';
import { decodeLivePhoto } from 'services/livePhotoService';
import { addLogLine } from '@ente/shared/logging';
-import { Remote } from 'comlink';
-import { DedicatedCryptoWorker } from '@ente/shared/crypto/internal/crypto.worker';
export function f32Average(descriptors: Float32Array[]) {
if (descriptors.length < 1) {
@@ -229,7 +224,7 @@ export async function getFaceImage(
file = await getLocalFile(face.fileId);
}
- const imageBitmap = await getOriginalImageBitmap(file, token);
+ const imageBitmap = await getOriginalImageBitmap(file);
const faceImageBitmap = ibExtractFaceImage(
imageBitmap,
face.alignment,
@@ -325,39 +320,18 @@ export async function getImageBlobBitmap(blob: Blob): Promise<ImageBitmap> {
// return new TFImageBitmap(undefined, tfImage);
// }
-async function getOriginalFile(
- file: EnteFile,
- token: string,
- enteWorker?: Remote<DedicatedCryptoWorker>,
- queue?: PQueue
-) {
+async function getOriginalFile(file: EnteFile, queue?: PQueue) {
let fileStream;
if (queue) {
- fileStream = await queue.add(() =>
- DownloadManager.downloadFile(
- file,
- token,
- enteWorker,
- ML_SYNC_DOWNLOAD_TIMEOUT_MS
- )
- );
+ fileStream = await queue.add(() => DownloadManager.getFile(file));
} else {
- fileStream = await DownloadManager.downloadFile(
- file,
- token,
- enteWorker
- );
+ fileStream = await DownloadManager.getFile(file);
}
return new Response(fileStream).blob();
}
-async function getOriginalConvertedFile(
- file: EnteFile,
- token: string,
- enteWorker?: Remote<DedicatedCryptoWorker>,
- queue?: PQueue
-) {
- const fileBlob = await getOriginalFile(file, token, enteWorker, queue);
+async function getOriginalConvertedFile(file: EnteFile, queue?: PQueue) {
+ const fileBlob = await getOriginalFile(file, queue);
if (file.metadata.fileType === FILE_TYPE.IMAGE) {
return await getRenderableImage(file.metadata.title, fileBlob);
} else {
@@ -371,8 +345,6 @@ async function getOriginalConvertedFile(
export async function getOriginalImageBitmap(
file: EnteFile,
- token: string,
- enteWorker?: Remote<DedicatedCryptoWorker>,
queue?: PQueue,
useCache: boolean = false
) {
@@ -380,37 +352,21 @@ export async function getOriginalImageBitmap(
if (useCache) {
fileBlob = await cached(CACHES.FILES, file.id.toString(), () => {
- return getOriginalConvertedFile(file, token, enteWorker, queue);
+ return getOriginalConvertedFile(file, queue);
});
} else {
- fileBlob = await getOriginalConvertedFile(
- file,
- token,
- enteWorker,
- queue
- );
+ fileBlob = await getOriginalConvertedFile(file, queue);
}
addLogLine('[MLService] Got file: ', file.id.toString());
return getImageBlobBitmap(fileBlob);
}
-export async function getThumbnailImageBitmap(
- file: EnteFile,
- token: string,
- enteWorker?: Remote<DedicatedCryptoWorker>
-) {
- const fileUrl = await DownloadManager.getThumbnail(
- file,
- token,
- enteWorker,
- ML_SYNC_DOWNLOAD_TIMEOUT_MS
- );
+export async function getThumbnailImageBitmap(file: EnteFile) {
+ const thumbBlob = await DownloadManager.getThumbnail(file);
addLogLine('[MLService] Got thumbnail: ', file.id.toString());
- const thumbFile = await fetch(fileUrl);
-
- return getImageBlobBitmap(await thumbFile.blob());
+ return getImageBlobBitmap(thumbBlob);
}
export async function getLocalFileImageBitmap(