Replace enum with TS type

This commit is contained in:
Manav Rathi 2024-04-12 14:41:33 +05:30
parent cd3ff6f878
commit 495ff99874
No known key found for this signature in database
5 changed files with 17 additions and 20 deletions

View file

@ -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) => {
>
<ImageCacheView
url={person.displayImageUrl}
cacheName={CACHES.FACE_CROPS}
cacheName="face-crops"
faceID={person.displayFaceId}
/>
</FaceChip>
@ -176,7 +175,7 @@ export function UnidentifiedFaces(props: {
<ImageCacheView
faceID={face.id}
url={face.crop?.imageUrl}
cacheName={CACHES.FACE_CROPS}
cacheName="face-crops"
/>
</FaceChip>
))}

View file

@ -5,7 +5,6 @@ import { DedicatedCryptoWorker } from "@ente/shared/crypto/internal/crypto.worke
import { 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()) {

View file

@ -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,

View file

@ -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 {

View file

@ -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)));
};