all repos — honk @ 9b37ae3807b669b8b9213604bc2660ebab52e800

my fork of honk

rework emu save slightly for local emus. no need for database copy
Ted Unangst tedu@tedunangst.com
Sun, 01 Dec 2019 12:27:09 -0500
commit

9b37ae3807b669b8b9213604bc2660ebab52e800

parent

2b26864d8b650b69f2bfad67219ed4f21c4ad64c

2 files changed, 25 insertions(+), 13 deletions(-)

jump to
M fun.gofun.go

@@ -62,6 +62,10 @@ if !h.Public {

h.Style += " limited" } translate(h, false) + local := false + if (h.Whofore == 2 || h.Whofore == 3) || h.What != "bonked" { + local = true + } if h.Whofore == 2 || h.Whofore == 3 { h.URL = h.XID if h.What != "bonked" {

@@ -128,6 +132,13 @@ zap[d.XID] = true

if d.Local { return fmt.Sprintf(`<img class="emu" title="%s" src="/d/%s">`, d.Name, d.XID) } + } + } + if local { + var emu Emu + emucache.Get(e, &emu) + if emu.ID != "" { + return fmt.Sprintf(`<img class="emu" title="%s" src="%s">`, emu.Name, emu.ID) } } return e

@@ -319,18 +330,27 @@ }

var re_emus = regexp.MustCompile(`:[[:alnum:]_-]+:`) +var emucache = cache.New(cache.Options{Filler: func(ename string) (Emu, bool) { + fname := ename[1 : len(ename)-1] + _, err := os.Stat(dataDir + "/emus/" + fname + ".png") + if err != nil { + return Emu{Name: ename, ID: ""}, true + } + url := fmt.Sprintf("https://%s/emu/%s.png", serverName, fname) + return Emu{ID: url, Name: ename}, true +}, Duration: 10 * time.Second}) + func herdofemus(noise string) []Emu { m := re_emus.FindAllString(noise, -1) m = oneofakind(m) var emus []Emu for _, e := range m { - fname := e[1 : len(e)-1] - _, err := os.Stat("emus/" + fname + ".png") - if err != nil { + var emu Emu + emucache.Get(e, &emu) + if emu.ID == "" { continue } - url := fmt.Sprintf("https://%s/emu/%s.png", serverName, fname) - emus = append(emus, Emu{ID: url, Name: e}) + emus = append(emus, emu) } return emus }
M web.goweb.go

@@ -1575,14 +1575,6 @@ } else {

log.Printf("can't find file: %s", xid) } } - herd := herdofemus(noise) - for _, e := range herd { - donk := savedonk(e.ID, e.Name, e.Name, "image/png", true) - if donk != nil { - donk.Name = e.Name - honk.Donks = append(honk.Donks, donk) - } - } memetize(honk) imaginate(honk)