Disentangle

This commit is contained in:
Manav Rathi
2024-06-05 13:41:03 +05:30
parent e65ea1a8c5
commit c1134c9b0c
6 changed files with 15 additions and 34 deletions

View File

@@ -208,7 +208,7 @@ export default function App({ Component, pageProps }: AppProps) {
const initExport = async () => {
const token = getToken();
if (!token) return;
await DownloadManager.init(APPS.PHOTOS, { token });
await DownloadManager.init(token);
await resumeExportsIfNeeded();
};
initExport();

View File

@@ -1,6 +1,5 @@
import { fetchAndSaveFeatureFlagsIfNeeded } from "@/new/photos/services/feature-flags";
import log from "@/next/log";
import { APPS } from "@ente/shared/apps/constants";
import { CenteredFlex } from "@ente/shared/components/Container";
import EnteSpinner from "@ente/shared/components/EnteSpinner";
import { PHOTOS_PAGES as PAGES } from "@ente/shared/constants/pages";
@@ -347,7 +346,7 @@ export default function Gallery() {
if (!valid) {
return;
}
await downloadManager.init(APPS.PHOTOS, { token });
await downloadManager.init(token);
setupSelectAllKeyBoardShortcutHandler();
setActiveCollectionID(ALL_SECTION);
setIsFirstLoad(isFirstLogin());

View File

@@ -1,5 +1,4 @@
import log from "@/next/log";
import { APPS } from "@ente/shared/apps/constants";
import {
CenteredFlex,
SpaceBetweenFlex,
@@ -212,7 +211,7 @@ export default function PublicCollectionGallery() {
let redirectingToWebsite = false;
try {
const cryptoWorker = await ComlinkCryptoWorker.getInstance();
await downloadManager.init(APPS.ALBUMS);
await downloadManager.init();
url.current = window.location.href;
const currentURL = new URL(url.current);

View File

@@ -6,11 +6,10 @@ import { DownloadClient } from "services/download";
import { EnteFile } from "types/file";
export class PublicAlbumsDownloadClient implements DownloadClient {
constructor(
private token: string,
private passwordToken: string,
private timeout: number,
) {}
private token: string;
private passwordToken: string;
constructor(private timeout: number) {}
updateTokens(token: string, passwordToken: string) {
this.token = token;

View File

@@ -2,7 +2,6 @@ import { FILE_TYPE } from "@/media/file-type";
import { decodeLivePhoto } from "@/media/live-photo";
import { blobCache, type BlobCache } from "@/next/blob-cache";
import log from "@/next/log";
import { APPS } from "@ente/shared/apps/constants";
import ComlinkCryptoWorker from "@ente/shared/crypto";
import { DedicatedCryptoWorker } from "@ente/shared/crypto/internal/crypto.worker";
import { CustomError } from "@ente/shared/error";
@@ -81,15 +80,12 @@ class DownloadManagerImpl {
private progressUpdater: (value: Map<number, number>) => void = () => {};
async init(
app: APPS,
tokens?: { token: string; passwordToken?: string } | { token: string },
) {
async init(token?: string) {
if (this.ready) {
log.info("DownloadManager already initialized");
return;
}
this.downloadClient = createDownloadClient(app, tokens);
this.downloadClient = createDownloadClient(token);
try {
this.thumbnailCache = await blobCache("thumbs");
} catch (e) {
@@ -422,25 +418,14 @@ const DownloadManager = new DownloadManagerImpl();
export default DownloadManager;
function createDownloadClient(
app: APPS,
tokens?: { token: string; passwordToken?: string } | { token: string },
): DownloadClient {
const createDownloadClient = (token: string): DownloadClient => {
const timeout = 300000; // 5 minute
if (app === APPS.ALBUMS) {
if (!tokens) {
tokens = { token: undefined, passwordToken: undefined };
}
const { token, passwordToken } = tokens as {
token: string;
passwordToken: string;
};
return new PublicAlbumsDownloadClient(token, passwordToken, timeout);
} else {
const { token } = tokens;
if (token) {
return new PhotosDownloadClient(token, timeout);
} else {
return new PublicAlbumsDownloadClient(timeout);
}
}
};
async function getRenderableFileURL(
file: EnteFile,

View File

@@ -1,4 +1,3 @@
import { APPS } from "@ente/shared/apps/constants";
import { expose } from "comlink";
import downloadManager from "services/download";
import mlService from "services/machineLearning/machineLearningService";
@@ -20,7 +19,7 @@ export class DedicatedMLWorker {
}
public async sync(token: string, userID: number, userAgent: string) {
await downloadManager.init(APPS.PHOTOS, { token });
await downloadManager.init(token);
return mlService.sync(token, userID, userAgent);
}
}