notification icons

This commit is contained in:
Hunter Kehoe 2022-07-16 13:31:03 -06:00
parent bac5e1fa84
commit 354d01925f
14 changed files with 201 additions and 12 deletions

View file

@ -75,6 +75,7 @@ var (
fileRegex = regexp.MustCompile(`^/file/([-_A-Za-z0-9]{1,64})(?:\.[A-Za-z0-9]{1,16})?$`)
disallowedTopics = []string{"docs", "static", "file", "app", "settings"} // If updated, also update in Android app
attachURLRegex = regexp.MustCompile(`^https?://`)
iconURLRegex = regexp.MustCompile(`^https?://`)
//go:embed site
webFs embed.FS
@ -559,6 +560,7 @@ func (s *Server) parsePublishParams(r *http.Request, v *visitor, m *message) (ca
firebase = readBoolParam(r, true, "x-firebase", "firebase")
m.Title = readParam(r, "x-title", "title", "t")
m.Click = readParam(r, "x-click", "click")
ico := readParam(r, "x-icon", "icon")
filename := readParam(r, "x-filename", "filename", "file", "f")
attach := readParam(r, "x-attach", "attach", "a")
if attach != "" || filename != "" {
@ -585,6 +587,13 @@ func (s *Server) parsePublishParams(r *http.Request, v *visitor, m *message) (ca
m.Attachment.Name = "attachment"
}
}
if ico != "" {
m.Icon = &icon{}
if !iconURLRegex.MatchString(ico) {
return false, false, "", false, errHTTPBadRequestIconURLInvalid
}
m.Icon.URL = ico
}
email = readParam(r, "x-email", "x-e-mail", "email", "e-mail", "mail", "e")
if email != "" {
if err := v.EmailAllowed(); err != nil {
@ -1326,6 +1335,9 @@ func (s *Server) transformBodyJSON(next handleFunc) handleFunc {
if m.Click != "" {
r.Header.Set("X-Click", m.Click)
}
if m.Icon != "" {
r.Header.Set("X-Icon", m.Icon)
}
if len(m.Actions) > 0 {
actionsStr, err := json.Marshal(m.Actions)
if err != nil {