π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Replace enum with TS type
Manav Rathi495ff99874b3
diff --git a/web/apps/photos/src/components/MachineLearning/PeopleList.tsx b/web/apps/photos/src/components/MachineLearning/PeopleList.tsxindex dc5f0fd435..c28b5790da 100644--- a/web/apps/photos/src/components/MachineLearning/PeopleList.tsx+++ b/web/apps/photos/src/components/MachineLearning/PeopleList.tsx@@ -1,5 +1,4 @@import log from "@/next/log";-import { CACHES } from "@ente/shared/storage/cache";import { styled } from "@mui/material";import { Legend } from "components/PhotoViewer/styledComponents/Legend";import { t } from "i18next";@@ -65,7 +64,7 @@ export const PeopleList = React.memo((props: PeopleListProps) => {><ImageCacheViewurl={person.displayImageUrl}- cacheName={CACHES.FACE_CROPS}+ cacheName="face-crops"faceID={person.displayFaceId}/></FaceChip>@@ -176,7 +175,7 @@ export function UnidentifiedFaces(props: {<ImageCacheViewfaceID={face.id}url={face.crop?.imageUrl}- cacheName={CACHES.FACE_CROPS}+ cacheName="face-crops"/></FaceChip>))}diff --git a/web/apps/photos/src/services/download/index.ts b/web/apps/photos/src/services/download/index.tsindex 64930989ac..1c9919fbee 100644--- a/web/apps/photos/src/services/download/index.ts+++ b/web/apps/photos/src/services/download/index.ts@@ -5,7 +5,6 @@ import { DedicatedCryptoWorker } from "@ente/shared/crypto/internal/crypto.workeimport { CustomError } from "@ente/shared/error";import { Events, eventBus } from "@ente/shared/events";import {- CACHES,CacheStorageService,type LimitedCache,} from "@ente/shared/storage/cache";@@ -518,7 +517,7 @@ export default DownloadManager;async function openThumbnailCache() {try {- return await CacheStorageService.open(CACHES.THUMBS);+ return await CacheStorageService.open("thumbs");} catch (e) {log.error("Failed to open thumbnail cache", e);if (isInternalUser()) {@@ -534,7 +533,7 @@ async function openDiskFileCache() {if (!isElectron()) {throw Error(CustomError.NOT_AVAILABLE_ON_WEB);}- return await CacheStorageService.open(CACHES.FILES);+ return await CacheStorageService.open("files");} catch (e) {log.error("Failed to open file cache", e);if (isInternalUser()) {diff --git a/web/apps/photos/src/utils/machineLearning/faceCrop.ts b/web/apps/photos/src/utils/machineLearning/faceCrop.tsindex e681443263..177b2a8ec1 100644--- a/web/apps/photos/src/utils/machineLearning/faceCrop.ts+++ b/web/apps/photos/src/utils/machineLearning/faceCrop.ts@@ -1,4 +1,4 @@-import { CACHES, CacheStorageService } from "@ente/shared/storage/cache";+import { CacheStorageService } from "@ente/shared/storage/cache";import { BlobOptions } from "types/image";import {FaceAlignment,@@ -54,7 +54,7 @@ async function storeFaceCropForBlob() {const faceCropUrl = `/${faceId}`;const faceCropResponse = new Response(faceCropBlob);- const faceCropCache = await CacheStorageService.open(CACHES.FACE_CROPS);+ const faceCropCache = await CacheStorageService.open("face-crops");await faceCropCache.put(faceCropUrl, faceCropResponse);return {imageUrl: faceCropUrl,diff --git a/web/apps/photos/src/utils/machineLearning/index.ts b/web/apps/photos/src/utils/machineLearning/index.tsindex 0157f66c1c..95e1018c9c 100644--- a/web/apps/photos/src/utils/machineLearning/index.ts+++ b/web/apps/photos/src/utils/machineLearning/index.ts@@ -1,5 +1,5 @@import log from "@/next/log";-import { CACHES, cached } from "@ente/shared/storage/cache";+import { cached } from "@ente/shared/storage/cache";import { FILE_TYPE } from "constants/file";import PQueue from "p-queue";import DownloadManager from "services/download";@@ -151,7 +151,7 @@ export async function getOriginalImageBitmap(let fileBlob;if (useCache) {- fileBlob = await cached(CACHES.FILES, file.id.toString(), () => {+ fileBlob = await cached("files", file.id.toString(), () => {return getOriginalConvertedFile(file, queue);});} else {diff --git a/web/packages/shared/storage/cache.ts b/web/packages/shared/storage/cache.tsindex c863590872..be135c1b92 100644--- a/web/packages/shared/storage/cache.ts+++ b/web/packages/shared/storage/cache.ts@@ -1,9 +1,12 @@-export enum CACHES {- THUMBS = "thumbs",- FACE_CROPS = "face-crops",+const cacheNames = [+ "thumbs",+ "face-crops",// Desktop app only- FILES = "files",-}+ "files",+] as const;++/** Namespaces into which our caches data is divided */+export type CacheName = (typeof cacheNames)[number];interface LimitedCacheStorage {open: (cacheName: string) => Promise<LimitedCache>;@@ -75,9 +78,5 @@ export async function cached(* Meant for use during logout, to reset the state of the user's account.*/export const clearCaches = async () => {- await Promise.all([- caches.delete(CACHES.THUMBS),- caches.delete(CACHES.FACE_CROPS),- caches.delete(CACHES.FILES),- ]);+ await Promise.all(cacheNames.map((name) => caches.delete(name)));};