π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
do cache size validation on the node layer
Abhinav35566c9785cb
diff --git a/apps/photos/src/services/download/index.ts b/apps/photos/src/services/download/index.tsindex a25f1ab67b..671dc40728 100644--- a/apps/photos/src/services/download/index.ts+++ b/apps/photos/src/services/download/index.ts@@ -1,7 +1,6 @@import {generateStreamFromArrayBuffer,getRenderableFileURL,- getStreamLength,} from 'utils/file';import { EnteFile } from 'types/file';@@ -136,25 +135,12 @@ class DownloadManagerImpl {return null;}const cacheResp: Response = await this.diskFileCache?.match(- file.id.toString()+ file.id.toString(),+ { sizeInBytes: file.info?.fileSize });if (!cacheResp) {return null;}- // check if cached file size is same as file size- const fileSize = file.info?.fileSize;- if (!fileSize) {- return cacheResp;- }- const contentLength = await getStreamLength(cacheResp.clone().body);- if (file.info?.fileSize === contentLength) {- return cacheResp;- } else {- addLogLine(- `mismatch in file size, delete the cache, {actualSize: ${contentLength}, expectedSize: ${fileSize}`- );- this.diskFileCache?.delete(file.id.toString());- }} catch (e) {logError(e, 'failed to get cached thumbnail');throw e;diff --git a/apps/photos/src/utils/file/index.ts b/apps/photos/src/utils/file/index.tsindex a572feb06c..3cf6ed39d4 100644--- a/apps/photos/src/utils/file/index.ts+++ b/apps/photos/src/utils/file/index.ts@@ -958,18 +958,3 @@ const getFileObjectURL = (: null;return convertedURL;};--export const getStreamLength = async (stream: ReadableStream<Uint8Array>) => {- const reader = stream.getReader();- let length = 0;-- // eslint-disable-next-line no-constant-condition- while (true) {- const { done, value } = await reader.read();- if (done) {- break;- }- length += value.length;- }- return length;-};diff --git a/packages/shared/electron/service.ts b/packages/shared/electron/service.tsindex ef91319178..abbd031954 100644--- a/packages/shared/electron/service.ts+++ b/packages/shared/electron/service.ts@@ -73,8 +73,8 @@ export const WorkerSafeElectronService = new WorkerSafeElectronServiceImpl();function transformMatch(fn: ProxiedWorkerLimitedCache['match']): LimitedCache['match'] {- return async (key: string) => {- return deserializeToResponse(await fn(key));+ return async (key: string, options) => {+ return deserializeToResponse(await fn(key, options));};}diff --git a/packages/shared/electron/worker/client.ts b/packages/shared/electron/worker/client.tsindex 2593a5f18d..f16a9e0e54 100644--- a/packages/shared/electron/worker/client.ts+++ b/packages/shared/electron/worker/client.ts@@ -16,7 +16,10 @@ export interface ProxiedLimitedElectronAPIs {) => Promise<Uint8Array>;}export interface ProxiedWorkerLimitedCache {- match: (key: string) => Promise<ArrayBuffer>;+ match: (+ key: string,+ options?: { sizeInBytes?: number }+ ) => Promise<ArrayBuffer>;put: (key: string, data: ArrayBuffer) => Promise<void>;delete: (key: string) => Promise<boolean>;}@@ -53,8 +56,8 @@ export class WorkerSafeElectronClient implements ProxiedLimitedElectronAPIs {function transformMatch(fn: LimitedCache['match']): ProxiedWorkerLimitedCache['match'] {- return async (key: string) => {- return serializeResponse(await fn(key));+ return async (key: string, options: { sizeInBytes?: number }) => {+ return serializeResponse(await fn(key, options));};}diff --git a/packages/shared/storage/cacheStorage/types.ts b/packages/shared/storage/cacheStorage/types.tsindex c19fc05c37..dc87a70d58 100644--- a/packages/shared/storage/cacheStorage/types.ts+++ b/packages/shared/storage/cacheStorage/types.ts@@ -7,7 +7,10 @@ export interface LimitedCacheStorage {}export interface LimitedCache {- match: (key: string) => Promise<Response>;+ match: (+ key: string,+ options?: { sizeInBytes?: number }+ ) => Promise<Response>;put: (key: string, data: Response) => Promise<void>;delete: (key: string) => Promise<boolean>;}