Tortoise based database models
This commit is contained in:
1 parent
2c7b3d61d1
commit
cccdb7d231
12 files changed
+469
-382
No files matched your search
+20
-14
@@ -12,6 +12,8 @@ import nest_asyncio
|
||||
frontend_path = '../../frontend/dist'
|
||||
|
||||
def start_server(app):
|
||||
nest_asyncio.apply()
|
||||
|
||||
server = Quart(__name__, static_folder=frontend_path)
|
||||
server.secret_key = 'horde-secret'
|
||||
auth_manager = QuartAuth(server, mode="brearer")
|
||||
@@ -48,7 +50,7 @@ def start_server(app):
|
||||
if "username" not in data or "password" not in data:
|
||||
return "invalid login arguments", 400
|
||||
|
||||
user_id = app.verify_user_credentials(data['username'], data['password'])
|
||||
user_id = await app.verify_user_credentials(data['username'], data['password'])
|
||||
if user_id == None:
|
||||
return "bad login credentials", 401
|
||||
|
||||
@@ -65,11 +67,11 @@ def start_server(app):
|
||||
email = data['email']
|
||||
password = data['password']
|
||||
|
||||
user_id = app.create_new_user(username, email, password)
|
||||
user_id = await app.create_new_user(username, email, password)
|
||||
if user_id is None:
|
||||
return "existing or incorrect credentials", 400
|
||||
|
||||
app.generate_default_user_data(user_id)
|
||||
await app.generate_default_user_data(user_id)
|
||||
|
||||
token = auth_manager.dump_token(user_id)
|
||||
return {"token": token}
|
||||
@@ -84,6 +86,9 @@ def start_server(app):
|
||||
if 'token' in auth_req:
|
||||
try:
|
||||
user_id = auth_manager.load_token(auth_req['token'])
|
||||
if not await app.verify_user_id(user_id):
|
||||
await websocket.send(json.dumps({'error': 'invalid credentials'}))
|
||||
return
|
||||
except Exception as err:
|
||||
print("Token authentication failed: ", err)
|
||||
await websocket.send(json.dumps({'error': 'token authentication failed'}))
|
||||
@@ -133,7 +138,7 @@ def start_server(app):
|
||||
|
||||
elif action == "create-agent":
|
||||
name = body['name']
|
||||
agent_id = app.create_agent(
|
||||
agent_id = await app.create_agent(
|
||||
user_id=user_id,
|
||||
name=name,
|
||||
agentname=body.get('agentname'),
|
||||
@@ -146,7 +151,7 @@ def start_server(app):
|
||||
|
||||
elif action == "update-agent":
|
||||
agent_id = body['agentId']
|
||||
app.update_agent(
|
||||
await app.update_agent(
|
||||
agent_id=agent_id,
|
||||
name=body.get('name'),
|
||||
agentname=body.get('agentname'),
|
||||
@@ -157,7 +162,7 @@ def start_server(app):
|
||||
await send({'message': "agent updated", 'agentId': agent_id, 'nonce': nonce})
|
||||
|
||||
elif action == "get-agent-config-fields":
|
||||
await send({'fields': app.get_agent_config_fields(body['agentId']), 'nonce': nonce})
|
||||
await send({'fields': await app.get_agent_config_fields(body['agentId']), 'nonce': nonce})
|
||||
|
||||
elif action == "get-agent-kinds":
|
||||
await send({'message': "agents retrieved", 'kinds': app.get_agent_kinds(), 'nonce': nonce})
|
||||
@@ -166,10 +171,11 @@ def start_server(app):
|
||||
await send({'message': "agent kind retrieved", 'info': app.get_agent_kind_info(body['kind']), 'nonce': nonce})
|
||||
|
||||
elif action == "get-agents":
|
||||
await send({'message': "agents retrieved", 'agents': app.get_agents(user_id), 'nonce': nonce})
|
||||
#await send({'agents': [], 'nonce': nonce})
|
||||
await send({'message': "agents retrieved", 'agents': await app.get_agents(user_id), 'nonce': nonce})
|
||||
|
||||
elif action == "create-chat":
|
||||
chat_id = app.create_chat(
|
||||
chat_id = await app.create_chat(
|
||||
user_id=user_id,
|
||||
name=body['name'],
|
||||
description=body.get('description'),
|
||||
@@ -179,24 +185,24 @@ def start_server(app):
|
||||
await send({'message': "chat created", 'chatId': chat_id, 'nonce': nonce})
|
||||
|
||||
elif action == "get-chats":
|
||||
chats_data = app.get_chats(user_id)
|
||||
chats_data = await app.get_chats(user_id)
|
||||
await send({'message': "chats retrieved", 'chats': chats_data, 'nonce': nonce})
|
||||
|
||||
elif action == "delete-chat":
|
||||
chat_id = app.delete_chat(
|
||||
chat_id = await app.delete_chat(
|
||||
chat_id=body['chatId']
|
||||
)
|
||||
await send({'message': "chat deleted", 'chatId': chat_id, 'nonce': nonce})
|
||||
|
||||
elif action == "get-chat-messages":
|
||||
messages_data = app.get_chat_messages(
|
||||
messages_data = await app.get_chat_messages(
|
||||
body['chatId'],
|
||||
earliest_index=body.get('earliestIndex', 0)
|
||||
)
|
||||
await send({'message': "chat messages retrieved", 'messages': messages_data, 'nonce': nonce})
|
||||
|
||||
elif action == "send-chat-message":
|
||||
message = app.send_chat_message(
|
||||
message = await app.send_chat_message(
|
||||
chat_id=body['chatId'],
|
||||
thread_id=body.get('threadId'),
|
||||
content=body['content'],
|
||||
@@ -207,7 +213,7 @@ def start_server(app):
|
||||
await send({'message': "message sent", 'messageId': message['id'], 'nonce': nonce})
|
||||
|
||||
elif action == "update-chat-message":
|
||||
message = app.update_chat_message(
|
||||
message = await app.update_chat_message(
|
||||
message_id=body['messageId'],
|
||||
content=body['content'],
|
||||
kind=body.get('kind'),
|
||||
@@ -217,7 +223,7 @@ def start_server(app):
|
||||
await send({'message': "message sent", 'messageId': body['messageId'], 'nonce': nonce})
|
||||
|
||||
elif action == "create-chat-thread":
|
||||
thread_id = app.create_chat_thread(
|
||||
thread_id = await app.create_chat_thread(
|
||||
chat_id=body['chatId'],
|
||||
name=body.get('name'),
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user