allow pdf attachments. serious business only.
This commit is contained in:
parent
a81ec6f628
commit
0a04051c42
|
@ -2,6 +2,8 @@ changelog
|
||||||
|
|
||||||
-- next
|
-- next
|
||||||
|
|
||||||
|
+ Allow PDF attachments. For serious business only.
|
||||||
|
|
||||||
+ "Untag" button to mute part of a thread.
|
+ "Untag" button to mute part of a thread.
|
||||||
|
|
||||||
++ Subscribe to hashtags.
|
++ Subscribe to hashtags.
|
||||||
|
|
|
@ -91,7 +91,7 @@ to read this noise.
|
||||||
One may attach a file to a post.
|
One may attach a file to a post.
|
||||||
Images are automatically rescaled and reduced in size for federation.
|
Images are automatically rescaled and reduced in size for federation.
|
||||||
A description, or caption, is encouraged.
|
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.
|
Other formats are not supported.
|
||||||
.Pp
|
.Pp
|
||||||
One may also check in to a location.
|
One may also check in to a location.
|
||||||
|
|
|
@ -65,7 +65,9 @@ in reply to: <a href="{{ .RID }}" rel=noreferrer>{{ .RID }}</a>
|
||||||
{{ range .Donks }}
|
{{ range .Donks }}
|
||||||
{{ if .Local }}
|
{{ if .Local }}
|
||||||
{{ if eq .Media "text/plain" }}
|
{{ 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 }}
|
{{ else }}
|
||||||
<p><img src="/d/{{ .XID }}" title="{{ .Desc }}" alt="{{ .Desc }}">
|
<p><img src="/d/{{ .XID }}" title="{{ .Desc }}" alt="{{ .Desc }}">
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
47
web.go
47
web.go
|
@ -1310,25 +1310,42 @@ func submithonk(w http.ResponseWriter, r *http.Request) {
|
||||||
name = xid + "." + format
|
name = xid + "." + format
|
||||||
xid = name
|
xid = name
|
||||||
} else {
|
} else {
|
||||||
maxsize := 100000
|
ct := http.DetectContentType(data)
|
||||||
if len(data) > maxsize {
|
switch ct {
|
||||||
log.Printf("bad image: %s too much text: %d", err, len(data))
|
case "application/pdf":
|
||||||
http.Error(w, "didn't like your attachment", http.StatusUnsupportedMediaType)
|
maxsize := 1000000
|
||||||
return
|
if len(data) > maxsize {
|
||||||
}
|
log.Printf("bad image: %s too much pdf: %d", err, len(data))
|
||||||
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)
|
http.Error(w, "didn't like your attachment", http.StatusUnsupportedMediaType)
|
||||||
return
|
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"))
|
desc := strings.TrimSpace(r.FormValue("donkdesc"))
|
||||||
if desc == "" {
|
if desc == "" {
|
||||||
|
|
Loading…
Reference in New Issue