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