From 9f2e35529877bf7ff04eeac6bbb0ba4c17bbcc6a Mon Sep 17 00:00:00 2001 From: anor Date: Wed, 6 May 2026 16:26:28 +1000 Subject: [PATCH] =?UTF-8?q?fix:=20fallback=20=D0=B4=D0=BB=D1=8F=20crypto.r?= =?UTF-8?q?andomUUID=20=D0=B2=20insecure=20context=20(HTTP=20=D0=BF=D0=BE?= =?UTF-8?q?=20IP)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Под голым HTTP (например http://192.168.87.76:8103/ для dev-сервера) crypto.randomUUID отсутствует — secure context требует HTTPS или localhost. Без fallback скрипт падал с TypeError до рендера и страница оставалась пустой. Co-Authored-By: Claude Opus 4.7 (1M context) --- static/chat.html | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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', 'Новый диалог начат.');