Skip to content

armgit / ente

Public Imported from GitHub
0

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

Move

Manav Rathibffaf65ec5d6
diff --git a/web/apps/photos/src/components/FixCreationTime.tsx b/web/apps/photos/src/components/FixCreationTime.tsx
index b060d33d6c..c30bd4b258 100644
--- a/web/apps/photos/src/components/FixCreationTime.tsx
+++ b/web/apps/photos/src/components/FixCreationTime.tsx
@@ -1,6 +1,7 @@
import { FocusVisibleButton } from "@/base/components/mui/FocusVisibleButton";
import type { ModalVisibilityProps } from "@/base/components/utils/modal";
import log from "@/base/log";
+import { downloadManager } from "@/gallery/services/download";
import { fileLogID, type EnteFile } from "@/media/file";
import {
decryptPublicMagicMetadata,
@@ -10,7 +11,6 @@ import {
} from "@/media/file-metadata";
import { FileType } from "@/media/file-type";
import { PhotoDateTimePicker } from "@/new/photos/components/PhotoDateTimePicker";
-import downloadManager from "@/new/photos/services/download";
import { extractExifDates } from "@/new/photos/services/exif";
import {
Box,
diff --git a/web/apps/photos/src/components/PhotoFrame.tsx b/web/apps/photos/src/components/PhotoFrame.tsx
index db889a169c..55271c0367 100644
--- a/web/apps/photos/src/components/PhotoFrame.tsx
+++ b/web/apps/photos/src/components/PhotoFrame.tsx
@@ -3,10 +3,11 @@ 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, {
+import {
+ downloadManager,
type LivePhotoSourceURL,
type SourceURLs,
-} from "@/new/photos/services/download";
+} from "@/gallery/services/download";
import { PHOTOS_PAGES } from "@ente/shared/constants/pages";
import useMemoSingleThreaded from "@ente/shared/hooks/useMemoSingleThreaded";
import { styled } from "@mui/material";
@@ -364,7 +365,7 @@ const PhotoFrame = ({
thumbFetching[item.id] = true;
// URL will always be defined (unless an error is thrown) since
// we are not passing the `cachedOnly` option.
- const url = await DownloadManager.renderableThumbnailURL(item)!;
+ const url = await downloadManager.renderableThumbnailURL(item)!;
updateThumb(instance, index, item, url, false);
} catch (e) {
log.error("getSlideData failed get msrc url failed", e);
@@ -389,7 +390,7 @@ const PhotoFrame = ({
try {
log.info(`[${item.id}] new file src request`);
fetching[item.id] = true;
- const srcURLs = await DownloadManager.getFileForPreview(item);
+ const srcURLs = await downloadManager.getFileForPreview(item);
if (item.metadata.fileType === FileType.livePhoto) {
const srcImgURL = srcURLs.url as LivePhotoSourceURL;
const imageURL = await srcImgURL.image();
@@ -515,7 +516,7 @@ const PhotoFrame = ({
);
fetching[item.id] = true;
- const srcURL = await DownloadManager.getFileForPreview(item, {
+ const srcURL = await downloadManager.getFileForPreview(item, {
forceConvert: true,
});
diff --git a/web/apps/photos/src/components/PhotoViewer/ImageEditorOverlay.tsx b/web/apps/photos/src/components/PhotoViewer/ImageEditorOverlay.tsx
index 432df774d4..a619278563 100644
--- a/web/apps/photos/src/components/PhotoViewer/ImageEditorOverlay.tsx
+++ b/web/apps/photos/src/components/PhotoViewer/ImageEditorOverlay.tsx
@@ -8,9 +8,9 @@ import { SidebarDrawer } from "@/base/components/mui/SidebarDrawer";
import { nameAndExtension } from "@/base/file-name";
import log from "@/base/log";
import { downloadAndRevokeObjectURL } from "@/base/utils/web";
+import { downloadManager } from "@/gallery/services/download";
import { EnteFile } from "@/media/file";
import { photosDialogZIndex } from "@/new/photos/components/utils/z-index";
-import downloadManager from "@/new/photos/services/download";
import { AppContext } from "@/new/photos/types/context";
import {
CenteredFlex,
diff --git a/web/apps/photos/src/components/PhotoViewer/index.tsx b/web/apps/photos/src/components/PhotoViewer/index.tsx
index 25a498d9e9..bb1cf97e3d 100644
--- a/web/apps/photos/src/components/PhotoViewer/index.tsx
+++ b/web/apps/photos/src/components/PhotoViewer/index.tsx
@@ -5,12 +5,13 @@ 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 {
+ downloadManager,
+ type LoadedLivePhotoSourceURL,
+} from "@/gallery/services/download";
import { fileLogID, type EnteFile } from "@/media/file";
import { FileType } from "@/media/file-type";
import { isHEICExtension, needsJPEGConversion } from "@/media/formats";
-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";
diff --git a/web/apps/photos/src/components/pages/gallery/PreviewCard.tsx b/web/apps/photos/src/components/pages/gallery/PreviewCard.tsx
index a84709b010..bd0200bc2c 100644
--- a/web/apps/photos/src/components/pages/gallery/PreviewCard.tsx
+++ b/web/apps/photos/src/components/pages/gallery/PreviewCard.tsx
@@ -1,5 +1,6 @@
import { Overlay } from "@/base/components/mui/Container";
import log from "@/base/log";
+import { downloadManager } from "@/gallery/services/download";
import { FileType } from "@/media/file-type";
import {
GAP_BTW_TILES,
@@ -10,7 +11,6 @@ import {
StaticThumbnail,
} from "@/new/photos/components/PlaceholderThumbnails";
import { TRASH_SECTION } from "@/new/photos/services/collection";
-import DownloadManager from "@/new/photos/services/download";
import useLongPress from "@ente/shared/hooks/useLongPress";
import AlbumOutlined from "@mui/icons-material/AlbumOutlined";
import Favorite from "@mui/icons-material/FavoriteRounded";
@@ -274,7 +274,7 @@ export default function PreviewCard(props: IProps) {
return;
}
const url: string =
- await DownloadManager.renderableThumbnailURL(
+ await downloadManager.renderableThumbnailURL(
file,
props.showPlaceholder,
);
diff --git a/web/apps/photos/src/pages/shared-albums.tsx b/web/apps/photos/src/pages/shared-albums.tsx
index 05de541503..67d4bab9f3 100644
--- a/web/apps/photos/src/pages/shared-albums.tsx
+++ b/web/apps/photos/src/pages/shared-albums.tsx
@@ -9,6 +9,7 @@ import {
} from "@/base/components/utils/hooks";
import { sharedCryptoWorker } from "@/base/crypto";
import log from "@/base/log";
+import { downloadManager } from "@/gallery/services/download";
import { updateShouldDisableCFUploadProxy } from "@/gallery/upload";
import type { Collection } from "@/media/collection";
import { type EnteFile, mergeMetadata } from "@/media/file";
@@ -20,7 +21,6 @@ import {
ALL_SECTION,
isHiddenCollection,
} from "@/new/photos/services/collection";
-import downloadManager from "@/new/photos/services/download";
import { sortFiles } from "@/new/photos/services/files";
import { useAppContext } from "@/new/photos/types/context";
import {
diff --git a/web/apps/photos/src/services/export/index.ts b/web/apps/photos/src/services/export/index.ts
index 78cec8c197..b310115450 100644
--- a/web/apps/photos/src/services/export/index.ts
+++ b/web/apps/photos/src/services/export/index.ts
@@ -1,5 +1,6 @@
import { ensureElectron } from "@/base/electron";
import log from "@/base/log";
+import { downloadManager } from "@/gallery/services/download";
import { writeStream } from "@/gallery/utils/native-stream";
import type { Collection } from "@/media/collection";
import { mergeMetadata, type EnteFile } from "@/media/file";
@@ -14,7 +15,6 @@ import {
createCollectionNameByID,
getCollectionUserFacingName,
} from "@/new/photos/services/collection";
-import downloadManager from "@/new/photos/services/download";
import {
exportMetadataDirectoryName,
exportTrashDirectoryName,
diff --git a/web/apps/photos/src/services/export/migration.ts b/web/apps/photos/src/services/export/migration.ts
index 1578085566..a29ef68ce5 100644
--- a/web/apps/photos/src/services/export/migration.ts
+++ b/web/apps/photos/src/services/export/migration.ts
@@ -1,11 +1,11 @@
import { ensureElectron } from "@/base/electron";
import { nameAndExtension } from "@/base/file-name";
import log from "@/base/log";
+import { downloadManager } from "@/gallery/services/download";
import type { Collection } from "@/media/collection";
import { type EnteFile, mergeMetadata } from "@/media/file";
import { FileType } from "@/media/file-type";
import { decodeLivePhoto } from "@/media/live-photo";
-import downloadManager from "@/new/photos/services/download";
import { exportMetadataDirectoryName } from "@/new/photos/services/export";
import { getAllLocalFiles } from "@/new/photos/services/files";
import {
diff --git a/web/apps/photos/src/services/logout.ts b/web/apps/photos/src/services/logout.ts
index 12ddc6bf23..18b14e400a 100644
--- a/web/apps/photos/src/services/logout.ts
+++ b/web/apps/photos/src/services/logout.ts
@@ -3,8 +3,8 @@ import {
logoutClearStateAgain,
} from "@/accounts/services/logout";
import log from "@/base/log";
+import { downloadManager } from "@/gallery/services/download";
import { resetUploadState } from "@/gallery/upload";
-import DownloadManager from "@/new/photos/services/download";
import { logoutML, terminateMLWorker } from "@/new/photos/services/ml";
import { logoutSearch } from "@/new/photos/services/search";
import { logoutSettings } from "@/new/photos/services/settings";
@@ -30,7 +30,7 @@ export const photosLogout = async () => {
try {
await terminateMLWorker();
} catch (e) {
- ignoreError("ml/worker", e);
+ ignoreError("ML/worker", e);
}
// - Remote logout and clear state
@@ -44,31 +44,31 @@ export const photosLogout = async () => {
try {
logoutSettings();
} catch (e) {
- ignoreError("settings", e);
+ ignoreError("Settings", e);
}
try {
logoutUserDetails();
} catch (e) {
- ignoreError("userDetails", e);
+ ignoreError("User details", e);
}
try {
resetUploadState();
} catch (e) {
- ignoreError("upload", e);
+ ignoreError("Upload", e);
}
try {
- DownloadManager.logout();
+ downloadManager.logout();
} catch (e) {
- ignoreError("download", e);
+ ignoreError("Download", e);
}
try {
logoutSearch();
} catch (e) {
- ignoreError("search", e);
+ ignoreError("Search", e);
}
// - Desktop
@@ -84,13 +84,13 @@ export const photosLogout = async () => {
try {
exportService.disableContinuousExport();
} catch (e) {
- ignoreError("export", e);
+ ignoreError("Export", e);
}
try {
await electron.logout();
} catch (e) {
- ignoreError("electron", e);
+ ignoreError("Electron", e);
}
}
diff --git a/web/apps/photos/src/utils/file/index.ts b/web/apps/photos/src/utils/file/index.ts
index ce5740039f..34a12fb98d 100644
--- a/web/apps/photos/src/utils/file/index.ts
+++ b/web/apps/photos/src/utils/file/index.ts
@@ -2,6 +2,7 @@ import { sharedCryptoWorker } from "@/base/crypto";
import log from "@/base/log";
import { type Electron } from "@/base/types/ipc";
import { downloadAndRevokeObjectURL } from "@/base/utils/web";
+import { downloadManager } from "@/gallery/services/download";
import { detectFileTypeInfo } from "@/gallery/utils/detect-type";
import { writeStream } from "@/gallery/utils/native-stream";
import {
@@ -17,7 +18,6 @@ import {
import { ItemVisibility } from "@/media/file-metadata";
import { FileType } from "@/media/file-type";
import { decodeLivePhoto } from "@/media/live-photo";
-import DownloadManager from "@/new/photos/services/download";
import {
isArchivedFile,
updateMagicMetadata,
@@ -56,7 +56,7 @@ export enum FILE_OPS_TYPE {
export async function downloadFile(file: EnteFile) {
try {
- let fileBlob = await DownloadManager.fileBlob(file);
+ let fileBlob = await downloadManager.fileBlob(file);
if (file.metadata.fileType === FileType.livePhoto) {
const { imageFileName, imageData, videoFileName, videoData } =
await decodeLivePhoto(file.metadata.title, fileBlob);
@@ -390,7 +390,7 @@ async function downloadFileDesktop(
) {
const fs = electron.fs;
- const stream = await DownloadManager.fileStream(file);
+ const stream = await downloadManager.fileStream(file);
if (file.metadata.fileType === FileType.livePhoto) {
const fileBlob = await new Response(stream).blob();
diff --git a/web/packages/new/photos/services/download.ts b/web/packages/gallery/services/download.ts
similarity index 97%
rename from web/packages/new/photos/services/download.ts
rename to web/packages/gallery/services/download.ts
index bd109577a2..f53348afac 100644
--- a/web/packages/new/photos/services/download.ts
+++ b/web/packages/gallery/services/download.ts
@@ -55,7 +55,15 @@ export interface SourceURLs {
mimeType?: string;
}
-class DownloadManagerImpl {
+/**
+ * A class that tracks the state of in-progress downloads and conversions,
+ * including caching them for subsequent retrieval if appropriate.
+ *
+ * External code can use it via its singleton instance, {@link downloadManager}.
+ * The class will initialize itself on first use, however {@link logout} should
+ * be called on logout to reset its internal state.
+ */
+class DownloadManager {
/**
* Credentials that should be used to download files when we're in the
* context of the public albums app.
@@ -121,6 +129,9 @@ class DownloadManagerImpl {
}
}
+ /**
+ * Reset the internal state of the download manager.
+ */
logout() {
this.publicAlbumsCredentials = undefined;
this.thumbnailURLPromises.clear();
@@ -480,9 +491,10 @@ class DownloadManagerImpl {
}
}
-const DownloadManager = new DownloadManagerImpl();
-
-export default DownloadManager;
+/**
+ * Singleton instance of {@link DownloadManager}.
+ */
+export const downloadManager = new DownloadManager();
async function getRenderableFileURL(
file: EnteFile,
@@ -540,6 +552,8 @@ async function getRenderableFileURL(
}
// TODO: Can we remove this non-null assertion and reflect it in the types?
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
+ // @ts-ignore
return {
url: url!,
type,
diff --git a/web/packages/new/photos/components/Tiles.tsx b/web/packages/new/photos/components/Tiles.tsx
index 18bf6a7aa1..a6a44d5da5 100644
--- a/web/packages/new/photos/components/Tiles.tsx
+++ b/web/packages/new/photos/components/Tiles.tsx
@@ -1,9 +1,9 @@
+import { downloadManager } from "@/gallery/services/download";
import { type EnteFile } from "@/media/file";
import {
LoadingThumbnail,
StaticThumbnail,
} from "@/new/photos/components/PlaceholderThumbnails";
-import downloadManager from "@/new/photos/services/download";
import { styled } from "@mui/material";
import React, { useEffect, useState } from "react";
import { faceCrop } from "../services/ml";
diff --git a/web/packages/new/photos/services/ml/blob.ts b/web/packages/new/photos/services/ml/blob.ts
index 2bf7b024ab..b64036bc34 100644
--- a/web/packages/new/photos/services/ml/blob.ts
+++ b/web/packages/new/photos/services/ml/blob.ts
@@ -1,11 +1,11 @@
import { basename } from "@/base/file-name";
import type { ElectronMLWorker } from "@/base/types/ipc";
+import { downloadManager } from "@/gallery/services/download";
import { renderableImageBlob } from "@/gallery/utils/convert";
import { readStream } from "@/gallery/utils/native-stream";
import type { EnteFile } from "@/media/file";
import { FileType } from "@/media/file-type";
import { decodeLivePhoto } from "@/media/live-photo";
-import DownloadManager from "../download";
import type { UploadItem } from "../upload/types";
/**
@@ -91,7 +91,7 @@ const fetchRenderableUploadItemBlob = async (
) => {
const fileType = file.metadata.fileType;
if (fileType == FileType.video) {
- const thumbnailData = await DownloadManager.thumbnailData(file);
+ const thumbnailData = await downloadManager.thumbnailData(file);
return new Blob([thumbnailData!]);
} else {
const blob = await readNonVideoUploadItem(uploadItem, electron);
@@ -146,11 +146,11 @@ export const fetchRenderableEnteFileBlob = async (
): Promise<Blob> => {
const fileType = file.metadata.fileType;
if (fileType == FileType.video) {
- const thumbnailData = await DownloadManager.thumbnailData(file);
+ const thumbnailData = await downloadManager.thumbnailData(file);
return new Blob([thumbnailData!]);
}
- const originalFileBlob = await DownloadManager.fileBlob(file);
+ const originalFileBlob = await downloadManager.fileBlob(file);
if (fileType == FileType.livePhoto) {
const { imageFileName, imageData } = await decodeLivePhoto(