mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 08:13:42 +00:00
[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>
This commit is contained in:
42
apps/web/src/app/platform/web-global-state.provider.ts
Normal file
42
apps/web/src/app/platform/web-global-state.provider.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user