diff --git a/static/chat.html b/static/chat.html index b4eb570..d811354 100644 --- a/static/chat.html +++ b/static/chat.html @@ -167,10 +167,19 @@ const API = ''; let token = localStorage.getItem('token'); let pendingFiles = []; let streaming = false; +// crypto.randomUUID работает только в secure context (HTTPS / localhost), +// под голым HTTP по IP его нет — используем fallback +function genUUID() { + if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') return crypto.randomUUID(); + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => { + const r = Math.random() * 16 | 0; + return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16); + }); +} // Session continuity: reuse last tabId from localStorage // New session only via "Новый чат" button or ?tab=UUID const urlTab = new URLSearchParams(window.location.search).get('tab'); -let tabId = urlTab || localStorage.getItem('tabId') || crypto.randomUUID(); +let tabId = urlTab || localStorage.getItem('tabId') || genUUID(); localStorage.setItem('tabId', tabId); function checkAdmin() { @@ -470,7 +479,7 @@ async function sendMessage() { // --- Session --- async function resetSession() { // Create new tab = new session, old one stays in DB - tabId = crypto.randomUUID(); + tabId = genUUID(); localStorage.setItem('tabId', tabId); msgs.innerHTML = ''; addMsg('system', 'Новый диалог начат.');