Coreccion del cliente para descargar los archivos multimedia
This commit is contained in:
@@ -244,8 +244,10 @@ def sync_from_hub_task():
|
||||
# Download assets after bulk update (Polling)
|
||||
from .utils import download_file_from_hub, sync_assets_from_content
|
||||
for art_data in articles_data:
|
||||
if art_data.get('file_url'):
|
||||
# art_data contains the virtual fields because it was dumped via HelpArticleInDB
|
||||
if "file_url" in art_data and art_data['file_url']:
|
||||
download_file_from_hub(art_data['file_url'])
|
||||
|
||||
sync_assets_from_content(art_data.get('content', ''))
|
||||
|
||||
logger.info("Polling sync completed successfully.")
|
||||
|
||||
@@ -29,6 +29,7 @@ def download_file_from_hub(relative_path: str) -> bool:
|
||||
|
||||
local_path = Path(clean_path)
|
||||
if local_path.exists():
|
||||
logger.info(f"File {clean_path} already exists, skipping download.")
|
||||
return True
|
||||
|
||||
# Ensure directories exist
|
||||
@@ -38,7 +39,9 @@ def download_file_from_hub(relative_path: str) -> bool:
|
||||
# CENTRAL_SERVER_URL is usually http://hub:8000/api/v1/core/help-center/sync/
|
||||
# We want http://hub:8000/api/
|
||||
base_url = settings.CENTRAL_SERVER_URL.split("/v1/")[0]
|
||||
hub_file_url = f"{base_url}/uploads/{clean_path.replace('uploads/', '')}"
|
||||
# The file in backend is served usually under /api/uploads/...
|
||||
# But clean_path is just "uploads/...". So the Hub route is base_url + "/" + clean_path
|
||||
hub_file_url = f"{base_url}/{clean_path}"
|
||||
|
||||
logger.info(f"Downloading asset from Hub: {hub_file_url} -> {local_path}")
|
||||
|
||||
@@ -51,7 +54,7 @@ def download_file_from_hub(relative_path: str) -> bool:
|
||||
logger.info(f"Successfully downloaded {clean_path}")
|
||||
return True
|
||||
else:
|
||||
logger.warning(f"Failed to download {clean_path}: Status {response.status_code}")
|
||||
logger.warning(f"Failed to download {clean_path}: Status {response.status_code} URL: {hub_file_url}")
|
||||
return False
|
||||
except Exception as e:
|
||||
logger.error(f"Error downloading {clean_path}: {str(e)}")
|
||||
|
||||
Reference in New Issue
Block a user