From 817897c42c57c1d9aedbfae0f0b589e5864fac80 Mon Sep 17 00:00:00 2001 From: Ian Lai Date: Wed, 24 Oct 2018 21:29:29 +0100 Subject: [PATCH] Fix `weaver` local conversion treating HTML files as plaintext Due to a recent upgrade (f59e999), Chromium (via Electron) is not automatically detecting HTML files by the contents. Instead, the extension of the file must be set for it to be treated as (M)HTML. Thus, this commit sets the default file extension to `html` unless otherwise specified using the `ext` argument (see b1a16ac8). This is so that files will not be treated as plaintext, and so we will not end up converting HTML to a PDF showing the raw HTML, but rather the rendered HTML. For debugging purposes, the name of the temporary file now includes `athena` for easy identification in the temporary directory. --- weaver/converter/source.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/weaver/converter/source.go b/weaver/converter/source.go index 57e39702..7eed60a6 100644 --- a/weaver/converter/source.go +++ b/weaver/converter/source.go @@ -50,7 +50,7 @@ func readerContentType(r io.Reader) (string, error) { // It returns the full temporary file path, and its mime type if successful. func readerTmpFile(r io.Reader) (string, string, error) { // Create a temporary file - f, err := ioutil.TempFile("/tmp", "tmp") + f, err := ioutil.TempFile("/tmp", "athena.tmp.*") if err != nil { return "", "", err } @@ -171,6 +171,10 @@ func NewConversionSource(uri string, body io.Reader, ext string) (*ConversionSou return nil, err } + if ext == "" { + ext = "html" + } + if err := setCustomExtension(s, ext); err != nil { return nil, err }