mirror of
https://github.com/idrainformatica/PecFlow.git
synced 2026-06-16 12:45:42 +02:00
modifiche varie
This commit is contained in:
@@ -860,6 +860,64 @@ async def get_attachment_preview_url(
|
||||
}
|
||||
|
||||
|
||||
# ─── Feature 7b: Serve allegato inline per preview ───────────────────────────
|
||||
|
||||
@router.get("/{message_id}/attachments/{attachment_id}/inline")
|
||||
async def inline_attachment(
|
||||
message_id: uuid.UUID,
|
||||
attachment_id: uuid.UUID,
|
||||
current_user: CurrentUser,
|
||||
db: DB,
|
||||
):
|
||||
"""
|
||||
Serve l'allegato con Content-Disposition: inline per la preview nel browser.
|
||||
|
||||
Legge il file da MinIO internamente e lo restituisce attraverso il backend,
|
||||
evitando i problemi di accessibilita' con i presigned URL di MinIO in ambienti Docker.
|
||||
Supporta PDF e immagini; per altri tipi restituisce 404.
|
||||
"""
|
||||
await _resolve_message(message_id, current_user, db)
|
||||
|
||||
result = await db.execute(
|
||||
select(Attachment).where(
|
||||
Attachment.id == attachment_id,
|
||||
Attachment.message_id == message_id,
|
||||
)
|
||||
)
|
||||
attachment = result.scalar_one_or_none()
|
||||
if not attachment:
|
||||
raise NotFoundError(f"Allegato {attachment_id} non trovato")
|
||||
|
||||
content_type = attachment.content_type or "application/octet-stream"
|
||||
filename = attachment.filename.replace('"', "'")
|
||||
|
||||
try:
|
||||
from miniopy_async import Minio
|
||||
|
||||
client = Minio(
|
||||
endpoint=settings.minio_endpoint,
|
||||
access_key=settings.minio_access_key,
|
||||
secret_key=settings.minio_secret_key,
|
||||
secure=settings.minio_use_ssl,
|
||||
)
|
||||
response = await client.get_object(settings.minio_bucket, attachment.storage_path)
|
||||
data = await response.content.read()
|
||||
response.close()
|
||||
return StreamingResponse(
|
||||
iter([data]),
|
||||
media_type=content_type,
|
||||
headers={
|
||||
"Content-Disposition": f'inline; filename="{filename}"',
|
||||
"Content-Length": str(len(data)),
|
||||
},
|
||||
)
|
||||
except Exception as e:
|
||||
from app.core.logging import get_logger
|
||||
logger = get_logger(__name__)
|
||||
logger.error(f"Errore inline allegato {attachment_id}: {e}")
|
||||
raise NotFoundError("File non disponibile al momento")
|
||||
|
||||
|
||||
# ─── Feature 8: Stampa/export HTML ────────────────────────────────────────────
|
||||
|
||||
@router.get("/{message_id}/print")
|
||||
|
||||
Reference in New Issue
Block a user