memes
Ted Unangst tedu@tedunangst.com
Fri, 31 May 2019 00:24:18 -0400
3 files changed,
57 insertions(+),
3 deletions(-)
M
fun.go
→
fun.go
@@ -23,6 +23,7 @@ "html"
"html/template" "log" "net/http" + "os" "regexp" "strings" "sync"@@ -180,6 +181,44 @@ url := fmt.Sprintf("https://%s/emu/%s.png", serverName, fname)
emus = append(emus, Emu{ID: url, Name: e}) } return emus +} + +var re_memes = regexp.MustCompile("meme: ?([[:alnum:]_.-]+)") + +func memetics(noise string) []*Donk { + var donks []*Donk + m := re_memes.FindAllString(noise, -1) + for _, x := range m { + name := x[5:] + if name[0] == ' ' { + name = name[1:] + } + fd, err := os.Open("memes/" + name) + if err != nil { + log.Printf("no meme for %s", name) + continue + } + var peek [512]byte + n, _ := fd.Read(peek[:]) + ct := http.DetectContentType(peek[:n]) + fd.Close() + + url := fmt.Sprintf("https://%s/meme/%s", serverName, name) + res, err := stmtSaveFile.Exec("", name, url, ct, 0, "") + if err != nil { + log.Printf("error saving meme: %s", err) + continue + } + var d Donk + d.FileID, _ = res.LastInsertId() + d.XID = "" + d.Name = name + d.Media = ct + d.URL = url + d.Local = false + donks = append(donks, &d) + } + return donks } var re_bolder = regexp.MustCompile(`(^|\W)\*\*([\w\s,.!?'-]+)\*\*($|\W)`)
M
honk.go
→
honk.go
@@ -183,8 +183,8 @@ var modtime time.Time
for _, honk := range honks { desc := string(honk.HTML) for _, d := range honk.Donks { - desc += fmt.Sprintf(`<p><a href="%sd/%s">Attachment: %s</a>`, - base, d.XID, html.EscapeString(d.Name)) + desc += fmt.Sprintf(`<p><a href="%s">Attachment: %s</a>`, + d.URL, html.EscapeString(d.Name)) } feed.Items = append(feed.Items, &rss.Item{@@ -919,6 +919,7 @@ donk.Name = e.Name
honk.Donks = append(honk.Donks, donk) } } + honk.Donks = append(honk.Donks, memetics(honk.Noise)...) aud := strings.Join(honk.Audience, " ") whofore := 2@@ -1210,6 +1211,11 @@ xid := mux.Vars(r)["xid"]
w.Header().Set("Cache-Control", "max-age="+somedays()) http.ServeFile(w, r, "emus/"+xid) } +func servememe(w http.ResponseWriter, r *http.Request) { + xid := mux.Vars(r)["xid"] + w.Header().Set("Cache-Control", "max-age="+somedays()) + http.ServeFile(w, r, "memes/"+xid) +} func servefile(w http.ResponseWriter, r *http.Request) { xid := mux.Vars(r)["xid"]@@ -1278,7 +1284,8 @@ getters.HandleFunc("/u/{name:[[:alnum:]]+}/following", emptiness)
getters.HandleFunc("/a", avatate) getters.HandleFunc("/t", showconvoy) getters.HandleFunc("/d/{xid:[[:alnum:].]+}", servefile) - getters.HandleFunc("/emu/{xid:[[:alnum:]_.]+}", serveemu) + getters.HandleFunc("/emu/{xid:[[:alnum:]_.-]+}", serveemu) + getters.HandleFunc("/meme/{xid:[[:alnum:]_.-]+}", servememe) getters.HandleFunc("/.well-known/webfinger", fingerlicker) getters.HandleFunc("/style.css", servecss)
M
views/honk.html
→
views/honk.html
@@ -31,7 +31,15 @@ {{ else }}
<p><a href="/d/{{ .XID }}"><img src="/d/{{ .XID }}" title="{{ .URL }}"></a> {{ end }} {{ else }} +{{ if .XID }} <p><a href="{{ .URL }}">External Attachment: {{ .Name }}</a> +{{ else }} +{{ if eq .Media "video/mp4" }} +<p><a href="{{ .URL }}"><video controls src="{{ .URL }}">{{ .Name }}</video></a> +{{ else }} +<p><a href="{{ .URL }}"><img src="{{ .URL }}" title="{{ .Name }}"></a> +{{ end }} +{{ end }} {{ end }} {{ end }} </div>