use reader.js

This commit is contained in:
2026-04-18 20:18:17 +02:00
parent 593f2288ae
commit 08056a3820
4 changed files with 656 additions and 47 deletions
+15 -4
View File
@@ -5,6 +5,17 @@ import threading, uuid, time
import asyncio
import websockets
from websockets import ServerConnection, Request, Response, Headers
import mimetypes
def get_content_type(filename: str) -> str:
# Fallback to Python's mimetypes
mime_type, _ = mimetypes.guess_type(filename)
if mime_type:
return mime_type
# Final fallback
return "application/octet-stream"
from modules import InterModuleCommunication
@@ -113,20 +124,20 @@ def websocket_server_process(shared_data: dict, imc_q: multiprocessing.Queue, ws
await websocket.close(1001, "")
clients.discard(websocket)
async def process_request(websocket: ServerConnection, request: Request):
if request.path == "/" and (file := Path(__file__, "..", "web.html").resolve()).exists():
if request.path == "/" and (file := Path(__file__, "..", "index.html").resolve()).exists():
data = file.read_bytes()
return Response(
200,
"OK",
Headers([("Content-Type", "text/html"), ("Content-Length", f"{len(data)}")]),
Headers([("Content-Type", "text/html; charset=utf-8"), ("Content-Length", f"{len(data)}")]),
data
)
if request.path == "/web.js" and (file := Path(__file__, "..", "web.js").resolve()).exists():
if (file := Path(__file__, "..", request.path.removeprefix("/").strip()).resolve()).exists():
data = file.read_bytes()
return Response(
200,
"OK",
Headers([("Content-Type", "text/javascript"), ("Content-Length", f"{len(data)}")]),
Headers([("Content-Type", get_content_type(file.name)), ("Content-Length", f"{len(data)}")]),
data
)
if request.path == "/ws":