rework emu save slightly for local emus. no need for database copy

This commit is contained in:
Ted Unangst 2019-12-01 12:27:09 -05:00
parent f994120a87
commit d164471a92
2 changed files with 25 additions and 13 deletions

30
fun.go
View File

@ -62,6 +62,10 @@ func reverbolate(userid int64, honks []*Honk) {
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" {
@ -130,6 +134,13 @@ func reverbolate(userid int64, honks []*Honk) {
}
}
}
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
}
h.Precis = re_emus.ReplaceAllStringFunc(h.Precis, emuxifier)
@ -319,18 +330,27 @@ type Emu struct {
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
}

8
web.go
View File

@ -1575,14 +1575,6 @@ func submithonk(w http.ResponseWriter, r *http.Request, isAPI bool) {
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)