2022-05-26 04:44:26 +02:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
// ****************************************************************************
|
|
|
|
// ****************************************************************************
|
|
|
|
|
|
|
|
export const LS = Object.freeze({
|
|
|
|
AUTH_IN_PROGRESS: 'authInProgress',
|
|
|
|
CHANNEL_LIVE_STATUS: 'channel-live-status',
|
|
|
|
GDPR_REQUIRED: 'gdprRequired', // <-- should be using 'locale/get', right?
|
|
|
|
SHARE_INTERNAL: 'shareInternal',
|
|
|
|
TUS_LOCKED_UPLOADS: 'tusLockedUploads',
|
|
|
|
TUS_REFRESH_LOCK: 'tusRefreshLock',
|
|
|
|
TUS_REMOVED_UPLOADS: 'tusRemovedUploads',
|
|
|
|
});
|
|
|
|
|
|
|
|
// ****************************************************************************
|
|
|
|
// ****************************************************************************
|
|
|
|
|
2021-12-07 15:48:09 +01:00
|
|
|
export function isLocalStorageAvailable() {
|
|
|
|
try {
|
|
|
|
return Boolean(window.localStorage);
|
|
|
|
} catch (e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isSessionStorageAvailable() {
|
|
|
|
try {
|
|
|
|
return Boolean(window.sessionStorage);
|
|
|
|
} catch (e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2022-02-22 16:11:22 +01:00
|
|
|
|
|
|
|
export function getLocalStorageSummary() {
|
|
|
|
try {
|
|
|
|
const count = window.localStorage.length;
|
|
|
|
const estimatedSize = JSON.stringify(window.localStorage).length;
|
|
|
|
return `${count} items; ${estimatedSize} bytes`;
|
|
|
|
} catch (e) {
|
|
|
|
return 'inaccessible';
|
|
|
|
}
|
|
|
|
}
|
2022-05-18 10:57:25 +02:00
|
|
|
|
2022-05-26 04:44:26 +02:00
|
|
|
// ****************************************************************************
|
|
|
|
// LocalStorage (wrapper for 'window.localStorage')
|
|
|
|
// ****************************************************************************
|
|
|
|
|
|
|
|
// This assumes that local storage availability never changes after boot.
|
2022-05-18 10:57:25 +02:00
|
|
|
const localStorageAvailable = isLocalStorageAvailable();
|
|
|
|
|
2022-05-26 04:44:26 +02:00
|
|
|
export const LocalStorage = {
|
|
|
|
setItem: (key: string, value: string) => {
|
|
|
|
if (localStorageAvailable) window.localStorage.setItem(key, value);
|
|
|
|
},
|
2022-05-18 10:57:25 +02:00
|
|
|
|
2022-05-26 04:44:26 +02:00
|
|
|
getItem: (key: string) => {
|
|
|
|
return localStorageAvailable ? window.localStorage.getItem(key) : undefined;
|
|
|
|
},
|
|
|
|
|
|
|
|
removeItem: (key: string) => {
|
|
|
|
if (localStorageAvailable) window.localStorage.removeItem(key);
|
|
|
|
},
|
|
|
|
};
|