rework emu save slightly for local emus. no need for database copy
This commit is contained in:
parent
f994120a87
commit
d164471a92
30
fun.go
30
fun.go
|
@ -62,6 +62,10 @@ func reverbolate(userid int64, honks []*Honk) {
|
||||||
h.Style += " limited"
|
h.Style += " limited"
|
||||||
}
|
}
|
||||||
translate(h, false)
|
translate(h, false)
|
||||||
|
local := false
|
||||||
|
if (h.Whofore == 2 || h.Whofore == 3) || h.What != "bonked" {
|
||||||
|
local = true
|
||||||
|
}
|
||||||
if h.Whofore == 2 || h.Whofore == 3 {
|
if h.Whofore == 2 || h.Whofore == 3 {
|
||||||
h.URL = h.XID
|
h.URL = h.XID
|
||||||
if h.What != "bonked" {
|
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
|
return e
|
||||||
}
|
}
|
||||||
h.Precis = re_emus.ReplaceAllStringFunc(h.Precis, emuxifier)
|
h.Precis = re_emus.ReplaceAllStringFunc(h.Precis, emuxifier)
|
||||||
|
@ -319,18 +330,27 @@ type Emu struct {
|
||||||
|
|
||||||
var re_emus = regexp.MustCompile(`:[[:alnum:]_-]+:`)
|
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 {
|
func herdofemus(noise string) []Emu {
|
||||||
m := re_emus.FindAllString(noise, -1)
|
m := re_emus.FindAllString(noise, -1)
|
||||||
m = oneofakind(m)
|
m = oneofakind(m)
|
||||||
var emus []Emu
|
var emus []Emu
|
||||||
for _, e := range m {
|
for _, e := range m {
|
||||||
fname := e[1 : len(e)-1]
|
var emu Emu
|
||||||
_, err := os.Stat("emus/" + fname + ".png")
|
emucache.Get(e, &emu)
|
||||||
if err != nil {
|
if emu.ID == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
url := fmt.Sprintf("https://%s/emu/%s.png", serverName, fname)
|
emus = append(emus, emu)
|
||||||
emus = append(emus, Emu{ID: url, Name: e})
|
|
||||||
}
|
}
|
||||||
return emus
|
return emus
|
||||||
}
|
}
|
||||||
|
|
8
web.go
8
web.go
|
@ -1575,14 +1575,6 @@ func submithonk(w http.ResponseWriter, r *http.Request, isAPI bool) {
|
||||||
log.Printf("can't find file: %s", xid)
|
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)
|
memetize(honk)
|
||||||
imaginate(honk)
|
imaginate(honk)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue