Add/edit notifications
This commit is contained in:
parent
1ede36b8aa
commit
c7ad2aa1b6
19 changed files with 531 additions and 11 deletions
|
|
@ -7,6 +7,7 @@ import (
|
|||
// Standard
|
||||
"encoding/json"
|
||||
"log/slog"
|
||||
"net/url"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
|
@ -17,6 +18,13 @@ type Script struct {
|
|||
Prio int
|
||||
AcknowledgeURL string
|
||||
logger *slog.Logger
|
||||
|
||||
exists bool
|
||||
updated Service
|
||||
}
|
||||
|
||||
func init() {
|
||||
allServices = append(allServices, &Script{})
|
||||
}
|
||||
|
||||
func NewScript(config []byte, prio int, ackURL string) (instance *Script, err error) {
|
||||
|
|
@ -43,6 +51,22 @@ func (script *Script) GetPrio() int {
|
|||
return script.Prio
|
||||
}
|
||||
|
||||
func (script *Script) SetPrio(prio int) {
|
||||
script.Prio = prio
|
||||
}
|
||||
|
||||
func (script *Script) SetExists(exists bool) {
|
||||
script.exists = exists
|
||||
}
|
||||
|
||||
func (script Script) Exists() bool {
|
||||
return script.exists
|
||||
}
|
||||
|
||||
func (script *Script) String() string {
|
||||
return script.Filename
|
||||
}
|
||||
|
||||
func (script Script) Send(problemID int, msg []byte) (err error) {
|
||||
var errbuf strings.Builder
|
||||
cmd := exec.Command(script.Filename, strconv.Itoa(problemID), script.AcknowledgeURL, string(msg))
|
||||
|
|
@ -68,3 +92,40 @@ func (script Script) Send(problemID int, msg []byte) (err error) {
|
|||
|
||||
return
|
||||
}
|
||||
|
||||
func (script *Script) Update(values url.Values) (err error) {
|
||||
updated := Script{}
|
||||
updated.Prio, err = strconv.Atoi(values.Get("prio"))
|
||||
if err != nil {
|
||||
return werr.Wrap(err)
|
||||
}
|
||||
|
||||
givenFilename := values.Get("filename")
|
||||
if strings.TrimSpace(givenFilename) == "" {
|
||||
return werr.New("Filename cannot be empty")
|
||||
}
|
||||
updated.Filename = strings.TrimSpace(givenFilename)
|
||||
|
||||
script.updated = &updated
|
||||
return
|
||||
}
|
||||
|
||||
func (script *Script) Updated() Service {
|
||||
return script.updated
|
||||
}
|
||||
|
||||
func (script *Script) Commit() {
|
||||
updated := script.updated.(*Script)
|
||||
script.Prio = updated.Prio
|
||||
script.Filename = updated.Filename
|
||||
}
|
||||
|
||||
func (script Script) JSON() []byte {
|
||||
data := struct {
|
||||
Filename string `json:"filename"`
|
||||
}{
|
||||
script.Filename,
|
||||
}
|
||||
j, _ := json.Marshal(data)
|
||||
return j
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue