allow pdf attachments. serious business only.
Ted Unangst tedu@tedunangst.com
Thu, 31 Oct 2019 03:19:15 -0400
4 files changed,
38 insertions(+),
17 deletions(-)
M
docs/changelog.txt
→
docs/changelog.txt
@@ -2,6 +2,8 @@ changelog
-- next ++ Allow PDF attachments. For serious business only. + + "Untag" button to mute part of a thread. ++ Subscribe to hashtags.
M
docs/honk.5
→
docs/honk.5
@@ -91,7 +91,7 @@ .Pp
One may attach a file to a post. Images are automatically rescaled and reduced in size for federation. A description, or caption, is encouraged. -Text files are also supported as attachments. +Text files and PDFs are also supported as attachments. Other formats are not supported. .Pp One may also check in to a location.
M
views/honk.html
→
views/honk.html
@@ -65,7 +65,9 @@ {{ end }}
{{ range .Donks }} {{ if .Local }} {{ if eq .Media "text/plain" }} -<p><a href="/d/{{ .XID }}">Attachment: {{ .Name }}</a> +<p><a href="/d/{{ .XID }}">Attachment: {{ .Name }}</a> {{ .Desc }} +{{ else if eq .Media "application/pdf" }} +<p><a href="/d/{{ .XID }}">Attachment: {{ .Name }}</a> {{ .Desc }} {{ else }} <p><img src="/d/{{ .XID }}" title="{{ .Desc }}" alt="{{ .Desc }}"> {{ end }}
M
web.go
→
web.go
@@ -1310,25 +1310,42 @@ }
name = xid + "." + format xid = name } else { - maxsize := 100000 - if len(data) > maxsize { - log.Printf("bad image: %s too much text: %d", err, len(data)) - http.Error(w, "didn't like your attachment", http.StatusUnsupportedMediaType) - return - } - for i := 0; i < len(data); i++ { - if data[i] < 32 && data[i] != '\t' && data[i] != '\r' && data[i] != '\n' { - log.Printf("bad image: %s not text: %d", err, data[i]) + ct := http.DetectContentType(data) + switch ct { + case "application/pdf": + maxsize := 1000000 + if len(data) > maxsize { + log.Printf("bad image: %s too much pdf: %d", err, len(data)) + http.Error(w, "didn't like your attachment", http.StatusUnsupportedMediaType) + return + } + media = ct + xid += ".pdf" + name = filehdr.Filename + if name == "" { + name = xid + } + default: + maxsize := 100000 + if len(data) > maxsize { + log.Printf("bad image: %s too much text: %d", err, len(data)) http.Error(w, "didn't like your attachment", http.StatusUnsupportedMediaType) return } + for i := 0; i < len(data); i++ { + if data[i] < 32 && data[i] != '\t' && data[i] != '\r' && data[i] != '\n' { + log.Printf("bad image: %s not text: %d", err, data[i]) + http.Error(w, "didn't like your attachment", http.StatusUnsupportedMediaType) + return + } + } + media = "text/plain" + xid += ".txt" + name = filehdr.Filename + if name == "" { + name = xid + } } - media = "text/plain" - name = filehdr.Filename - if name == "" { - name = xid + ".txt" - } - xid += ".txt" } desc := strings.TrimSpace(r.FormValue("donkdesc")) if desc == "" {