SHA256
Добавить деплой без clean/тестов и доработки PWA/сессии в UI
This commit is contained in:
+65
-4
@@ -1,11 +1,15 @@
|
||||
import { chatMessages, wallet } from './mock-data.js';
|
||||
import { wallet } from './mock-data.js';
|
||||
import { AuthService } from './services/auth-service.js';
|
||||
import { clearClientAuthData } from './services/key-vault.js';
|
||||
import { listStoredMessages, putStoredMessage } from './services/message-store.js';
|
||||
import { clearStoredMessages, listStoredMessages, putStoredMessage } from './services/message-store.js';
|
||||
|
||||
const clone = (value) => JSON.parse(JSON.stringify(value));
|
||||
const SESSION_STORAGE_KEY = 'shine-ui-current-session-v1';
|
||||
const REACTIONS_STORAGE_KEY = 'shine-ui-message-reactions-v2';
|
||||
const WEB_PUSH_SUBSCRIPTION_KEY = 'shine-ui-webpush-subscription-v1';
|
||||
const CHANNEL_NOTIFY_KEY = 'shine-channels-notify-v1';
|
||||
const CHANNELS_DEMO_KEY = 'shine-channels-demo';
|
||||
const CREATE_CHANNEL_FLASH_KEY = 'shine-channels-create-success';
|
||||
const MAX_APP_LOG_ENTRIES = 500;
|
||||
const INVALID_SESSION_CODES = new Set([
|
||||
'NOT_AUTHENTICATED',
|
||||
@@ -121,13 +125,36 @@ function clearStoredSession() {
|
||||
}
|
||||
}
|
||||
|
||||
function clearBrowserClientData() {
|
||||
const localKeys = [
|
||||
SESSION_STORAGE_KEY,
|
||||
REACTIONS_STORAGE_KEY,
|
||||
WEB_PUSH_SUBSCRIPTION_KEY,
|
||||
CHANNEL_NOTIFY_KEY,
|
||||
CHANNELS_DEMO_KEY,
|
||||
];
|
||||
localKeys.forEach((key) => {
|
||||
try {
|
||||
localStorage.removeItem(key);
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
sessionStorage.removeItem(CREATE_CHANNEL_FLASH_KEY);
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
function createInitialState({ withStoredSession = true } = {}) {
|
||||
const storedSession = withStoredSession ? loadStoredSession() : null;
|
||||
const storedReactions = loadStoredReactions();
|
||||
const initialShineServer = LOCAL_WS_OVERRIDE_URL || DEFAULT_SHINE_SERVER;
|
||||
|
||||
return {
|
||||
chats: clone(chatMessages),
|
||||
chats: {},
|
||||
contacts: [],
|
||||
appLog: [],
|
||||
incomingDedup: {},
|
||||
@@ -504,9 +531,16 @@ export async function refreshSessions() {
|
||||
function resetStateForSignedOut() {
|
||||
const next = createInitialState({ withStoredSession: false });
|
||||
state.chats = next.chats;
|
||||
state.contacts = next.contacts;
|
||||
state.appLog = next.appLog;
|
||||
state.incomingDedup = next.incomingDedup;
|
||||
state.knownMessageKeys = next.knownMessageKeys;
|
||||
state.outgoingTempSeq = next.outgoingTempSeq;
|
||||
state.notificationsTab = next.notificationsTab;
|
||||
state.pageLabelCollapsed = next.pageLabelCollapsed;
|
||||
state.session = next.session;
|
||||
state.startHint = next.startHint;
|
||||
state.entrySettings = next.entrySettings;
|
||||
state.registrationDraft = next.registrationDraft;
|
||||
state.loginDraft = next.loginDraft;
|
||||
state.registrationPayment = next.registrationPayment;
|
||||
@@ -522,21 +556,48 @@ function resetStateForSignedOut() {
|
||||
|
||||
export async function terminateCurrentSession({ infoMessage = '' } = {}) {
|
||||
clearStoredSession();
|
||||
clearBrowserClientData();
|
||||
resetStateForSignedOut();
|
||||
authService.close();
|
||||
try {
|
||||
await clearClientAuthData();
|
||||
await Promise.all([
|
||||
clearClientAuthData(),
|
||||
clearStoredMessages(),
|
||||
]);
|
||||
} catch {
|
||||
// ignore cleanup errors in prototype mode
|
||||
}
|
||||
if (infoMessage) {
|
||||
state.startHint = infoMessage;
|
||||
}
|
||||
try {
|
||||
await authService.reconnect(state.entrySettings.shineServer);
|
||||
} catch {
|
||||
// ignore reconnect errors on sign out
|
||||
}
|
||||
if (onSessionReset) {
|
||||
onSessionReset();
|
||||
}
|
||||
}
|
||||
|
||||
export async function closeCurrentSessionAndSignOut({ infoMessage = '' } = {}) {
|
||||
const currentSessionId = String(state.session.sessionId || '').trim();
|
||||
try {
|
||||
if (state.session.isAuthorized && currentSessionId) {
|
||||
await authService.closeSession(currentSessionId);
|
||||
}
|
||||
} catch (error) {
|
||||
addAppLogEntry({
|
||||
level: 'warn',
|
||||
source: 'session',
|
||||
message: 'Не удалось завершить текущую сессию на сервере',
|
||||
details: { sessionId: currentSessionId, error: error?.message || 'unknown' },
|
||||
});
|
||||
}
|
||||
|
||||
await terminateCurrentSession({ infoMessage });
|
||||
}
|
||||
|
||||
export function refreshRegistrationBalance() {
|
||||
const next = (0.005 + Math.random() * 0.03).toFixed(4);
|
||||
state.registrationPayment.balanceSOL = next;
|
||||
|
||||
Reference in New Issue
Block a user