π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Inline local storage calls
Manav Rathif10f751a2f03
diff --git a/web/docs/storage.md b/web/docs/storage.mdnew file mode 100644index 0000000000..8f072684bf--- /dev/null+++ b/web/docs/storage.md@@ -0,0 +1,16 @@+# Storage++## 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+cleared when the browser tab is closed.++The data in local storage is tied to the Document's origin (scheme + host).++## Session Storage++## Indexed DB++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.diff --git a/web/packages/utils/env.ts b/web/packages/next/env.tssimilarity index 100%rename from web/packages/utils/env.tsrename to web/packages/next/env.tsdiff --git a/web/packages/next/hello.ts b/web/packages/next/hello.tsdeleted file mode 100644index 6e26a0ea88..0000000000--- a/web/packages/next/hello.ts+++ /dev/null@@ -1,4 +0,0 @@-/** Howdy! */-export const sayNamaste = () => {- console.log("Namaste, world");-};diff --git a/web/packages/next/i18n.ts b/web/packages/next/i18n.tsindex 9f0f2a3970..3f51d5c101 100644--- a/web/packages/next/i18n.ts+++ b/web/packages/next/i18n.ts@@ -1,9 +1,4 @@-import { isDevBuild } from "@/utils/env";-import {- getLSString,- removeLSString,- setLSString,-} from "@/utils/local-storage";+import { isDevBuild } from "@/next/env";import { logError } from "@/utils/logging";import { includes } from "@/utils/type-guards";import { getUserLocales } from "get-user-locale";@@ -119,8 +114,8 @@ export const setupI18n = async () => {* If it finds a locale stored in the old format, it also updates the saved* value and returns it in the new format.*/-const savedLocaleStringMigratingIfNeeded = () => {- const ls = getLSString("locale");+const savedLocaleStringMigratingIfNeeded = (): SupportedLocale | undefined => {+ const ls = localStorage.getItem("locale");// An older version of our code had stored only the language code, not the// full locale. Migrate these to the new locale format. Luckily, all such@@ -133,7 +128,7 @@ const savedLocaleStringMigratingIfNeeded = () => {if (!ls) {// Nothing found- return ls;+ return undefined;}if (includes(supportedLocales, ls)) {@@ -150,12 +145,12 @@ const savedLocaleStringMigratingIfNeeded = () => {// have happened, we're the only one setting it.logError("Failed to parse locale obtained from local storage", e);// Also remove the old key, it is not parseable by us anymore.- removeLSString("locale");+ localStorage.removeItem("locale");return undefined;}const newValue = mapOldValue(value);- if (newValue) setLSString("locale", newValue);+ if (newValue) localStorage.setItem("locale", newValue);return newValue;};@@ -249,6 +244,6 @@ export const getLocaleInUse = (): SupportedLocale => {* preference that is stored in local storage.*/export const setLocaleInUse = async (locale: SupportedLocale) => {- setLSString("locale", locale);+ localStorage.setItem("locale", locale);return i18n.changeLanguage(locale);};diff --git a/web/packages/shared/logging/index.ts b/web/packages/shared/logging/index.tsindex c7c793dbfe..12ff5bf6ea 100644--- a/web/packages/shared/logging/index.ts+++ b/web/packages/shared/logging/index.ts@@ -1,4 +1,4 @@-import { isDevBuild } from "@/utils/env";+import { isDevBuild } from "@/next/env";import { logError } from "@ente/shared/sentry";import isElectron from "is-electron";import { WorkerSafeElectronService } from "../electron/service";diff --git a/web/packages/shared/logging/web.ts b/web/packages/shared/logging/web.tsindex 7c9e7e2ed9..7b15851b86 100644--- a/web/packages/shared/logging/web.ts+++ b/web/packages/shared/logging/web.ts@@ -1,4 +1,4 @@-import { isDevBuild } from "@/utils/env";+import { isDevBuild } from "@/next/env";import { logError } from "@ente/shared/sentry";import {getData,diff --git a/web/packages/utils/local-storage.ts b/web/packages/utils/local-storage.tsdeleted file mode 100644index 7da0b150c0..0000000000--- a/web/packages/utils/local-storage.ts+++ /dev/null@@ -1,40 +0,0 @@-/**- * Keys corresponding to the items that we save in local storage.- *- * The type of each of the these keys is {@link LSKey}.- *- * Note: [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 cleared when the browser tab is closed.- *- * The data in local storage is tied to the Document's origin (scheme + host).- */-export const lsKeys = ["locale"] as const;--/** The type of {@link lsKeys}. */-export type LSKey = (typeof lsKeys)[number];--/**- * Read a previously saved string from local storage- */-export const getLSString = (key: LSKey) => {- const item = localStorage.getItem(key);- if (item === null) return undefined;- return item;-};--/**- * Save a string in local storage- */-export const setLSString = (key: LSKey, value: string) => {- localStorage.setItem(key, value);-};--/**- * Remove an string from local storage.- */-export const removeLSString = (key: LSKey) => {- localStorage.removeItem(key);-};