Introduce idb

This commit is contained in:
Manav Rathi
2024-05-28 15:04:33 +05:30
parent 126727a9cc
commit f5947a0c4a
3 changed files with 35 additions and 11 deletions

View File

@@ -20,6 +20,8 @@ import type { FaceIndex } from "./types";
* In tandem, these serve as the underlying storage for the functions exposed by
* this file.
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const openFaceDB = () => {};
/**
* Save the given {@link faceIndex} locally.
@@ -58,3 +60,10 @@ export const addFileEntry = (fileID: string) => {};
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export const markIndexingFailed = (fileID: string) => {};
/**
* Clear any data stored by the face module.
*
* Meant to be called during logout.
*/
export const clearFaceData = () => {};

View File

@@ -161,11 +161,16 @@ some cases.
- [heic-convert](https://github.com/catdad-experiments/heic-convert) is used
for converting HEIC files (which browsers don't natively support) into JPEG.
## Processing
## General
- [comlink](https://github.com/GoogleChromeLabs/comlink) provides a minimal
layer on top of Web Workers to make them more easier to use.
- [idb](https://github.com/jakearchibald/idb) provides a promise API over the
browser-native IndexedDB APIs.
> For more details about IDB and its role, see [storage.md](storage.md).
## Photos app specific
- [react-dropzone](https://github.com/react-dropzone/react-dropzone/) is a

View File

@@ -1,9 +1,15 @@
# Storage
## Session Storage
Data tied to the browser tab's lifetime.
We store the user's encryption key here.
## Local Storage
Data in the local storage is persisted even after the user closes the tab (or
the browser itself). This is in contrast with session storage, where the data is
Data in the local storage is persisted even after the user closes the tab, or
the browser itself. This is in contrast with session storage, where the data is
cleared when the browser tab is closed.
The data in local storage is tied to the Document's origin (scheme + host).
@@ -15,19 +21,23 @@ Some things that get stored here are:
- Various user preferences
## Session Storage
## IndexedDB
Data tied to the browser tab's lifetime.
IndexedDB is a transactional NoSQL store provided by browsers. It has quite
large storage limits, and data is stored per origin (and remains persistent
across tab restarts).
We store the user's encryption key here.
Older code used the LocalForage library for storing things in Indexed DB. This
library falls back to localStorage in case Indexed DB storage is not available.
## Indexed DB
Newer code uses the idb library which provides a promise API over the IndexedDB,
but otherwise does not introduce any new abstractions.
We use the LocalForage library for storing things in Indexed DB. This library
falls back to localStorage in case Indexed DB storage is not available.
For more details, see:
- https://web.dev/articles/indexeddb
- https://github.com/jakearchibald/idb
Indexed DB allows for larger sizes than local/session storage, and is generally
meant for larger, tabular data.
## OPFS