Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
Fix weaver local conversion treating HTML files as plaintext
Browse files Browse the repository at this point in the history
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 b1a16ac). 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.
  • Loading branch information
MrSaints committed Oct 24, 2018
1 parent f78ca39 commit 817897c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion weaver/converter/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down

1 comment on commit 817897c

@MrSaints
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc: @sanohin

Please sign in to comment.