allow pdf attachments. serious business only.
This commit is contained in:
parent
a81ec6f628
commit
0a04051c42
|
@ -2,6 +2,8 @@ changelog
|
|||
|
||||
-- next
|
||||
|
||||
+ Allow PDF attachments. For serious business only.
|
||||
|
||||
+ "Untag" button to mute part of a thread.
|
||||
|
||||
++ Subscribe to hashtags.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -65,7 +65,9 @@ in reply to: <a href="{{ .RID }}" rel=noreferrer>{{ .RID }}</a>
|
|||
{{ 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 }}
|
||||
|
|
47
web.go
47
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 == "" {
|
||||
|
|
Loading…
Reference in New Issue