SHA256
61 lines
1.7 KiB
JavaScript
61 lines
1.7 KiB
JavaScript
import { t } from '../i18n/index.js';
|
|
// Keep historical Frame snapshots in their original bucket; never publish them as CORE.
|
|
const SNAPSHOT_STORAGE_KEY = 'shine-ui-blockchain-snapshot-test5593';
|
|
|
|
function normalizeLogin(login) {
|
|
return String(login || '').trim().toLowerCase();
|
|
}
|
|
|
|
function storageBucketKey(login) {
|
|
return normalizeLogin(login) || 'anonymous';
|
|
}
|
|
|
|
function readStorageMap() {
|
|
try {
|
|
const raw = localStorage.getItem(SNAPSHOT_STORAGE_KEY);
|
|
const parsed = raw ? JSON.parse(raw) : {};
|
|
return parsed && typeof parsed === 'object' ? parsed : {};
|
|
} catch {
|
|
return {};
|
|
}
|
|
}
|
|
|
|
function writeStorageMap(value) {
|
|
try {
|
|
localStorage.setItem(SNAPSHOT_STORAGE_KEY, JSON.stringify(value || {}));
|
|
} catch {
|
|
// ignore localStorage errors
|
|
}
|
|
}
|
|
|
|
export function readStoredBlockchainSnapshot(login) {
|
|
const key = storageBucketKey(login);
|
|
const map = readStorageMap();
|
|
const value = map?.[key];
|
|
return value && typeof value === 'object' ? value : null;
|
|
}
|
|
|
|
export function saveStoredBlockchainSnapshot(login, snapshot) {
|
|
const key = storageBucketKey(login);
|
|
const map = readStorageMap();
|
|
map[key] = {
|
|
...snapshot,
|
|
savedAtMs: Date.now(),
|
|
};
|
|
writeStorageMap(map);
|
|
return map[key];
|
|
}
|
|
|
|
export function clearStoredBlockchainSnapshot(login) {
|
|
const key = storageBucketKey(login);
|
|
const map = readStorageMap();
|
|
delete map[key];
|
|
writeStorageMap(map);
|
|
}
|
|
|
|
// The old concatenated Frame file is not a CORE archive. Do not upload an empty
|
|
// or lossy replacement or invent a snapshot format before D defines recovery.
|
|
export async function buildBlockchainSnapshotFile() {
|
|
throw new Error(t('remaining.blockchain_snapshot.core_pending'));
|
|
}
|