Added new chat page and fixed JSON error

This commit is contained in:
2025-09-28 09:24:15 +01:00
parent 1abb1b5106
commit b2e51be8e5
4 changed files with 938 additions and 8 deletions

16
main.py
View File

@@ -111,8 +111,7 @@ def generateMessage(_id):
print(chunk['message']['content'], end='', flush=True)
content = chunk['message']['content']
response += content
json_data = {"response": response}
yield f"data: {json.dumps(json_data)}\n\n"
yield f"data: {response}\n\n"
return Response(generateStream(), mimetype='text/event-stream')
else:
@@ -238,6 +237,19 @@ def index():
else:
render_template('logout.html', appName=appName)
@app.route('/chat/<_id>', methods = ['GET'])
def chatPage(_id):
token = request.cookies.get('auth_token', 'none')
if (token == 'none'):
return render_template('login.html', appName=appName, githubUrl=github_auth_endpoint, githublogin=settings["github_oauth"]["enabled"], oauthlogin=settings["oauth_login"])
else:
a, userId = checkUserPermission(token, True)
if (a == True):
return render_template('chat.html', appName=appName, chatId=_id)
else:
render_template('logout.html', appName=appName)
# Login endpoint
# Api backend for login screen, check for user and returns token
# Arguments: username (required), password (required)