fix: make host paths configurable and add recursive search fallback for destruct mode
All checks were successful
Docker Build / build (push) Successful in 13s

This commit is contained in:
wander 2026-03-08 06:03:04 -04:00
parent e99d21fac7
commit b57aecf7cb

View file

@ -24,6 +24,7 @@ TARGET_DIR = Path("/app/target")
HIDDEN_DIR = Path("/app/hidden") HIDDEN_DIR = Path("/app/hidden")
IMPORT_DIR = Path("/app/import") IMPORT_DIR = Path("/app/import")
DATA_DIR = Path("/app/data") DATA_DIR = Path("/app/data")
HOST_SOURCE_BASE = Path(os.getenv("HOST_SOURCE_BASE", "/mnt/user/tubearchives/bp"))
HEADERS = {"Authorization": f"Token {API_TOKEN}"} HEADERS = {"Authorization": f"Token {API_TOKEN}"}
# Serve static files from ui/dist # Serve static files from ui/dist
@ -130,6 +131,12 @@ def translate_host_path(host_path):
rel = host_path_str[len(host_prefix):].lstrip("/") rel = host_path_str[len(host_prefix):].lstrip("/")
return SOURCE_DIR / rel return SOURCE_DIR / rel
# Generic fallback: if it starts with the configured HOST_SOURCE_BASE
host_base_str = str(HOST_SOURCE_BASE)
if host_path_str.startswith(host_base_str):
rel = host_path_str[len(host_base_str):].lstrip("/")
return SOURCE_DIR / rel
return Path(host_path) return Path(host_path)
def tlog(msg): def tlog(msg):
@ -846,7 +853,7 @@ def process_videos():
folder_name = f"{meta['published']} - {sanitized_title}" folder_name = f"{meta['published']} - {sanitized_title}"
video_dir = channel_dir / folder_name video_dir = channel_dir / folder_name
host_path_root = Path("/mnt/user/tubearchives/bp") host_path_root = HOST_SOURCE_BASE
host_source_path = host_path_root / video_file.relative_to(SOURCE_DIR) host_source_path = host_path_root / video_file.relative_to(SOURCE_DIR)
dest_file = video_dir / f"video{video_file.suffix}" dest_file = video_dir / f"video{video_file.suffix}"
@ -1230,6 +1237,16 @@ def api_recovery_delete_batch():
source_path = translate_ta_path(raw_ta_path) source_path = translate_ta_path(raw_ta_path)
log(f" [DESTRUCT] API Fallback Path: {source_path}") log(f" [DESTRUCT] API Fallback Path: {source_path}")
# --- Method C: Recursive Search Fallback (Safety net) ---
if not source_path or not source_path.exists():
log(f" [DESTRUCT] Final fallback: recursive search for ID {vid_id or 'unknown'}")
if vid_id:
for candidate in SOURCE_DIR.rglob(f"*{vid_id}*"):
if candidate.is_file():
source_path = candidate
log(f" [DESTRUCT] Search found match: {source_path}")
break
# --- Execution: Delete the identified source --- # --- Execution: Delete the identified source ---
if source_path and source_path.exists(): if source_path and source_path.exists():
try: try: