simplify: show Open button only for PDF, remove DOCX conversion
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
PDF files: "Otwórz" (inline in browser) + "Pobierz" (download) DOCX files: "Pobierz" only (browsers can't display DOCX inline) Removes LibreOffice on-the-fly conversion - simpler and more reliable. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
da3e88cef1
commit
0e96dd80fa
@ -22,8 +22,6 @@ Endpoints - Documents:
|
||||
"""
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import tempfile
|
||||
from datetime import datetime
|
||||
from flask import (
|
||||
render_template, request, redirect, url_for, flash,
|
||||
@ -539,7 +537,7 @@ def document_download(doc_id):
|
||||
@login_required
|
||||
@rada_member_required
|
||||
def document_view(doc_id):
|
||||
"""Open a document inline in the browser (converts DOCX to PDF on the fly)"""
|
||||
"""Open a PDF document inline in the browser"""
|
||||
db = SessionLocal()
|
||||
try:
|
||||
doc = db.query(BoardDocument).filter(
|
||||
@ -560,39 +558,6 @@ def document_view(doc_id):
|
||||
flash('Plik dokumentu nie został znaleziony na serwerze.', 'error')
|
||||
return redirect(url_for('board.meeting_view', meeting_id=doc.meeting_id))
|
||||
|
||||
# DOCX/DOC: convert to PDF for inline viewing
|
||||
if doc.file_extension in ('docx', 'doc'):
|
||||
pdf_path = file_path.rsplit('.', 1)[0] + '.pdf'
|
||||
|
||||
# Convert only if cached PDF doesn't exist
|
||||
if not os.path.exists(pdf_path):
|
||||
try:
|
||||
result = subprocess.run(
|
||||
['/usr/bin/libreoffice', '--headless', '--convert-to', 'pdf',
|
||||
'--outdir', os.path.dirname(file_path), file_path],
|
||||
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ę 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. 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'
|
||||
return send_file(
|
||||
pdf_path,
|
||||
mimetype='application/pdf',
|
||||
as_attachment=False,
|
||||
download_name=pdf_name
|
||||
)
|
||||
|
||||
return send_file(
|
||||
file_path,
|
||||
mimetype=doc.mime_type,
|
||||
|
||||
@ -755,12 +755,14 @@
|
||||
{% if doc.uploader %}<br>{{ doc.uploader.name }}{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if doc.file_extension == 'pdf' %}
|
||||
<a href="{{ url_for('board.document_view', doc_id=doc.id) }}" target="_blank" class="btn-action btn-publish" style="font-size: var(--font-size-sm); padding: 6px 12px; margin-bottom: 4px;">
|
||||
<svg fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" style="width:14px;height:14px">
|
||||
<path d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/><path d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"/>
|
||||
</svg>
|
||||
Otwórz
|
||||
</a>
|
||||
{% endif %}
|
||||
<a href="{{ url_for('board.document_download', doc_id=doc.id) }}" class="btn-action btn-edit" style="font-size: var(--font-size-sm); padding: 6px 12px;">
|
||||
<svg fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" style="width:14px;height:14px">
|
||||
<path d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"/>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user