Safe remove of items in exception

This commit is contained in:
James Ketr 2025-03-20 17:57:32 -07:00
parent ce6cdac00b
commit 1c4d3cee7e
17 changed files with 14 additions and 12 deletions

View File

@ -740,7 +740,7 @@ class WebServer:
def __init__(self, logging): def __init__(self, logging):
self.logging = logging self.logging = logging
self.app = Flask(__name__, static_folder='/opt/airc/src/client/dist', static_url_path='') self.app = Flask(__name__, static_folder='/opt/airc/src/ketr-chat/build', static_url_path='')
self.sock = Sock(self.app) self.sock = Sock(self.app)
self.sessions = {} self.sessions = {}
@ -756,7 +756,7 @@ class WebServer:
"system": system_message, "system": system_message,
"users": [], "users": [],
"history": [], "history": [],
"sockets": [socket] "sockets": []
} }
logging.info(f"{session['id']} created and added to sessions.") logging.info(f"{session['id']} created and added to sessions.")
self.sessions[session['id']] = session self.sessions[session['id']] = session
@ -770,8 +770,8 @@ class WebServer:
user = random_nick() user = random_nick()
if not session_id in self.sessions: if not session_id in self.sessions:
self.generate_session(ws, session_id) self.generate_session(ws, session_id)
else:
self.sessions[session_id]['sockets'].append(ws) self.sessions[session_id]['sockets'].append(ws)
while True: while True:
try: try:
@ -831,8 +831,10 @@ class WebServer:
ws.send(json.dumps({"type": "error", "error": f"Invalid request type: {data['type']}"})) ws.send(json.dumps({"type": "error", "error": f"Invalid request type: {data['type']}"}))
except Exception as e: except Exception as e:
logging.error(f"WebSocket error: {str(e)}") logging.error(f"WebSocket error: {str(e)}")
self.sessions[session_id]['users'].remove(user) if user in self.sessions[session_id]['users']:
self.sessions[session_id]['sockets'].remove(ws) self.sessions[session_id]['users'].remove(user)
if ws in self.sessions[session_id]['sockets']:
self.sessions[session_id]['sockets'].remove(ws)
for socket in self.sessions[session_id]['sockets']: for socket in self.sessions[session_id]['sockets']:
socket.send(json.dumps({"type": "users", "update": self.sessions[session_id]['users']})) socket.send(json.dumps({"type": "users", "update": self.sessions[session_id]['users']}))

BIN
src/ketr-chat/favicon.ico Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 318 B

BIN
src/ketr-chat/favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 318 B

BIN
src/ketr-chat/public/favicon.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
src/ketr-chat/public/icon.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

View File

@ -24,7 +24,7 @@
work correctly both with client-side routing and a non-root public URL. work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`. Learn how to configure a non-root public URL by running `npm run build`.
--> -->
<title>React App</title> <title>Ketr-Chat</title>
</head> </head>
<body> <body>
<noscript>You need to enable JavaScript to run this app.</noscript> <noscript>You need to enable JavaScript to run this app.</noscript>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

After

Width:  |  Height:  |  Size: 7.5 KiB

View File

@ -1,6 +1,6 @@
{ {
"short_name": "React App", "short_name": "Ketr-Chat",
"name": "Create React App Sample", "name": "Ketrenos AI Chat",
"icons": [ "icons": [
{ {
"src": "favicon.ico", "src": "favicon.ico",

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -6,7 +6,7 @@ import { createSemanticDiagnosticsBuilderProgram } from 'typescript';
const welcome_message = "Welcome to Ketr-Chat. I have real-time access to a lot of information. Ask things like 'What are the headlines from cnn.com?' or 'What is the weather in Portland, OR?'"; const welcome_message = "Welcome to Ketr-Chat. I have real-time access to a lot of information. Ask things like 'What are the headlines from cnn.com?' or 'What is the weather in Portland, OR?'";
const url: string = "http://battle-linux.ketrenos.com:5000" const url: string = "https://ai.ketrenos.com"
const App = () => { const App = () => {
const [query, setQuery] = useState(''); const [query, setQuery] = useState('');
@ -185,8 +185,8 @@ const App = () => {
} else { } else {
new_uri = "ws://"; new_uri = "ws://";
} }
//new_uri += loc.host + `/api/ws/${sessionId}`; new_uri += loc.host + `/api/ws/${sessionId}`;
new_uri += `battle-linux.ketrenos.com:5000/api/ws/${sessionId}`; //new_uri += `battle-linux.ketrenos.com:5000/api/ws/${sessionId}`;
console.log(`Attempting WebSocket connection to ${new_uri}`); console.log(`Attempting WebSocket connection to ${new_uri}`);
socket = new WebSocket(new_uri) socket = new WebSocket(new_uri)
setWs(socket); setWs(socket);