mirror of
https://github.com/MarekWo/mc-webui.git
synced 2026-03-28 17:42:45 +01:00
feat(v2): Add v2 config settings (DB, TCP, backup)
New environment variables for Phase 0: - MC_DB_PATH: SQLite database location - MC_TCP_HOST/MC_TCP_PORT: TCP transport (meshcore-proxy) - MC_BACKUP_ENABLED/HOUR/RETENTION_DAYS: automated backup - MC_AUTO_RECONNECT, MC_LOG_LEVEL: connection management Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -18,14 +18,30 @@ class Config:
|
||||
MC_DEVICE_NAME = os.getenv('MC_DEVICE_NAME', 'MeshCore')
|
||||
MC_CONFIG_DIR = os.getenv('MC_CONFIG_DIR', '/root/.config/meshcore')
|
||||
|
||||
# MeshCore Bridge configuration
|
||||
# MeshCore Bridge configuration (v1 — will be removed in Phase 1)
|
||||
MC_BRIDGE_URL = os.getenv('MC_BRIDGE_URL', 'http://meshcore-bridge:5001/cli')
|
||||
|
||||
# Archive configuration
|
||||
# Archive configuration (v1 — archives move to SQLite in v2)
|
||||
MC_ARCHIVE_DIR = os.getenv('MC_ARCHIVE_DIR', '/root/.archive/meshcore')
|
||||
MC_ARCHIVE_ENABLED = os.getenv('MC_ARCHIVE_ENABLED', 'true').lower() == 'true'
|
||||
MC_ARCHIVE_RETENTION_DAYS = int(os.getenv('MC_ARCHIVE_RETENTION_DAYS', '7'))
|
||||
|
||||
# v2: Database
|
||||
MC_DB_PATH = os.getenv('MC_DB_PATH', '') # empty = auto: {MC_CONFIG_DIR}/mc-webui.db
|
||||
|
||||
# v2: TCP connection (alternative to serial, e.g. meshcore-proxy)
|
||||
MC_TCP_HOST = os.getenv('MC_TCP_HOST', '') # empty = use serial
|
||||
MC_TCP_PORT = int(os.getenv('MC_TCP_PORT', '5000'))
|
||||
|
||||
# v2: Backup
|
||||
MC_BACKUP_ENABLED = os.getenv('MC_BACKUP_ENABLED', 'true').lower() == 'true'
|
||||
MC_BACKUP_HOUR = int(os.getenv('MC_BACKUP_HOUR', '2'))
|
||||
MC_BACKUP_RETENTION_DAYS = int(os.getenv('MC_BACKUP_RETENTION_DAYS', '7'))
|
||||
|
||||
# v2: Connection
|
||||
MC_AUTO_RECONNECT = os.getenv('MC_AUTO_RECONNECT', 'true').lower() == 'true'
|
||||
MC_LOG_LEVEL = os.getenv('MC_LOG_LEVEL', 'INFO')
|
||||
|
||||
# Flask server configuration
|
||||
FLASK_HOST = os.getenv('FLASK_HOST', '0.0.0.0')
|
||||
FLASK_PORT = int(os.getenv('FLASK_PORT', '5000'))
|
||||
@@ -42,10 +58,23 @@ class Config:
|
||||
"""Get the full path to archive directory"""
|
||||
return Path(self.MC_ARCHIVE_DIR)
|
||||
|
||||
@property
|
||||
def db_path(self) -> Path:
|
||||
"""Get SQLite database path"""
|
||||
if self.MC_DB_PATH:
|
||||
return Path(self.MC_DB_PATH)
|
||||
return Path(self.MC_CONFIG_DIR) / 'mc-webui.db'
|
||||
|
||||
@property
|
||||
def use_tcp(self) -> bool:
|
||||
"""True if TCP transport should be used instead of serial"""
|
||||
return bool(self.MC_TCP_HOST)
|
||||
|
||||
def __repr__(self):
|
||||
transport = f"tcp={self.MC_TCP_HOST}:{self.MC_TCP_PORT}" if self.use_tcp else f"serial={self.MC_SERIAL_PORT}"
|
||||
return (
|
||||
f"Config(device={self.MC_DEVICE_NAME}, "
|
||||
f"port={self.MC_SERIAL_PORT}, "
|
||||
f"{transport}, "
|
||||
f"config_dir={self.MC_CONFIG_DIR})"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user