1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-13 06:43:35 +00:00
Files
browser/apps/web/src/app/platform/web-global-state.provider.ts
Justin Baur 45c0c09b71 [PM-5829] Add disk-local option for web (#7669)
* Add `disk-local` option for web

* Fix `web` DI

* Update libs/common/src/platform/state/state-definition.ts

Co-authored-by: Matt Gibson <mgibson@bitwarden.com>

* Rely On Default Implementation for Most of Cache Key

---------

Co-authored-by: Matt Gibson <mgibson@bitwarden.com>
2024-01-25 12:48:51 -05:00

43 lines
1.6 KiB
TypeScript

import {
AbstractMemoryStorageService,
AbstractStorageService,
ObservableStorageService,
} from "@bitwarden/common/platform/abstractions/storage.service";
import { KeyDefinition } from "@bitwarden/common/platform/state";
/* eslint-disable import/no-restricted-paths -- Needed to extend class & in platform owned code*/
import { DefaultGlobalStateProvider } from "@bitwarden/common/platform/state/implementations/default-global-state.provider";
import { StateDefinition } from "@bitwarden/common/platform/state/state-definition";
/* eslint-enable import/no-restricted-paths */
export class WebGlobalStateProvider extends DefaultGlobalStateProvider {
constructor(
memoryStorage: AbstractMemoryStorageService & ObservableStorageService,
sessionStorage: AbstractStorageService & ObservableStorageService,
private readonly diskLocalStorage: AbstractStorageService & ObservableStorageService,
) {
super(memoryStorage, sessionStorage);
}
protected getLocationString(keyDefinition: KeyDefinition<unknown>): string {
return (
keyDefinition.stateDefinition.storageLocationOverrides["web"] ??
keyDefinition.stateDefinition.defaultStorageLocation
);
}
protected override getLocation(
stateDefinition: StateDefinition,
): AbstractStorageService & ObservableStorageService {
const location =
stateDefinition.storageLocationOverrides["web"] ?? stateDefinition.defaultStorageLocation;
switch (location) {
case "disk":
return this.diskStorage;
case "memory":
return this.memoryStorage;
case "disk-local":
return this.diskLocalStorage;
}
}
}