fix: use absolute path for libreoffice and handle errors gracefully
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
- Use /usr/bin/libreoffice (Gunicorn has limited PATH) - Set HOME=/tmp (LibreOffice needs writable home dir) - Handle FileNotFoundError with user-friendly message - Improve error flash messages in Polish Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
52eb79f87d
commit
da3e88cef1
@ -568,16 +568,21 @@ def document_view(doc_id):
|
||||
if not os.path.exists(pdf_path):
|
||||
try:
|
||||
result = subprocess.run(
|
||||
['libreoffice', '--headless', '--convert-to', 'pdf',
|
||||
['/usr/bin/libreoffice', '--headless', '--convert-to', 'pdf',
|
||||
'--outdir', os.path.dirname(file_path), file_path],
|
||||
capture_output=True, timeout=30
|
||||
capture_output=True, timeout=30,
|
||||
env={**os.environ, 'HOME': '/tmp'}
|
||||
)
|
||||
if result.returncode != 0:
|
||||
current_app.logger.error(f"DOCX to PDF conversion failed: {result.stderr.decode()}")
|
||||
flash('Nie udało się przekonwertować dokumentu do PDF.', 'error')
|
||||
flash('Nie udało się otworzyć dokumentu — konwersja do PDF nie powiodła się.', 'error')
|
||||
return redirect(url_for('board.meeting_view', meeting_id=doc.meeting_id))
|
||||
except FileNotFoundError:
|
||||
current_app.logger.error("LibreOffice not found at /usr/bin/libreoffice")
|
||||
flash('Podgląd dokumentów Word nie jest dostępny na tym serwerze. Użyj przycisku „Pobierz".', 'error')
|
||||
return redirect(url_for('board.meeting_view', meeting_id=doc.meeting_id))
|
||||
except subprocess.TimeoutExpired:
|
||||
flash('Konwersja dokumentu trwała za długo.', 'error')
|
||||
flash('Konwersja dokumentu trwała za długo. Użyj przycisku „Pobierz".', 'error')
|
||||
return redirect(url_for('board.meeting_view', meeting_id=doc.meeting_id))
|
||||
|
||||
pdf_name = doc.original_filename.rsplit('.', 1)[0] + '.pdf'
|
||||
|
||||
Loading…
Reference in New Issue
Block a user