From e27c84b072c9da6fcd717f4073ae1250f3e87a65 Mon Sep 17 00:00:00 2001 From: rambros Date: Thu, 12 Mar 2026 14:34:44 +0530 Subject: [PATCH] fix: show correct server in backup stats --- src/ui/backup_ops.py | 17 +++++++---------- src/ui/backup_stats.py | 25 ++++++++----------------- 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/src/ui/backup_ops.py b/src/ui/backup_ops.py index d7a08df..a0c3c9e 100644 --- a/src/ui/backup_ops.py +++ b/src/ui/backup_ops.py @@ -121,20 +121,16 @@ class BackupPane(Container): self._update_ui(f"[red]Error: {e}[/red]", "", "", False, False) def _get_backup_info(self) -> str | None: - base_dir = Path(f"ReaperFiles-{self.cfg_name}") - if not base_dir.exists(): + if not self.config or not self.config.discord_server_id: return None - target_dir = None - for child in base_dir.iterdir(): - if child.is_dir() and (child / "server_profile" / "profile.json").exists(): - target_dir = child - break - - if not target_dir: + target_dir = Path(f"ReaperFiles-{self.cfg_name}") / f"DISCORD_BACKUP-{self.config.discord_server_id}" + if not target_dir.exists(): return None profile_file = target_dir / "server_profile" / "profile.json" + if not profile_file.exists(): + return None try: with open(profile_file, "r", encoding="utf-8") as f: data = json.load(f) @@ -183,7 +179,8 @@ class BackupPane(Container): self.run_backup_sync() elif bid == "bp_backup_stats": from src.ui.backup_stats import BackupStatsScreen - self.app.push_screen(BackupStatsScreen(self.cfg_name)) + target_dir = Path(f"ReaperFiles-{self.cfg_name}") / f"DISCORD_BACKUP-{self.config.discord_server_id}" + self.app.push_screen(BackupStatsScreen(self.cfg_name, target_dir)) # ── workers ─────────────────────────────────────────────────────────── diff --git a/src/ui/backup_stats.py b/src/ui/backup_stats.py index b34ad4c..71fe48e 100644 --- a/src/ui/backup_stats.py +++ b/src/ui/backup_stats.py @@ -148,10 +148,10 @@ class BackupStatsScreen(Screen[None]): } """ - def __init__(self, profile_name: str, *args, **kwargs): + def __init__(self, profile_name: str, target_dir: Path, *args, **kwargs): super().__init__(*args, **kwargs) self.profile_name = profile_name - self.base_dir = Path(f"ReaperFiles-{self.profile_name}") + self.target_dir = target_dir self.profile_path = None self.backup_path = None @@ -252,22 +252,13 @@ class BackupStatsScreen(Screen[None]): @work(exclusive=True) async def load_data(self) -> None: try: - # Locate the correct backup directory inside base_dir - if not self.base_dir.exists(): - raise FileNotFoundError(f"Config directory {self.base_dir} not found.") + # Locate the correct backup directory passed from backup_ops + if not self.target_dir.exists(): + raise FileNotFoundError(f"Config directory {self.target_dir} not found.") - target_dir = None - # The exporter creates directories like DISCORD_BACKUP- or - - # We look for the first one that contains a server_profile - for child in self.base_dir.iterdir(): - if child.is_dir() and (child / "server_profile" / "profile.json").exists(): - target_dir = child - # If it's a recent backup, prefer it. We'll simply grab the first valid one if multiple exist. - # Usually there's only one valid backup per profile. - break - - if not target_dir: - raise FileNotFoundError(f"No valid backup found in {self.base_dir}") + target_dir = self.target_dir + if not (target_dir / "server_profile" / "profile.json").exists(): + raise FileNotFoundError(f"No valid backup found in {self.target_dir}") self.profile_path = target_dir / "server_profile" self.backup_path = target_dir / "message_backup"