Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

4.3 KB
Raw Blame
"""Backup status warning checks.

Pure functions that take primitive values and return warning dicts (or None).
"""

from typing import Optional

from ...config.paths import MODE_NOT_KEPT, OWNED_BY_ANOTHER_ACCOUNT

_REPORT_BACKUP_CAUSES = {
    OWNED_BY_ANOTHER_ACCOUNT: (
        "another OS account owns the server's research_outputs folder, as "
        "with Docker Desktop bind mounts of Windows folders or after the app "
        "ran as a different user"
    ),
    MODE_NOT_KEPT: (
        "the filesystem holding the server's research_outputs folder does not "
        "keep owner-only permissions, as on WSL drives such as /mnt/c, "
        "CIFS/SMB shares and exFAT"
    ),
}


def check_report_backup_unavailable(
    backup_enabled: bool, problem: Optional[str]
) -> Optional[dict]:
    """Warn that report file backups are refused although they are enabled.

    ``problem`` is None when the folder is private, a
    ``DirectoryNotPrivateError.reason``, or any other string when the folder
    could not be prepared at all. Not dismissible: it shows while the
    setting is on and FileReportStorage would refuse the folder.
    """
    if not backup_enabled or problem is None:
        return None
    cause = _REPORT_BACKUP_CAUSES.get(
        problem,
        "the server could not make its research_outputs folder private "
        "(the server log names the cause when a report is saved)",
    )
    return {
        "type": "report_backup_unavailable",
        "icon": "⚠️",
        "title": "Report File Backups Disabled",
        "message": (
            "Report file backup is on, but no report files are being "
            f"written because {cause}. Reports are still saved in the "
            "database. Keep the data directory (LDR_DATA_DIR) on a Linux "
            "filesystem path or a Docker named volume owned by the account "
            "that runs the app, or turn off report file backup."
        ),
        "dismissKey": None,
        "actionUrl": "/settings#setting-report-enable_file_backup",
        "actionLabel": "Open report backup setting",
    }


def check_backup_disabled(
    backup_enabled: bool, dismissed: bool
) -> Optional[dict]:
    """Warn if automatic backups are disabled."""
    if backup_enabled:
        return None
    if dismissed:
        return None

    return {
        "type": "backup_disabled",
        "icon": "💾",
        "title": "Database Backups Disabled",
        "message": (
            "Automatic database backups are disabled. Without backups, "
            "data cannot be recovered if the database is corrupted. "
            "Enable backups in Settings \u203a Backup."
        ),
        "dismissKey": "app.warnings.dismiss_backup_disabled",
    }


def check_no_backups_exist(
    backup_enabled: bool, backup_count: int, dismissed: bool
) -> Optional[dict]:
    """Warn if backups are enabled but none exist yet."""
    if not backup_enabled:
        return None
    if backup_count > 0:
        return None
    if dismissed:
        return None

    return {
        "type": "no_backups",
        "icon": "📁",
        "title": "No Backups Found",
        "message": (
            "No database backups have been created yet. A backup will "
            "be created automatically on your next login. You can "
            "configure backup settings in Settings \u203a Backup."
        ),
        "dismissKey": "app.warnings.dismiss_no_backups",
    }


def check_backup_healthy(
    backup_enabled: bool,
    backup_count: int,
    total_size_human: str,
    dismissed: bool,
) -> Optional[dict]:
    """Show positive backup status info (dismissable)."""
    if not backup_enabled:
        return None
    if backup_count == 0:
        return None
    if dismissed:
        return None

    return {
        "type": "backup_info",
        "icon": "✅",
        "title": "Database Backup Active",
        "message": (
            f"{backup_count} backup{'s' if backup_count > 1 else ''} "
            f"({total_size_human}) on disk. Encrypted backups cannot be "
            "compressed, so each backup equals your database size "
            "(which can be large if PDFs are stored in the database). "
            "Backups are created once per day on login. Manage backups "
            "in Settings \u203a Backup."
        ),
        "dismissKey": "app.warnings.dismiss_backup_info",
    }