fix: show correct server in backup stats
This commit is contained in:
parent
5b31b7fc50
commit
e27c84b072
2 changed files with 15 additions and 27 deletions
|
|
@ -121,20 +121,16 @@ class BackupPane(Container):
|
||||||
self._update_ui(f"[red]Error: {e}[/red]", "", "", False, False)
|
self._update_ui(f"[red]Error: {e}[/red]", "", "", False, False)
|
||||||
|
|
||||||
def _get_backup_info(self) -> str | None:
|
def _get_backup_info(self) -> str | None:
|
||||||
base_dir = Path(f"ReaperFiles-{self.cfg_name}")
|
if not self.config or not self.config.discord_server_id:
|
||||||
if not base_dir.exists():
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
target_dir = None
|
target_dir = Path(f"ReaperFiles-{self.cfg_name}") / f"DISCORD_BACKUP-{self.config.discord_server_id}"
|
||||||
for child in base_dir.iterdir():
|
if not target_dir.exists():
|
||||||
if child.is_dir() and (child / "server_profile" / "profile.json").exists():
|
|
||||||
target_dir = child
|
|
||||||
break
|
|
||||||
|
|
||||||
if not target_dir:
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
profile_file = target_dir / "server_profile" / "profile.json"
|
profile_file = target_dir / "server_profile" / "profile.json"
|
||||||
|
if not profile_file.exists():
|
||||||
|
return None
|
||||||
try:
|
try:
|
||||||
with open(profile_file, "r", encoding="utf-8") as f:
|
with open(profile_file, "r", encoding="utf-8") as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
|
|
@ -183,7 +179,8 @@ class BackupPane(Container):
|
||||||
self.run_backup_sync()
|
self.run_backup_sync()
|
||||||
elif bid == "bp_backup_stats":
|
elif bid == "bp_backup_stats":
|
||||||
from src.ui.backup_stats import BackupStatsScreen
|
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 ───────────────────────────────────────────────────────────
|
# ── workers ───────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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)
|
super().__init__(*args, **kwargs)
|
||||||
self.profile_name = profile_name
|
self.profile_name = profile_name
|
||||||
self.base_dir = Path(f"ReaperFiles-{self.profile_name}")
|
self.target_dir = target_dir
|
||||||
self.profile_path = None
|
self.profile_path = None
|
||||||
self.backup_path = None
|
self.backup_path = None
|
||||||
|
|
||||||
|
|
@ -252,22 +252,13 @@ class BackupStatsScreen(Screen[None]):
|
||||||
@work(exclusive=True)
|
@work(exclusive=True)
|
||||||
async def load_data(self) -> None:
|
async def load_data(self) -> None:
|
||||||
try:
|
try:
|
||||||
# Locate the correct backup directory inside base_dir
|
# Locate the correct backup directory passed from backup_ops
|
||||||
if not self.base_dir.exists():
|
if not self.target_dir.exists():
|
||||||
raise FileNotFoundError(f"Config directory {self.base_dir} not found.")
|
raise FileNotFoundError(f"Config directory {self.target_dir} not found.")
|
||||||
|
|
||||||
target_dir = None
|
target_dir = self.target_dir
|
||||||
# The exporter creates directories like DISCORD_BACKUP-<id> or <name>-<id>
|
if not (target_dir / "server_profile" / "profile.json").exists():
|
||||||
# We look for the first one that contains a server_profile
|
raise FileNotFoundError(f"No valid backup found in {self.target_dir}")
|
||||||
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}")
|
|
||||||
|
|
||||||
self.profile_path = target_dir / "server_profile"
|
self.profile_path = target_dir / "server_profile"
|
||||||
self.backup_path = target_dir / "message_backup"
|
self.backup_path = target_dir / "message_backup"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue