fixes and improvements
This commit is contained in:
@@ -16,11 +16,41 @@ from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import paramiko
|
||||
from media_library_viewer_api.config import get_settings
|
||||
|
||||
DEFAULT_SETTINGS_PATH = Path(".cache/media_library_viewer/settings.sqlite")
|
||||
LOCAL_MACHINE_ID = "local"
|
||||
DEFAULT_SERVICES = ["monitoring", "files", "jellyfin"]
|
||||
|
||||
|
||||
def _default_local_machine() -> dict[str, Any]:
|
||||
settings = get_settings()
|
||||
return {
|
||||
"id": LOCAL_MACHINE_ID,
|
||||
"name": "This machine",
|
||||
"mode": "local",
|
||||
"enabled": True,
|
||||
"services": list(DEFAULT_SERVICES),
|
||||
"host": "",
|
||||
"port": 22,
|
||||
"username": "",
|
||||
"key_directory": "",
|
||||
"key_name": "",
|
||||
"ssh_key_id": "",
|
||||
"ssh_private_key": "",
|
||||
"ssh_private_key_passphrase": "",
|
||||
"password": "",
|
||||
"media_root": settings.media_root,
|
||||
"path_prefix": settings.path_prefix,
|
||||
"jellyfin_url": settings.jellyfin_url,
|
||||
"jellyfin_user_id": settings.jellyfin_user_id,
|
||||
"jellyfin_api_key": settings.jellyfin_api_key or "",
|
||||
"jellyseerr_url": settings.jellyseerr_url,
|
||||
"jellyseerr_api_key": settings.jellyseerr_api_key or "",
|
||||
"notes": "",
|
||||
}
|
||||
|
||||
|
||||
class SettingsStore:
|
||||
"""SQLite-backed settings store for machine definitions and history."""
|
||||
|
||||
@@ -281,6 +311,48 @@ class SettingsStore:
|
||||
|
||||
def ensure_defaults(self) -> None:
|
||||
self.init_schema()
|
||||
with self.connect() as conn:
|
||||
row = conn.execute("SELECT COUNT(*) FROM monitoring_machines").fetchone()
|
||||
if row and int(row[0]) > 0:
|
||||
return
|
||||
machine = _default_local_machine()
|
||||
now = int(time.time())
|
||||
config = {
|
||||
"services": machine["services"],
|
||||
"host": machine["host"],
|
||||
"port": machine["port"],
|
||||
"username": machine["username"],
|
||||
"key_directory": machine["key_directory"],
|
||||
"key_name": machine["key_name"],
|
||||
"ssh_key_id": machine.get("ssh_key_id", ""),
|
||||
"ssh_private_key": "",
|
||||
"ssh_private_key_passphrase": "",
|
||||
"password": "",
|
||||
"media_root": machine["media_root"],
|
||||
"path_prefix": machine["path_prefix"],
|
||||
"jellyfin_url": machine["jellyfin_url"],
|
||||
"jellyfin_user_id": machine["jellyfin_user_id"],
|
||||
"jellyfin_api_key": machine["jellyfin_api_key"],
|
||||
"jellyseerr_url": machine["jellyseerr_url"],
|
||||
"jellyseerr_api_key": machine["jellyseerr_api_key"],
|
||||
"notes": machine["notes"],
|
||||
}
|
||||
with self.connect() as conn:
|
||||
conn.execute(
|
||||
"""
|
||||
INSERT INTO monitoring_machines (id, name, mode, enabled, config_json, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
(
|
||||
machine["id"],
|
||||
machine["name"],
|
||||
machine["mode"],
|
||||
1,
|
||||
json.dumps(config),
|
||||
now,
|
||||
now,
|
||||
),
|
||||
)
|
||||
|
||||
def list_machines(self) -> list[dict[str, Any]]:
|
||||
self.ensure_defaults()
|
||||
|
||||
Reference in New Issue
Block a user