import json from pathlib import Path DEFAULT_SAVE_ROOT = "/mnt/svr-01/storage/records" SETTINGS_FILE = Path("/mnt/storage/document-processor/settings/storage.json") def _ensure_parent() -> None: SETTINGS_FILE.parent.mkdir(parents=True, exist_ok=True) def get_default_save_root() -> str: try: if SETTINGS_FILE.exists(): data = json.loads(SETTINGS_FILE.read_text()) value = str(data.get("default_save_root") or "").strip() if value: return value except Exception: pass return DEFAULT_SAVE_ROOT def set_default_save_root(path_str: str) -> str: value = str(path_str or "").strip() or DEFAULT_SAVE_ROOT _ensure_parent() SETTINGS_FILE.write_text(json.dumps({"default_save_root": value}, indent=2)) return value def reset_default_save_root() -> str: _ensure_parent() SETTINGS_FILE.write_text(json.dumps({"default_save_root": DEFAULT_SAVE_ROOT}, indent=2)) return DEFAULT_SAVE_ROOT