Vben
authored
|
1
|
import { getStorageShortName } from '/@/utils/env';
|
Vben
authored
|
2
|
import { createStorage as create, CreateStorageParams } from './storageCache';
|
vben
authored
|
3
|
import { enableStorageEncryption } from '/@/settings/encryptionSetting';
|
Vben
authored
|
4
|
import { DEFAULT_CACHE_TIME } from '/@/settings/encryptionSetting';
|
|
5
|
|
Vben
authored
|
6
7
8
|
export type Options = Partial<CreateStorageParams>;
const createOptions = (storage: Storage, options: Options = {}): Options => {
|
|
9
|
return {
|
vben
authored
|
10
11
|
// No encryption in debug mode
hasEncrypt: enableStorageEncryption,
|
|
12
13
|
storage,
prefixKey: getStorageShortName(),
|
Vben
authored
|
14
|
...options,
|
|
15
16
|
};
};
|
vben
authored
|
17
|
|
Vben
authored
|
18
19
20
21
22
|
export const WebStorage = create(createOptions(sessionStorage));
export const createStorage = (storage: Storage = sessionStorage, options: Options = {}) => {
return create(createOptions(storage, options));
};
|
|
23
|
|
Vben
authored
|
24
25
26
27
28
29
|
export const createSessionStorage = (options: Options = {}) => {
return createStorage(sessionStorage, { ...options, timeout: DEFAULT_CACHE_TIME });
};
export const createLocalStorage = (options: Options = {}) => {
return createStorage(localStorage, { ...options, timeout: DEFAULT_CACHE_TIME });
|
|
30
|
};
|
vben
authored
|
31
|
|
|
32
|
export default WebStorage;
|