mirror of
https://github.com/radio95-rnt/RadioPlayer.git
synced 2026-07-29 23:39:15 +02:00
there
This commit is contained in:
+17
-16
@@ -124,22 +124,6 @@ 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__, "..", "index.html").resolve()).exists():
|
||||
data = file.read_bytes()
|
||||
return Response(
|
||||
200,
|
||||
"OK",
|
||||
Headers([("Content-Type", "text/html; charset=utf-8"), ("Content-Length", f"{len(data)}")]),
|
||||
data
|
||||
)
|
||||
if (file := Path(__file__, "..", request.path.removeprefix("/").strip()).resolve()).exists():
|
||||
data = file.read_bytes()
|
||||
return Response(
|
||||
200,
|
||||
"OK",
|
||||
Headers([("Content-Type", get_content_type(file.name)), ("Content-Length", f"{len(data)}")]),
|
||||
data
|
||||
)
|
||||
if request.path == "/ws":
|
||||
if not "upgrade" in request.headers.get("Connection", "").lower():
|
||||
return Response(
|
||||
@@ -149,6 +133,23 @@ def websocket_server_process(shared_data: dict, imc_q: multiprocessing.Queue, ws
|
||||
b"WebSocket upgrade required\n"
|
||||
)
|
||||
return None
|
||||
else:
|
||||
if request.path == "/" and (file := Path(__file__, "..", "index.html").resolve()).exists():
|
||||
data = file.read_bytes()
|
||||
return Response(
|
||||
200,
|
||||
"OK",
|
||||
Headers([("Content-Type", "text/html; charset=utf-8"), ("Content-Length", f"{len(data)}")]),
|
||||
data
|
||||
)
|
||||
elif (file := Path(__file__, "..", request.path.removeprefix("/").strip()).resolve()).exists():
|
||||
data = file.read_bytes()
|
||||
return Response(
|
||||
200,
|
||||
"OK",
|
||||
Headers([("Content-Type", get_content_type(file.name)), ("Content-Length", f"{len(data)}")]),
|
||||
data
|
||||
)
|
||||
else:
|
||||
data = b"Not Found\n"
|
||||
return Response(
|
||||
|
||||
Reference in New Issue
Block a user