Descarga de archivos implementada
This commit is contained in:
@@ -865,10 +865,16 @@ async def download_attachment(
|
||||
current_tenant: Tenant = Depends(get_current_tenant)
|
||||
):
|
||||
"""Descargar un archivo adjunto"""
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
logger.info(f"Download request - ticket_id: {ticket_id}, attachment_id: {attachment_id}")
|
||||
|
||||
try:
|
||||
ticket_uuid = uuid.UUID(ticket_id)
|
||||
attachment_uuid = uuid.UUID(attachment_id)
|
||||
except ValueError:
|
||||
logger.error(f"Invalid UUID format - ticket_id: {ticket_id}, attachment_id: {attachment_id}")
|
||||
raise HTTPException(status_code=400, detail="ID inválido")
|
||||
|
||||
# Verificar ticket
|
||||
@@ -878,6 +884,7 @@ async def download_attachment(
|
||||
ticket = result.scalar_one_or_none()
|
||||
|
||||
if not ticket:
|
||||
logger.error(f"Ticket not found - ticket_id: {ticket_id}")
|
||||
raise HTTPException(status_code=404, detail="Ticket no encontrado")
|
||||
|
||||
# Obtener attachment
|
||||
@@ -888,12 +895,26 @@ async def download_attachment(
|
||||
attachment = result.scalar_one_or_none()
|
||||
|
||||
if not attachment:
|
||||
logger.error(f"Attachment not found - attachment_id: {attachment_id}")
|
||||
raise HTTPException(status_code=404, detail="Adjunto no encontrado")
|
||||
|
||||
logger.info(f"Attachment found - file_path: {attachment.file_path}, original_filename: {attachment.original_filename}")
|
||||
|
||||
# Obtener path del archivo
|
||||
file_path = file_handler.get_file_path(attachment.file_path)
|
||||
try:
|
||||
file_path = file_handler.get_file_path(attachment.file_path)
|
||||
logger.info(f"Absolute file path: {file_path}")
|
||||
|
||||
if not file_path.exists():
|
||||
logger.error(f"File does not exist at path: {file_path}")
|
||||
raise HTTPException(status_code=404, detail="Archivo no encontrado en el sistema")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting file path: {str(e)}")
|
||||
raise
|
||||
|
||||
# Retornar archivo
|
||||
logger.info(f"Returning file: {attachment.original_filename}")
|
||||
return FileResponse(
|
||||
path=file_path,
|
||||
filename=attachment.original_filename,
|
||||
|
||||
Reference in New Issue
Block a user