From 7812eb9d19d50bfa33778c352844aeef726efde6 Mon Sep 17 00:00:00 2001 From: binwiederhier Date: Wed, 24 May 2023 20:37:27 -0400 Subject: [PATCH] WIP: Markdown --- server/server.go | 4 ++++ server/server_firebase.go | 23 ++++++++++++----------- server/types.go | 35 ++++++++++++++++++----------------- 3 files changed, 34 insertions(+), 28 deletions(-) diff --git a/server/server.go b/server/server.go index ac54aa5..179359d 100644 --- a/server/server.go +++ b/server/server.go @@ -963,6 +963,10 @@ func (s *Server) parsePublishParams(r *http.Request, m *message) (cache bool, fi return false, false, "", "", false, errHTTPBadRequestActionsInvalid.Wrap(e.Error()) } } + contentType, markdown := readParam(r, "content-type"), readBoolParam(r, false, "x-markdown", "markdown", "md") + if markdown || strings.ToLower(contentType) == "text/markdown" { + m.ContentType = "text/markdown" + } unifiedpush = readBoolParam(r, false, "x-unifiedpush", "unifiedpush", "up") // see GET too! if unifiedpush { firebase = false diff --git a/server/server_firebase.go b/server/server_firebase.go index 6318b98..b8158d2 100644 --- a/server/server_firebase.go +++ b/server/server_firebase.go @@ -144,17 +144,18 @@ func toFirebaseMessage(m *message, auther user.Auther) (*messaging.Message, erro } if allowForward { data = map[string]string{ - "id": m.ID, - "time": fmt.Sprintf("%d", m.Time), - "event": m.Event, - "topic": m.Topic, - "priority": fmt.Sprintf("%d", m.Priority), - "tags": strings.Join(m.Tags, ","), - "click": m.Click, - "icon": m.Icon, - "title": m.Title, - "message": m.Message, - "encoding": m.Encoding, + "id": m.ID, + "time": fmt.Sprintf("%d", m.Time), + "event": m.Event, + "topic": m.Topic, + "priority": fmt.Sprintf("%d", m.Priority), + "tags": strings.Join(m.Tags, ","), + "click": m.Click, + "icon": m.Icon, + "title": m.Title, + "message": m.Message, + "content_type": m.ContentType, + "encoding": m.Encoding, } if len(m.Actions) > 0 { actions, err := json.Marshal(m.Actions) diff --git a/server/types.go b/server/types.go index 9e4ff55..7798a65 100644 --- a/server/types.go +++ b/server/types.go @@ -24,23 +24,24 @@ const ( // message represents a message published to a topic type message struct { - ID string `json:"id"` // Random message ID - Time int64 `json:"time"` // Unix time in seconds - Expires int64 `json:"expires,omitempty"` // Unix time in seconds (not required for open/keepalive) - Event string `json:"event"` // One of the above - Topic string `json:"topic"` - Title string `json:"title,omitempty"` - Message string `json:"message,omitempty"` - Priority int `json:"priority,omitempty"` - Tags []string `json:"tags,omitempty"` - Click string `json:"click,omitempty"` - Icon string `json:"icon,omitempty"` - Actions []*action `json:"actions,omitempty"` - Attachment *attachment `json:"attachment,omitempty"` - PollID string `json:"poll_id,omitempty"` - Encoding string `json:"encoding,omitempty"` // empty for raw UTF-8, or "base64" for encoded bytes - Sender netip.Addr `json:"-"` // IP address of uploader, used for rate limiting - User string `json:"-"` // Username of the uploader, used to associated attachments + ID string `json:"id"` // Random message ID + Time int64 `json:"time"` // Unix time in seconds + Expires int64 `json:"expires,omitempty"` // Unix time in seconds (not required for open/keepalive) + Event string `json:"event"` // One of the above + Topic string `json:"topic"` + Title string `json:"title,omitempty"` + Message string `json:"message,omitempty"` + Priority int `json:"priority,omitempty"` + Tags []string `json:"tags,omitempty"` + Click string `json:"click,omitempty"` + Icon string `json:"icon,omitempty"` + Actions []*action `json:"actions,omitempty"` + Attachment *attachment `json:"attachment,omitempty"` + PollID string `json:"poll_id,omitempty"` + ContentType string `json:"content_type,omitempty"` // text/plain by default (if empty), or text/markdown + Encoding string `json:"encoding,omitempty"` // empty for raw UTF-8, or "base64" for encoded bytes + Sender netip.Addr `json:"-"` // IP address of uploader, used for rate limiting + User string `json:"-"` // Username of the uploader, used to associated attachments } func (m *message) Context() log.Context {