[18.0][attachment_preview] Add Office format preview via LibreOffice conversion#603
Open
[18.0][attachment_preview] Add Office format preview via LibreOffice conversion#603
Conversation
…ffice Extends attachment_preview to support DOCX, XLSX, PPTX, DOC, XLS, PPT, and ODG in addition to the existing PDF + ODF format support. New endpoint: GET /attachment_preview/office_to_pdf Accepts ?model=<model>&field=<field>&id=<id>&filename=<name> Converts the binary field content to PDF using LibreOffice headless, then streams the PDF to ViewerJS for in-browser rendering. Returns HTTP 503 gracefully if LibreOffice is not installed. Changes: - controllers/main.py: new HTTP controller with LibreOffice conversion - utils.esm.js: OFFICE_EXTENSIONS added to canPreview(); getUrl() routes Office files to the conversion endpoint - binary_field.esm.js: passes filename for correct extension detection - tests: controller unit tests covering success, FileNotFoundError, TimeoutExpired, and non-zero exit code paths Closes OCA#603
8702c2f to
d9a4a06
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extends
attachment_previewto support DOCX, XLSX, PPTX, DOC, XLS, PPT, and ODG preview in addition to the existing PDF + ODF support.How it works
GET /attachment_preview/office_to_pdf?model=&field=&id=&filename=libreoffice --headless --convert-to pdf)Changes
controllers/main.pystatic/src/js/utils.esm.jsOFFICE_EXTENSIONSadded tocanPreview();getUrl()routes Office extensions through conversion endpoint with?type=pdffor ViewerJSstatic/src/js/web_views/fields/binary_field.esm.jsfilenametoshowPreview()so conversion endpoint receives correct extensionRequirements
subprocess,tempfile)Test plan
.docxfile to a record with a binary field → preview button (↗) appears.xlsx/.pptx→ same behavior🤖 Generated with Claude Code