mirror of
https://github.com/radio95-rnt/RadioPlayer.git
synced 2026-07-29 15:29:14 +02:00
use reader.js
This commit is contained in:
+15
-4
@@ -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":
|
||||
|
||||
Reference in New Issue
Block a user