From 92c560e4e8ba5bc90b4d99d324862c86f9a8e691 Mon Sep 17 00:00:00 2001 From: Jordan Date: Tue, 22 Feb 2022 18:17:00 -0700 Subject: util.go: paper download sanity checks; extension, content-type --- util.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/util.go b/util.go index 0ce512f..5d5de44 100644 --- a/util.go +++ b/util.go @@ -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 -- cgit v1.2.3-54-g00ecf