WIP: Markdown
This commit is contained in:
		
							parent
							
								
									fa29da1a32
								
							
						
					
					
						commit
						7812eb9d19
					
				
					 3 changed files with 34 additions and 28 deletions
				
			
		|  | @ -963,6 +963,10 @@ func (s *Server) parsePublishParams(r *http.Request, m *message) (cache bool, fi | ||||||
| 			return false, false, "", "", false, errHTTPBadRequestActionsInvalid.Wrap(e.Error()) | 			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! | 	unifiedpush = readBoolParam(r, false, "x-unifiedpush", "unifiedpush", "up") // see GET too! | ||||||
| 	if unifiedpush { | 	if unifiedpush { | ||||||
| 		firebase = false | 		firebase = false | ||||||
|  |  | ||||||
|  | @ -144,17 +144,18 @@ func toFirebaseMessage(m *message, auther user.Auther) (*messaging.Message, erro | ||||||
| 		} | 		} | ||||||
| 		if allowForward { | 		if allowForward { | ||||||
| 			data = map[string]string{ | 			data = map[string]string{ | ||||||
| 				"id":       m.ID, | 				"id":           m.ID, | ||||||
| 				"time":     fmt.Sprintf("%d", m.Time), | 				"time":         fmt.Sprintf("%d", m.Time), | ||||||
| 				"event":    m.Event, | 				"event":        m.Event, | ||||||
| 				"topic":    m.Topic, | 				"topic":        m.Topic, | ||||||
| 				"priority": fmt.Sprintf("%d", m.Priority), | 				"priority":     fmt.Sprintf("%d", m.Priority), | ||||||
| 				"tags":     strings.Join(m.Tags, ","), | 				"tags":         strings.Join(m.Tags, ","), | ||||||
| 				"click":    m.Click, | 				"click":        m.Click, | ||||||
| 				"icon":     m.Icon, | 				"icon":         m.Icon, | ||||||
| 				"title":    m.Title, | 				"title":        m.Title, | ||||||
| 				"message":  m.Message, | 				"message":      m.Message, | ||||||
| 				"encoding": m.Encoding, | 				"content_type": m.ContentType, | ||||||
|  | 				"encoding":     m.Encoding, | ||||||
| 			} | 			} | ||||||
| 			if len(m.Actions) > 0 { | 			if len(m.Actions) > 0 { | ||||||
| 				actions, err := json.Marshal(m.Actions) | 				actions, err := json.Marshal(m.Actions) | ||||||
|  |  | ||||||
|  | @ -24,23 +24,24 @@ const ( | ||||||
| 
 | 
 | ||||||
| // message represents a message published to a topic | // message represents a message published to a topic | ||||||
| type message struct { | type message struct { | ||||||
| 	ID         string      `json:"id"`                // Random message ID | 	ID          string      `json:"id"`                // Random message ID | ||||||
| 	Time       int64       `json:"time"`              // Unix time in seconds | 	Time        int64       `json:"time"`              // Unix time in seconds | ||||||
| 	Expires    int64       `json:"expires,omitempty"` // Unix time in seconds (not required for open/keepalive) | 	Expires     int64       `json:"expires,omitempty"` // Unix time in seconds (not required for open/keepalive) | ||||||
| 	Event      string      `json:"event"`             // One of the above | 	Event       string      `json:"event"`             // One of the above | ||||||
| 	Topic      string      `json:"topic"` | 	Topic       string      `json:"topic"` | ||||||
| 	Title      string      `json:"title,omitempty"` | 	Title       string      `json:"title,omitempty"` | ||||||
| 	Message    string      `json:"message,omitempty"` | 	Message     string      `json:"message,omitempty"` | ||||||
| 	Priority   int         `json:"priority,omitempty"` | 	Priority    int         `json:"priority,omitempty"` | ||||||
| 	Tags       []string    `json:"tags,omitempty"` | 	Tags        []string    `json:"tags,omitempty"` | ||||||
| 	Click      string      `json:"click,omitempty"` | 	Click       string      `json:"click,omitempty"` | ||||||
| 	Icon       string      `json:"icon,omitempty"` | 	Icon        string      `json:"icon,omitempty"` | ||||||
| 	Actions    []*action   `json:"actions,omitempty"` | 	Actions     []*action   `json:"actions,omitempty"` | ||||||
| 	Attachment *attachment `json:"attachment,omitempty"` | 	Attachment  *attachment `json:"attachment,omitempty"` | ||||||
| 	PollID     string      `json:"poll_id,omitempty"` | 	PollID      string      `json:"poll_id,omitempty"` | ||||||
| 	Encoding   string      `json:"encoding,omitempty"` // empty for raw UTF-8, or "base64" for encoded bytes | 	ContentType string      `json:"content_type,omitempty"` // text/plain by default (if empty), or text/markdown | ||||||
| 	Sender     netip.Addr  `json:"-"`                  // IP address of uploader, used for rate limiting | 	Encoding    string      `json:"encoding,omitempty"`     // empty for raw UTF-8, or "base64" for encoded bytes | ||||||
| 	User       string      `json:"-"`                  // Username of the uploader, used to associated attachments | 	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 { | func (m *message) Context() log.Context { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue