Remove from the web side

This commit is contained in:
Manav Rathi 2024-03-22 17:38:24 +05:30
parent 3dbf82552d
commit 03bad54bce
No known key found for this signature in database
10 changed files with 7 additions and 165 deletions

View file

@ -1,24 +1,8 @@
import { LimitedCacheStorage } from "types/cache/index";
// import { ElectronCacheStorage } from 'services/electron/cache';
// import { runningInElectron, runningInWorker } from 'utils/common';
// import { WorkerElectronCacheStorageService } from 'services/workerElectronCache/service';
class cacheStorageFactory {
// workerElectronCacheStorageServiceInstance: WorkerElectronCacheStorageService;
getCacheStorage(): LimitedCacheStorage {
// if (runningInElectron()) {
// if (runningInWorker()) {
// if (!this.workerElectronCacheStorageServiceInstance) {
// // this.workerElectronCacheStorageServiceInstance =
// // new WorkerElectronCacheStorageService();
// }
// return this.workerElectronCacheStorageServiceInstance;
// } else {
// // return ElectronCacheStorage;
// }
// } else {
return transformBrowserCacheStorageToLimitedCacheStorage(caches);
// }
}
}

View file

@ -8,13 +8,3 @@ export interface LimitedCache {
put: (key: string, data: Response) => Promise<void>;
delete: (key: string) => Promise<boolean>;
}
export interface ProxiedLimitedCacheStorage {
open: (cacheName: string) => Promise<ProxiedWorkerLimitedCache>;
delete: (cacheName: string) => Promise<boolean>;
}
export interface ProxiedWorkerLimitedCache {
match: (key: string) => Promise<ArrayBuffer>;
put: (key: string, data: ArrayBuffer) => Promise<void>;
delete: (key: string) => Promise<boolean>;
}

View file

@ -57,8 +57,6 @@ export interface DownloadClient {
downloadFileStream: (file: EnteFile) => Promise<Response>;
}
const FILE_CACHE_LIMIT = 5 * 1024 * 1024 * 1024; // 5GB
class DownloadManagerImpl {
private ready: boolean = false;
private downloadClient: DownloadClient;
@ -565,7 +563,7 @@ async function openDiskFileCache() {
if (!isElectron()) {
throw Error(CustomError.NOT_AVAILABLE_ON_WEB);
}
return await CacheStorageService.open(CACHES.FILES, FILE_CACHE_LIMIT);
return await CacheStorageService.open(CACHES.FILES);
} catch (e) {
logError(e, "Failed to open file cache");
if (isInternalUser()) {

View file

@ -1,19 +1,11 @@
import { runningInWorker } from "@ente/shared/platform";
import { LimitedCache } from "@ente/shared/storage/cacheStorage/types";
import * as Comlink from "comlink";
import { wrap } from "comlink";
import { ElectronAPIsType } from "./types";
import {
ProxiedWorkerLimitedCache,
WorkerSafeElectronClient,
} from "./worker/client";
import { deserializeToResponse, serializeResponse } from "./worker/utils/proxy";
import { WorkerSafeElectronClient } from "./worker/client";
export interface LimitedElectronAPIs
extends Pick<
ElectronAPIsType,
"openDiskCache" | "deleteDiskCache" | "convertToJPEG" | "logToDisk"
> {}
extends Pick<ElectronAPIsType, "convertToJPEG" | "logToDisk"> {}
class WorkerSafeElectronServiceImpl implements LimitedElectronAPIs {
proxiedElectron:
@ -34,23 +26,6 @@ class WorkerSafeElectronServiceImpl implements LimitedElectronAPIs {
this.proxiedElectron = new WorkerSafeElectronClient();
}
}
async openDiskCache(cacheName: string, cacheLimitInBytes?: number) {
await this.ready;
const cache = await this.proxiedElectron.openDiskCache(
cacheName,
cacheLimitInBytes,
);
return {
match: transformMatch(cache.match.bind(cache)),
put: transformPut(cache.put.bind(cache)),
delete: cache.delete.bind(cache),
};
}
async deleteDiskCache(cacheName: string) {
await this.ready;
return await this.proxiedElectron.deleteDiskCache(cacheName);
}
async convertToJPEG(
inputFileData: Uint8Array,
@ -59,6 +34,7 @@ class WorkerSafeElectronServiceImpl implements LimitedElectronAPIs {
await this.ready;
return this.proxiedElectron.convertToJPEG(inputFileData, filename);
}
async logToDisk(message: string) {
await this.ready;
return this.proxiedElectron.logToDisk(message);
@ -66,19 +42,3 @@ class WorkerSafeElectronServiceImpl implements LimitedElectronAPIs {
}
export const WorkerSafeElectronService = new WorkerSafeElectronServiceImpl();
function transformMatch(
fn: ProxiedWorkerLimitedCache["match"],
): LimitedCache["match"] {
return async (key: string, options) => {
return deserializeToResponse(await fn(key, options));
};
}
function transformPut(
fn: ProxiedWorkerLimitedCache["put"],
): LimitedCache["put"] {
return async (key: string, data: Response) => {
fn(key, await serializeResponse(data));
};
}

View file

@ -1,4 +1,3 @@
import { LimitedCache } from "@ente/shared/storage/cacheStorage/types";
import { ElectronFile } from "@ente/shared/upload/types";
import { WatchMapping } from "@ente/shared/watchFolder/types";
@ -63,11 +62,6 @@ export interface ElectronAPIsType {
clearElectronStore: () => void;
setEncryptionKey: (encryptionKey: string) => Promise<void>;
getEncryptionKey: () => Promise<string>;
openDiskCache: (
cacheName: string,
cacheLimitInBytes?: number,
) => Promise<LimitedCache>;
deleteDiskCache: (cacheName: string) => Promise<boolean>;
logToDisk: (msg: string) => void;
convertToJPEG: (
fileData: Uint8Array,

View file

@ -1,46 +1,14 @@
import ElectronAPIs from "@ente/shared/electron";
import { LimitedCache } from "@ente/shared/storage/cacheStorage/types";
import * as Comlink from "comlink";
import { deserializeToResponse, serializeResponse } from "./utils/proxy";
export interface ProxiedLimitedElectronAPIs {
openDiskCache: (
cacheName: string,
cacheLimitInBytes?: number,
) => Promise<ProxiedWorkerLimitedCache>;
deleteDiskCache: (cacheName: string) => Promise<boolean>;
convertToJPEG: (
inputFileData: Uint8Array,
filename: string,
) => Promise<Uint8Array>;
logToDisk: (message: string) => void;
}
export interface ProxiedWorkerLimitedCache {
match: (
key: string,
options?: { sizeInBytes?: number },
) => Promise<ArrayBuffer>;
put: (key: string, data: ArrayBuffer) => Promise<void>;
delete: (key: string) => Promise<boolean>;
}
export class WorkerSafeElectronClient implements ProxiedLimitedElectronAPIs {
async openDiskCache(cacheName: string, cacheLimitInBytes?: number) {
const cache = await ElectronAPIs.openDiskCache(
cacheName,
cacheLimitInBytes,
);
return Comlink.proxy({
match: Comlink.proxy(transformMatch(cache.match.bind(cache))),
put: Comlink.proxy(transformPut(cache.put.bind(cache))),
delete: Comlink.proxy(cache.delete.bind(cache)),
});
}
async deleteDiskCache(cacheName: string) {
return await ElectronAPIs.deleteDiskCache(cacheName);
}
async convertToJPEG(
inputFileData: Uint8Array,
filename: string,
@ -51,19 +19,3 @@ export class WorkerSafeElectronClient implements ProxiedLimitedElectronAPIs {
return ElectronAPIs.logToDisk(message);
}
}
function transformMatch(
fn: LimitedCache["match"],
): ProxiedWorkerLimitedCache["match"] {
return async (key: string, options: { sizeInBytes?: number }) => {
return serializeResponse(await fn(key, options));
};
}
function transformPut(
fn: LimitedCache["put"],
): ProxiedWorkerLimitedCache["put"] {
return async (key: string, data: ArrayBuffer) => {
fn(key, deserializeToResponse(data));
};
}

View file

@ -1,11 +0,0 @@
export function serializeResponse(response: Response) {
if (response) {
return response.arrayBuffer();
}
}
export function deserializeToResponse(arrayBuffer: ArrayBuffer) {
if (arrayBuffer) {
return new Response(arrayBuffer);
}
}

View file

@ -1,11 +0,0 @@
import * as Comlink from "comlink";
// didn't work kept for reference, so that can try to make it work later in future hopefully
export function setupResponseObjectTransferHandler() {
const transferHandler: Comlink.TransferHandler<Response, ArrayBuffer> = {
canHandle: (obj): obj is Response => obj instanceof Response,
serialize: (response: Response) => [response.arrayBuffer() as any, []],
deserialize: (arrayBuffer: ArrayBuffer) => new Response(arrayBuffer),
};
return Comlink.transferHandlers.set("RESPONSE", transferHandler);
}

View file

@ -1,5 +1,6 @@
export enum CACHES {
THUMBS = "thumbs",
FACE_CROPS = "face-crops",
// Desktop app only
FILES = "files",
}

View file

@ -1,23 +1,8 @@
import { WorkerSafeElectronService } from "@ente/shared/electron/service";
import { runningInElectron } from "@ente/shared/platform";
import { LimitedCacheStorage } from "./types";
class cacheStorageFactory {
getCacheStorage(): LimitedCacheStorage {
if (runningInElectron()) {
return {
open(cacheName, cacheLimitInBytes?: number) {
return WorkerSafeElectronService.openDiskCache(
cacheName,
cacheLimitInBytes,
);
},
delete(cacheName) {
return WorkerSafeElectronService.deleteDiskCache(cacheName);
},
};
} else {
return transformBrowserCacheStorageToLimitedCacheStorage(caches);
}
return transformBrowserCacheStorageToLimitedCacheStorage(caches);
}
}