diff --git a/app.py b/app.py index 8dc1ddd..8badfb8 100644 --- a/app.py +++ b/app.py @@ -11,7 +11,7 @@ app = FastAPI() conn = sqlite3.connect("/db/rustdesk.db", check_same_thread=False) cursor = conn.cursor() -# Создаем таблицы +# Создаем таблицы (добавляем поле protocol) cursor.execute(""" CREATE TABLE IF NOT EXISTS folders ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -23,10 +23,11 @@ CREATE TABLE IF NOT EXISTS folders ( cursor.execute(""" CREATE TABLE IF NOT EXISTS installs ( id INTEGER PRIMARY KEY AUTOINCREMENT, - rust_id TEXT, + rust_id TEXT, -- Оставляем название поля для совместимости, но оно теперь универсальное (ID подключения) computer_name TEXT, install_time TEXT, folder_id INTEGER, + protocol TEXT DEFAULT 'rustdesk', -- Новое поле с протоколом, по умолчанию RustDesk FOREIGN KEY (folder_id) REFERENCES folders(id) ) """) @@ -55,6 +56,7 @@ class InstallData(BaseModel): computer_name: str | None = None install_time: str | None = None folder_id: int | None = None + protocol: str | None = 'rustdesk' # По умолчанию RustDesk # Монтируем папку templates как статические файлы app.mount("/templates", StaticFiles(directory="templates"), name="templates") @@ -98,44 +100,43 @@ def delete_folder(folder_id: int): @app.get("/api/installs") def get_installs(): cursor.execute(""" - SELECT i.id, i.rust_id, i.computer_name, i.install_time, i.folder_id, f.name as folder_name + SELECT i.id, i.rust_id, i.computer_name, i.install_time, i.folder_id, f.name as folder_name, i.protocol FROM installs i LEFT JOIN folders f ON i.folder_id = f.id """) rows = cursor.fetchall() return [{"id": row[0], "rust_id": row[1], "computer_name": row[2], - "install_time": row[3], "folder_id": row[4], "folder_name": row[5]} + "install_time": row[3], "folder_id": row[4], "folder_name": row[5], "protocol": row[6]} for row in rows] @app.post("/api/install") def add_install(data: InstallData): install_time = data.install_time or datetime.datetime.now().isoformat() - # Если folder_id не указан (например, от скрипта), используем "Несортированные" folder_id = data.folder_id if data.folder_id is not None else unsorted_folder_id - cursor.execute("INSERT INTO installs (rust_id, computer_name, install_time, folder_id) VALUES (?, ?, ?, ?)", - (data.rust_id, data.computer_name, install_time, folder_id)) + protocol = data.protocol or 'rustdesk' # По умолчанию RustDesk для POST-запросов + cursor.execute("INSERT INTO installs (rust_id, computer_name, install_time, folder_id, protocol) VALUES (?, ?, ?, ?, ?)", + (data.rust_id, data.computer_name, install_time, folder_id, protocol)) conn.commit() return {"status": "success"} @app.put("/api/install/{install_id}") def update_install(install_id: int, data: InstallData): - # Получаем текущие данные записи - cursor.execute("SELECT rust_id, computer_name, install_time, folder_id FROM installs WHERE id = ?", (install_id,)) + cursor.execute("SELECT rust_id, computer_name, install_time, folder_id, protocol FROM installs WHERE id = ?", (install_id,)) current = cursor.fetchone() if not current: raise HTTPException(status_code=404, detail="Запись не найдена") - # Обновляем только те поля, которые переданы new_rust_id = data.rust_id if data.rust_id is not None else current[0] new_computer_name = data.computer_name if data.computer_name is not None else current[1] new_install_time = data.install_time if data.install_time is not None else current[2] new_folder_id = data.folder_id if data.folder_id is not None else current[3] + new_protocol = data.protocol if data.protocol is not None else current[4] cursor.execute(""" UPDATE installs - SET rust_id = ?, computer_name = ?, install_time = ?, folder_id = ? + SET rust_id = ?, computer_name = ?, install_time = ?, folder_id = ?, protocol = ? WHERE id = ? - """, (new_rust_id, new_computer_name, new_install_time, new_folder_id, install_id)) + """, (new_rust_id, new_computer_name, new_install_time, new_folder_id, new_protocol, install_id)) conn.commit() return {"status": "success"} diff --git a/templates/index.html b/templates/index.html index 7361695..7e59193 100644 --- a/templates/index.html +++ b/templates/index.html @@ -21,6 +21,7 @@ .header div { flex: 1; text-align: center; } .header div:hover { background: #e0e0e0; } .sort-arrow { font-size: 12px; margin-left: 5px; } + .protocol-icon { margin-right: 5px; }
@@ -42,13 +43,21 @@