From d572db87774d4dc4f5724edb9ae4d7276046d937 Mon Sep 17 00:00:00 2001 From: shaohuzhang1 Date: Tue, 27 Feb 2024 17:18:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B5=8C=E5=85=A5=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E5=A6=82=E6=9E=9C=E5=85=AC=E5=85=B1=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E4=B8=8D=E5=AD=98=E5=9C=A8=E5=88=99=E4=B8=8D=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/public/embeb.js | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/ui/public/embeb.js b/ui/public/embeb.js index 9811e7b89..99177b8d4 100644 --- a/ui/public/embeb.js +++ b/ui/public/embeb.js @@ -1,6 +1,15 @@ +function auth(token,protocol,host){ + const XML=new XMLHttpRequest() + XML.open("POST",`${protocol}//${host}/api/application/authentication`,false) + XML.setRequestHeader('Content-Type', 'application/json'); + res=XML.send(JSON.stringify({"access_token":token})) + return XML.status==200 +} + function embedChatbot() { const t = window.maxkbChatConfig - if (t && t.token && t.protocol && t.host) { + check=auth(t.token,t.protocol, t.host) + if (t && t.token && t.protocol && t.host&& check) { icon = ` @@ -59,16 +68,30 @@ function embedChatbot() { cursor: pointer; ` close_button.onclick = () => { - chat_container.style['display'] = 'none' - chat_button.style['display'] = 'block' + document.body.removeChild(chat_container) + chat_button.style['display']='block' } chat_container.append(close_button) document.body.append(chat_container) - + let is_404=false chat_button.onclick = ($event) => { - chat_container.style['display'] = 'block' - chat_button.style['display'] = 'block' + if( chat_container.style['display']=='block'){ + chat_container.style['display']='none' + } else { + if(auth(t.token,t.protocol, t.host)){ + if(is_404){ + document.body.removeChild(chat_container) + document.body.append(chat_container) + is_404=false + }else{ + chat_container.style['display']='block' + } + + }else{ + is_404=true + } + } } sty = document.createElement('style') sty.innerText = ` #chat_container {