diff --git a/docs/changelog.txt b/docs/changelog.txt index 1d9c59f..1c917c1 100644 --- a/docs/changelog.txt +++ b/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. diff --git a/docs/honk.5 b/docs/honk.5 index c9609e1..7df35d3 100644 --- a/docs/honk.5 +++ b/docs/honk.5 @@ -91,7 +91,7 @@ to read this noise. 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. diff --git a/views/honk.html b/views/honk.html index b585016..a7f565e 100644 --- a/views/honk.html +++ b/views/honk.html @@ -65,7 +65,9 @@ in reply to: {{ .RID }} {{ range .Donks }} {{ if .Local }} {{ if eq .Media "text/plain" }} -
Attachment: {{ .Name }} {{ .Desc }} +{{ else if eq .Media "application/pdf" }} +
Attachment: {{ .Name }} {{ .Desc }} {{ else }}
{{ end }} diff --git a/web.go b/web.go index 8c83a95..2852e1b 100644 --- a/web.go +++ b/web.go @@ -1310,25 +1310,42 @@ func submithonk(w http.ResponseWriter, r *http.Request) { 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 == "" {