diff options
author | Jordan <me@jordan.im> | 2022-02-22 18:17:00 -0700 |
---|---|---|
committer | Jordan <me@jordan.im> | 2022-02-22 18:17:00 -0700 |
commit | 92c560e4e8ba5bc90b4d99d324862c86f9a8e691 (patch) | |
tree | a42d4c89a40eb5b0924bfd88ce8cddd241b48922 | |
parent | 2d4c63100d3bf39bdbcce588fe361ab39d77ea0a (diff) | |
download | crane-92c560e4e8ba5bc90b4d99d324862c86f9a8e691.tar.gz crane-92c560e4e8ba5bc90b4d99d324862c86f9a8e691.zip |
util.go: paper download sanity checks; extension, content-type
-rw-r--r-- | util.go | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -280,8 +280,10 @@ func getPaper(client *http.Client, u string) (string, error) { if err != nil { continue } - _u.Path = _v.Path - dl = _u + if strings.HasSuffix(_v.Path, "pdf") { + _u.Path = _v.Path + dl = _u + } } } } @@ -300,6 +302,10 @@ func getPaper(client *http.Client, u string) (string, error) { return "", err } + if resp.Header.Get("content-type") != "application/pdf" { + return "", fmt.Errorf("%q: parsed PDF direct link not application/pdf", u) + } + tmpPDF, err := ioutil.TempFile("", "tmp-*.pdf") if err != nil { return "", err |