From fc62d77131debf57124310e5d37080e2067b8105 Mon Sep 17 00:00:00 2001 From: Michael Sitz Date: Thu, 20 Aug 2026 16:41:20 -0400 Subject: [PATCH] PDF inline fix 1 --- offlineu_core.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/offlineu_core.py b/offlineu_core.py index 75a95c1..c4c18eb 100644 --- a/offlineu_core.py +++ b/offlineu_core.py @@ -725,12 +725,29 @@ def serve_file(filepath): print(f"Serving file: {full_path}") - # Determine MIME type - mime_type, _ = mimetypes.guess_type(full_path) - if mime_type is None: - mime_type = 'application/octet-stream' + # Determine MIME type. Don't rely solely on mimetypes.guess_type() - + # its results can vary by OS/container base image depending on what + # system mime databases are present. Force the types that matter for + # inline preview (PDF above all) so this can't silently regress. + ext = os.path.splitext(full_path)[1].lower() + KNOWN_MIME_TYPES = { + '.pdf': 'application/pdf', + '.html': 'text/html', + '.htm': 'text/html', + '.txt': 'text/plain', + '.md': 'text/plain', + } + if ext in KNOWN_MIME_TYPES: + mime_type = KNOWN_MIME_TYPES[ext] + else: + mime_type, _ = mimetypes.guess_type(full_path) + if mime_type is None: + mime_type = 'application/octet-stream' - return send_file(full_path, mimetype=mime_type) + # as_attachment=False (the default) sends Content-Disposition: inline + # so the browser renders PDFs/HTML in the iframe instead of prompting + # a download. Being explicit here so this can't drift. + return send_file(full_path, mimetype=mime_type, as_attachment=False) except Exception as e: print(f"Error serving file: {str(e)}") return f"Error serving file: {str(e)}", 500