meme: fix default config and save path

This commit is contained in:
Chris Sexton 2024-09-30 11:37:11 -04:00
parent c09dfd46e2
commit 067d3064a6
2 changed files with 12 additions and 3 deletions

View File

@ -370,8 +370,8 @@ func (p *MemePlugin) defaultFormatConfig() []memeText {
}
ret:
return []memeText{
{XPerc: 0.5, YPerc: 0.1, Caps: true},
{XPerc: 0.5, YPerc: 0.9, Caps: true},
{XPerc: 0.5, YPerc: 0.05, Caps: true},
{XPerc: 0.5, YPerc: 0.95, Caps: true},
}
}

View File

@ -2,6 +2,7 @@ package meme
import (
"encoding/json"
"errors"
"fmt"
"github.com/ggicci/httpin"
"net/http"
@ -89,7 +90,7 @@ func (p *MemePlugin) rmMeme(w http.ResponseWriter, r *http.Request) {
}
type SaveReq struct {
Name string `in:"path=name"`
Name string `in:"path=name;form=name"`
Config string `in:"form=config"`
URL string `in:"form=url"`
}
@ -98,6 +99,14 @@ func (p *MemePlugin) saveMeme(w http.ResponseWriter, r *http.Request) {
input := r.Context().Value(httpin.Input).(*SaveReq)
checkError := mkCheckError(w)
log.Debug().Interface("save input", input).Send()
if input.Name == "" {
checkError(errors.New("no name"))
}
if input.URL == "" {
checkError(errors.New("no URL"))
}
formats := p.c.GetMap("meme.memes", defaultFormats)
formats[input.Name] = input.URL
err := p.c.SetMap("meme.memes", formats)