55 lines
1.5 KiB
Python
55 lines
1.5 KiB
Python
from dataclasses import dataclass, field
|
|
|
|
import db
|
|
|
|
|
|
@dataclass
|
|
class SFTPConfig:
|
|
host: str = ""
|
|
port: int = 22
|
|
user: str = ""
|
|
auth_method: str = "key" # "key" or "password"
|
|
key: str = ""
|
|
password: str = ""
|
|
remote_path: str = ""
|
|
|
|
|
|
@dataclass
|
|
class AppConfig:
|
|
sftp: SFTPConfig = field(default_factory=SFTPConfig)
|
|
work_dir: str = "/tmp/calibresync"
|
|
import_dir: str = ""
|
|
|
|
|
|
def load() -> AppConfig:
|
|
s = db.get_all_settings()
|
|
return AppConfig(
|
|
sftp=SFTPConfig(
|
|
host=s.get("sftp_host", ""),
|
|
port=int(s.get("sftp_port", "22")),
|
|
user=s.get("sftp_user", ""),
|
|
auth_method=s.get("sftp_auth_method", "key"),
|
|
key=s.get("sftp_key", ""),
|
|
password=s.get("sftp_password", ""),
|
|
remote_path=s.get("sftp_remote_path", ""),
|
|
),
|
|
work_dir=s.get("work_dir", "/tmp/calibresync"),
|
|
import_dir=s.get("import_dir", ""),
|
|
)
|
|
|
|
|
|
def save(form: dict) -> None:
|
|
keys = [
|
|
"sftp_host", "sftp_port", "sftp_user", "sftp_auth_method",
|
|
"sftp_password", "sftp_remote_path",
|
|
"work_dir", "import_dir",
|
|
"scheduler_interval_minutes", "sync_batch_size",
|
|
]
|
|
for key in keys:
|
|
if key in form and form[key] is not None:
|
|
db.set_setting(key, str(form[key]))
|
|
|
|
# Only overwrite the SSH key if a non-empty value was submitted
|
|
if form.get("sftp_key", "").strip():
|
|
db.set_setting("sftp_key", form["sftp_key"].strip())
|