add half-working client

This commit is contained in:
2025-05-05 00:15:12 +02:00
parent 776ee8d637
commit bfa0ba8edf
13 changed files with 782 additions and 38 deletions

30
main.py
View File

@@ -1,5 +1,5 @@
from fastapi import FastAPI, Request, WebSocket, WebSocketDisconnect, BackgroundTasks, HTTPException
from fastapi.responses import HTMLResponse, JSONResponse, FileResponse
from fastapi import FastAPI, File, Request, WebSocket, WebSocketDisconnect, BackgroundTasks, HTTPException
from fastapi.responses import JSONResponse, FileResponse
import logging
import uvicorn
from typing import Dict, List, Any
@@ -55,7 +55,7 @@ class ConnectionManager:
def json_to_binary(self, json_str: str):
json_bytes = json_str.encode('utf-8')
json_length = len(json_bytes)
json_length = len(json_bytes) & 0xFFFFFFFF
# 4-byte unsigned integer (uint32)
length_bytes = struct.pack('!I', json_length)
@@ -100,26 +100,24 @@ class ConnectionManager:
manager = ConnectionManager()
# Static files
def read_file(filepath: str) -> str:
with open(filepath, "r", encoding="utf-8") as f:
return f.read()
@dataclass
class StaticFiles:
index_html: str = read_file("static/index.html")
script_js: str = read_file("static/script.js")
@app.get("/presentation/")
async def presentation_index(_: Request):
return HTMLResponse(status_code=200, content=StaticFiles.index_html, media_type="text/html")
return FileResponse(status_code=200, path="static/index.html", media_type="text/html")
@app.get("/presentation/script.js")
async def presentation_script(_: Request):
return HTMLResponse(
status_code=200, content=StaticFiles.script_js, media_type="text/javascript"
return FileResponse(
status_code=200, path="static/script.js", media_type="text/javascript"
)
@app.get("/presentation/style.css")
async def presentation_style(_: Request):
return FileResponse(status_code=200, path="static/style.css", media_type="text/css")
@app.get("/presentation/files/{file_path:path}")
async def presentation_file(file_path: str):
return FileResponse(status_code=200, path=f"static/{file_path}")
# Endpoints
@app.post("/control")
async def control_endpoint(request: Request):