aboutsummaryrefslogtreecommitdiff
path: root/util.go
diff options
context:
space:
mode:
authorJordan <me@jordan.im>2022-02-22 18:17:00 -0700
committerJordan <me@jordan.im>2022-02-22 18:17:00 -0700
commit92c560e4e8ba5bc90b4d99d324862c86f9a8e691 (patch)
treea42d4c89a40eb5b0924bfd88ce8cddd241b48922 /util.go
parent2d4c63100d3bf39bdbcce588fe361ab39d77ea0a (diff)
downloadcrane-92c560e4e8ba5bc90b4d99d324862c86f9a8e691.tar.gz
crane-92c560e4e8ba5bc90b4d99d324862c86f9a8e691.zip
util.go: paper download sanity checks; extension, content-type
Diffstat (limited to 'util.go')
-rw-r--r--util.go10
1 files 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