diff --git a/app.py b/app.py index 418b37e..7d93bae 100644 --- a/app.py +++ b/app.py @@ -119,8 +119,12 @@ async def root(): class ConnectionManager: def __init__(self): self.active_connections: list[WebSocket] = [] + self.max_connections = 100 # Ограничение числа подключений async def connect(self, websocket: WebSocket): + if len(self.active_connections) >= self.max_connections: + await websocket.close(code=1008, reason="Too many connections") + return await websocket.accept() self.active_connections.append(websocket) @@ -128,7 +132,7 @@ class ConnectionManager: self.active_connections.remove(websocket) async def broadcast(self, message: str): - for connection in self.active_connections: + for connection in self.active_connections[:]: # Копируем список для безопасного удаления await connection.send_text(message) manager = ConnectionManager() @@ -359,7 +363,7 @@ async def upload_image(install_id: int = Form(...), file: UploadFile = File(...) # CORS для API api_app.add_middleware( CORSMiddleware, - allow_origins=["http://10.0.0.10:8001", "http://localhost:8001"], + allow_origins=["https://rd.it-depot.ru"], # Обновлено для HTTPS allow_credentials=True, allow_methods=["*"], allow_headers=["*"], @@ -368,7 +372,7 @@ api_app.add_middleware( # CORS для веб-интерфейса web_app.add_middleware( CORSMiddleware, - allow_origins=["http://10.0.0.10:8001", "http://localhost:8001"], + allow_origins=["https://rd.it-depot.ru"], # Обновлено для HTTPS allow_credentials=True, allow_methods=["*"], allow_headers=["*"], diff --git a/templates/index.html b/templates/index.html index 58fc7a2..291987c 100644 --- a/templates/index.html +++ b/templates/index.html @@ -8,10 +8,252 @@ @@ -157,7 +399,7 @@ const containerRect = document.body.getBoundingClientRect(); let newWidth = e.clientX - containerRect.left; - const minWidth = parseInt(getComputedStyle(treeContainer).minWidth, 10); + const minWidth = 200; const maxWidth = containerRect.width * 0.5; if (newWidth < minWidth) newWidth = minWidth; @@ -194,7 +436,6 @@ $(items[currentIndex])[0].scrollIntoView({ behavior: 'smooth', block: 'nearest' }); }); - // Подключение к WebSocket connectWebSocket(); }); @@ -360,7 +601,8 @@ if (ws) { ws.close(); } - ws = new WebSocket(`ws://${window.location.host}/ws`); + // Используем wss для соответствия HTTPS + ws = new WebSocket(`wss://${window.location.host}/ws`); ws.onmessage = function(event) { allInstalls = JSON.parse(event.data); displayInstalls(allInstalls.filter(i => !selectedFolderId || i.folder_id == selectedFolderId)); @@ -438,7 +680,7 @@ return `
${item.computer_name}
-
${protocolIcons[item.protocol]}${item.rust_id}
+
${protocolIcons[item.protocol]}${item.rust_id}
${item.install_time}
@@ -865,7 +1107,7 @@ function formatItalic() { const textarea = $('#note-textarea'); const start = textarea[0].selectionStart; - const end = textarea[0].selectionEnd; + end = textarea[0].selectionEnd; const text = textarea.val(); const selected = text.substring(start, end); const newText = `*${selected}*`;