mirror of
https://github.com/binwiederhier/ntfy.git
synced 2024-12-14 11:47:33 +00:00
change icon from object to string
This commit is contained in:
parent
04f2535e92
commit
99886d7f66
8 changed files with 23 additions and 77 deletions
|
@ -47,7 +47,7 @@ type Message struct { // TODO combine with server.message
|
||||||
Priority int
|
Priority int
|
||||||
Tags []string
|
Tags []string
|
||||||
Click string
|
Click string
|
||||||
Icon *Icon
|
Icon string
|
||||||
Attachment *Attachment
|
Attachment *Attachment
|
||||||
|
|
||||||
// Additional fields
|
// Additional fields
|
||||||
|
@ -66,13 +66,6 @@ type Attachment struct {
|
||||||
Owner string `json:"-"` // IP address of uploader, used for rate limiting
|
Owner string `json:"-"` // IP address of uploader, used for rate limiting
|
||||||
}
|
}
|
||||||
|
|
||||||
// Icon represents a message icon
|
|
||||||
type Icon struct {
|
|
||||||
URL string `json:"url"`
|
|
||||||
Type string `json:"type,omitempty"`
|
|
||||||
Size int64 `json:"size,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type subscription struct {
|
type subscription struct {
|
||||||
ID string
|
ID string
|
||||||
topicURL string
|
topicURL string
|
||||||
|
|
|
@ -74,6 +74,7 @@ func TestCLI_Publish_All_The_Things(t *testing.T) {
|
||||||
require.Equal(t, "", m.Attachment.Owner)
|
require.Equal(t, "", m.Attachment.Owner)
|
||||||
require.Equal(t, int64(0), m.Attachment.Expires)
|
require.Equal(t, int64(0), m.Attachment.Expires)
|
||||||
require.Equal(t, "", m.Attachment.Type)
|
require.Equal(t, "", m.Attachment.Type)
|
||||||
|
require.Equal(t, "https://ntfy.sh/static/img/ntfy.png", m.Icon)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCLI_Publish_Wait_PID_And_Cmd(t *testing.T) {
|
func TestCLI_Publish_Wait_PID_And_Cmd(t *testing.T) {
|
||||||
|
|
|
@ -39,46 +39,44 @@ const (
|
||||||
sender TEXT NOT NULL,
|
sender TEXT NOT NULL,
|
||||||
encoding TEXT NOT NULL,
|
encoding TEXT NOT NULL,
|
||||||
published INT NOT NULL,
|
published INT NOT NULL,
|
||||||
icon_url TEXT NOT NULL,
|
icon TEXT NOT NULL
|
||||||
icon_type TEXT NOT NULL,
|
|
||||||
icon_size INT NOT NULL
|
|
||||||
);
|
);
|
||||||
CREATE INDEX IF NOT EXISTS idx_mid ON messages (mid);
|
CREATE INDEX IF NOT EXISTS idx_mid ON messages (mid);
|
||||||
CREATE INDEX IF NOT EXISTS idx_topic ON messages (topic);
|
CREATE INDEX IF NOT EXISTS idx_topic ON messages (topic);
|
||||||
COMMIT;
|
COMMIT;
|
||||||
`
|
`
|
||||||
insertMessageQuery = `
|
insertMessageQuery = `
|
||||||
INSERT INTO messages (mid, time, topic, message, title, priority, tags, click, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, encoding, published, icon_url, icon_type, icon_size)
|
INSERT INTO messages (mid, time, topic, message, title, priority, tags, click, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, encoding, published, icon)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
`
|
`
|
||||||
pruneMessagesQuery = `DELETE FROM messages WHERE time < ? AND published = 1`
|
pruneMessagesQuery = `DELETE FROM messages WHERE time < ? AND published = 1`
|
||||||
selectRowIDFromMessageID = `SELECT id FROM messages WHERE mid = ?` // Do not include topic, see #336 and TestServer_PollSinceID_MultipleTopics
|
selectRowIDFromMessageID = `SELECT id FROM messages WHERE mid = ?` // Do not include topic, see #336 and TestServer_PollSinceID_MultipleTopics
|
||||||
selectMessagesSinceTimeQuery = `
|
selectMessagesSinceTimeQuery = `
|
||||||
SELECT mid, time, topic, message, title, priority, tags, click, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, encoding, icon_url, icon_type, icon_size
|
SELECT mid, time, topic, message, title, priority, tags, click, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, encoding, icon
|
||||||
FROM messages
|
FROM messages
|
||||||
WHERE topic = ? AND time >= ? AND published = 1
|
WHERE topic = ? AND time >= ? AND published = 1
|
||||||
ORDER BY time, id
|
ORDER BY time, id
|
||||||
`
|
`
|
||||||
selectMessagesSinceTimeIncludeScheduledQuery = `
|
selectMessagesSinceTimeIncludeScheduledQuery = `
|
||||||
SELECT mid, time, topic, message, title, priority, tags, click, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, encoding, icon_url, icon_type, icon_size
|
SELECT mid, time, topic, message, title, priority, tags, click, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, encoding, icon
|
||||||
FROM messages
|
FROM messages
|
||||||
WHERE topic = ? AND time >= ?
|
WHERE topic = ? AND time >= ?
|
||||||
ORDER BY time, id
|
ORDER BY time, id
|
||||||
`
|
`
|
||||||
selectMessagesSinceIDQuery = `
|
selectMessagesSinceIDQuery = `
|
||||||
SELECT mid, time, topic, message, title, priority, tags, click, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, encoding, icon_url, icon_type, icon_size
|
SELECT mid, time, topic, message, title, priority, tags, click, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, encoding, icon
|
||||||
FROM messages
|
FROM messages
|
||||||
WHERE topic = ? AND id > ? AND published = 1
|
WHERE topic = ? AND id > ? AND published = 1
|
||||||
ORDER BY time, id
|
ORDER BY time, id
|
||||||
`
|
`
|
||||||
selectMessagesSinceIDIncludeScheduledQuery = `
|
selectMessagesSinceIDIncludeScheduledQuery = `
|
||||||
SELECT mid, time, topic, message, title, priority, tags, click, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, encoding, icon_url, icon_type, icon_size
|
SELECT mid, time, topic, message, title, priority, tags, click, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, encoding, icon
|
||||||
FROM messages
|
FROM messages
|
||||||
WHERE topic = ? AND (id > ? OR published = 0)
|
WHERE topic = ? AND (id > ? OR published = 0)
|
||||||
ORDER BY time, id
|
ORDER BY time, id
|
||||||
`
|
`
|
||||||
selectMessagesDueQuery = `
|
selectMessagesDueQuery = `
|
||||||
SELECT mid, time, topic, message, title, priority, tags, click, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, encoding, icon_url, icon_type, icon_size
|
SELECT mid, time, topic, message, title, priority, tags, click, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, encoding, icon
|
||||||
FROM messages
|
FROM messages
|
||||||
WHERE time <= ? AND published = 0
|
WHERE time <= ? AND published = 0
|
||||||
ORDER BY time, id
|
ORDER BY time, id
|
||||||
|
@ -183,9 +181,7 @@ const (
|
||||||
|
|
||||||
// 7 -> 8
|
// 7 -> 8
|
||||||
migrate7To8AlterMessagesTableQuery = `
|
migrate7To8AlterMessagesTableQuery = `
|
||||||
ALTER TABLE messages ADD COLUMN icon_url TEXT NOT NULL DEFAULT('');
|
ALTER TABLE messages ADD COLUMN icon TEXT NOT NULL DEFAULT('');
|
||||||
ALTER TABLE messages ADD COLUMN icon_type TEXT NOT NULL DEFAULT('');
|
|
||||||
ALTER TABLE messages ADD COLUMN icon_size INT NOT NULL DEFAULT('0');
|
|
||||||
`
|
`
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -258,13 +254,6 @@ func (c *messageCache) addMessages(ms []*message) error {
|
||||||
attachmentExpires = m.Attachment.Expires
|
attachmentExpires = m.Attachment.Expires
|
||||||
attachmentURL = m.Attachment.URL
|
attachmentURL = m.Attachment.URL
|
||||||
}
|
}
|
||||||
var iconURL, iconType string
|
|
||||||
var iconSize int64
|
|
||||||
if m.Icon != nil {
|
|
||||||
iconURL = m.Icon.URL
|
|
||||||
iconType = m.Icon.Type
|
|
||||||
iconSize = m.Icon.Size
|
|
||||||
}
|
|
||||||
var actionsStr string
|
var actionsStr string
|
||||||
if len(m.Actions) > 0 {
|
if len(m.Actions) > 0 {
|
||||||
actionsBytes, err := json.Marshal(m.Actions)
|
actionsBytes, err := json.Marshal(m.Actions)
|
||||||
|
@ -292,9 +281,7 @@ func (c *messageCache) addMessages(ms []*message) error {
|
||||||
m.Sender,
|
m.Sender,
|
||||||
m.Encoding,
|
m.Encoding,
|
||||||
published,
|
published,
|
||||||
iconURL,
|
m.Icon,
|
||||||
iconType,
|
|
||||||
iconSize,
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -432,9 +419,9 @@ func readMessages(rows *sql.Rows) ([]*message, error) {
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
messages := make([]*message, 0)
|
messages := make([]*message, 0)
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var timestamp, attachmentSize, attachmentExpires, iconSize int64
|
var timestamp, attachmentSize, attachmentExpires int64
|
||||||
var priority int
|
var priority int
|
||||||
var id, topic, msg, title, tagsStr, click, actionsStr, attachmentName, attachmentType, attachmentURL, sender, encoding, iconURL, iconType string
|
var id, topic, msg, title, tagsStr, click, actionsStr, attachmentName, attachmentType, attachmentURL, sender, encoding, icon string
|
||||||
err := rows.Scan(
|
err := rows.Scan(
|
||||||
&id,
|
&id,
|
||||||
×tamp,
|
×tamp,
|
||||||
|
@ -452,9 +439,7 @@ func readMessages(rows *sql.Rows) ([]*message, error) {
|
||||||
&attachmentURL,
|
&attachmentURL,
|
||||||
&sender,
|
&sender,
|
||||||
&encoding,
|
&encoding,
|
||||||
&iconURL,
|
&icon,
|
||||||
&iconType,
|
|
||||||
&iconSize,
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -479,14 +464,6 @@ func readMessages(rows *sql.Rows) ([]*message, error) {
|
||||||
URL: attachmentURL,
|
URL: attachmentURL,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var ico *icon
|
|
||||||
if iconURL != "" {
|
|
||||||
ico = &icon{
|
|
||||||
URL: iconURL,
|
|
||||||
Type: iconType,
|
|
||||||
Size: iconSize,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
messages = append(messages, &message{
|
messages = append(messages, &message{
|
||||||
ID: id,
|
ID: id,
|
||||||
Time: timestamp,
|
Time: timestamp,
|
||||||
|
@ -497,7 +474,7 @@ func readMessages(rows *sql.Rows) ([]*message, error) {
|
||||||
Priority: priority,
|
Priority: priority,
|
||||||
Tags: tags,
|
Tags: tags,
|
||||||
Click: click,
|
Click: click,
|
||||||
Icon: ico,
|
Icon: icon,
|
||||||
Actions: actions,
|
Actions: actions,
|
||||||
Attachment: att,
|
Attachment: att,
|
||||||
Sender: sender,
|
Sender: sender,
|
||||||
|
|
|
@ -569,7 +569,7 @@ func (s *Server) parsePublishParams(r *http.Request, v *visitor, m *message) (ca
|
||||||
firebase = readBoolParam(r, true, "x-firebase", "firebase")
|
firebase = readBoolParam(r, true, "x-firebase", "firebase")
|
||||||
m.Title = readParam(r, "x-title", "title", "t")
|
m.Title = readParam(r, "x-title", "title", "t")
|
||||||
m.Click = readParam(r, "x-click", "click")
|
m.Click = readParam(r, "x-click", "click")
|
||||||
ico := readParam(r, "x-icon", "icon")
|
m.Icon = readParam(r, "x-icon", "icon")
|
||||||
filename := readParam(r, "x-filename", "filename", "file", "f")
|
filename := readParam(r, "x-filename", "filename", "file", "f")
|
||||||
attach := readParam(r, "x-attach", "attach", "a")
|
attach := readParam(r, "x-attach", "attach", "a")
|
||||||
if attach != "" || filename != "" {
|
if attach != "" || filename != "" {
|
||||||
|
@ -596,13 +596,6 @@ func (s *Server) parsePublishParams(r *http.Request, v *visitor, m *message) (ca
|
||||||
m.Attachment.Name = "attachment"
|
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")
|
email = readParam(r, "x-email", "x-e-mail", "email", "e-mail", "mail", "e")
|
||||||
if email != "" {
|
if email != "" {
|
||||||
if err := v.EmailAllowed(); err != nil {
|
if err := v.EmailAllowed(); err != nil {
|
||||||
|
|
|
@ -151,6 +151,7 @@ func toFirebaseMessage(m *message, auther auth.Auther) (*messaging.Message, erro
|
||||||
"title": m.Title,
|
"title": m.Title,
|
||||||
"message": m.Message,
|
"message": m.Message,
|
||||||
"encoding": m.Encoding,
|
"encoding": m.Encoding,
|
||||||
|
"icon": m.Icon,
|
||||||
}
|
}
|
||||||
if len(m.Actions) > 0 {
|
if len(m.Actions) > 0 {
|
||||||
actions, err := json.Marshal(m.Actions)
|
actions, err := json.Marshal(m.Actions)
|
||||||
|
@ -166,11 +167,6 @@ func toFirebaseMessage(m *message, auther auth.Auther) (*messaging.Message, erro
|
||||||
data["attachment_expires"] = fmt.Sprintf("%d", m.Attachment.Expires)
|
data["attachment_expires"] = fmt.Sprintf("%d", m.Attachment.Expires)
|
||||||
data["attachment_url"] = m.Attachment.URL
|
data["attachment_url"] = m.Attachment.URL
|
||||||
}
|
}
|
||||||
if m.Icon != nil {
|
|
||||||
data["icon_url"] = m.Icon.URL
|
|
||||||
data["icon_type"] = m.Icon.Type
|
|
||||||
data["icon_size"] = fmt.Sprintf("%d", m.Icon.Size)
|
|
||||||
}
|
|
||||||
apnsConfig = createAPNSAlertConfig(m, data)
|
apnsConfig = createAPNSAlertConfig(m, data)
|
||||||
} else {
|
} else {
|
||||||
// If anonymous read for a topic is not allowed, we cannot send the message along
|
// If anonymous read for a topic is not allowed, we cannot send the message along
|
||||||
|
|
|
@ -123,11 +123,7 @@ func TestToFirebaseMessage_Message_Normal_Allowed(t *testing.T) {
|
||||||
m.Priority = 4
|
m.Priority = 4
|
||||||
m.Tags = []string{"tag 1", "tag2"}
|
m.Tags = []string{"tag 1", "tag2"}
|
||||||
m.Click = "https://google.com"
|
m.Click = "https://google.com"
|
||||||
m.Icon = &icon{
|
m.Icon = "https://ntfy.sh/static/img/ntfy.png"
|
||||||
URL: "https://ntfy.sh/static/img/ntfy.png",
|
|
||||||
Type: "image/jpeg",
|
|
||||||
Size: 4567,
|
|
||||||
}
|
|
||||||
m.Title = "some title"
|
m.Title = "some title"
|
||||||
m.Actions = []*action{
|
m.Actions = []*action{
|
||||||
{
|
{
|
||||||
|
@ -178,9 +174,7 @@ func TestToFirebaseMessage_Message_Normal_Allowed(t *testing.T) {
|
||||||
"priority": "4",
|
"priority": "4",
|
||||||
"tags": strings.Join(m.Tags, ","),
|
"tags": strings.Join(m.Tags, ","),
|
||||||
"click": "https://google.com",
|
"click": "https://google.com",
|
||||||
"icon_url": "https://ntfy.sh/static/img/ntfy.png",
|
"icon": "https://ntfy.sh/static/img/ntfy.png",
|
||||||
"icon_type": "image/jpeg",
|
|
||||||
"icon_size": "4567",
|
|
||||||
"title": "some title",
|
"title": "some title",
|
||||||
"message": "this is a message",
|
"message": "this is a message",
|
||||||
"actions": `[{"id":"123","action":"view","label":"Open page","clear":true,"url":"https://ntfy.sh"},{"id":"456","action":"http","label":"Close door","clear":false,"url":"https://door.com/close","method":"PUT","headers":{"really":"yes"}}]`,
|
"actions": `[{"id":"123","action":"view","label":"Open page","clear":true,"url":"https://ntfy.sh"},{"id":"456","action":"http","label":"Close door","clear":false,"url":"https://door.com/close","method":"PUT","headers":{"really":"yes"}}]`,
|
||||||
|
@ -201,9 +195,7 @@ func TestToFirebaseMessage_Message_Normal_Allowed(t *testing.T) {
|
||||||
"priority": "4",
|
"priority": "4",
|
||||||
"tags": strings.Join(m.Tags, ","),
|
"tags": strings.Join(m.Tags, ","),
|
||||||
"click": "https://google.com",
|
"click": "https://google.com",
|
||||||
"icon_url": "https://ntfy.sh/static/img/ntfy.png",
|
"icon": "https://ntfy.sh/static/img/ntfy.png",
|
||||||
"icon_type": "image/jpeg",
|
|
||||||
"icon_size": "4567",
|
|
||||||
"title": "some title",
|
"title": "some title",
|
||||||
"message": "this is a message",
|
"message": "this is a message",
|
||||||
"actions": `[{"id":"123","action":"view","label":"Open page","clear":true,"url":"https://ntfy.sh"},{"id":"456","action":"http","label":"Close door","clear":false,"url":"https://door.com/close","method":"PUT","headers":{"really":"yes"}}]`,
|
"actions": `[{"id":"123","action":"view","label":"Open page","clear":true,"url":"https://ntfy.sh"},{"id":"456","action":"http","label":"Close door","clear":false,"url":"https://door.com/close","method":"PUT","headers":{"really":"yes"}}]`,
|
||||||
|
|
|
@ -1058,7 +1058,7 @@ func TestServer_PublishAsJSON(t *testing.T) {
|
||||||
require.Equal(t, "http://google.com", m.Attachment.URL)
|
require.Equal(t, "http://google.com", m.Attachment.URL)
|
||||||
require.Equal(t, "google.pdf", m.Attachment.Name)
|
require.Equal(t, "google.pdf", m.Attachment.Name)
|
||||||
require.Equal(t, "http://ntfy.sh", m.Click)
|
require.Equal(t, "http://ntfy.sh", m.Click)
|
||||||
require.Equal(t, "https://ntfy.sh/static/img/ntfy.png", m.Icon.URL)
|
require.Equal(t, "https://ntfy.sh/static/img/ntfy.png", m.Icon)
|
||||||
|
|
||||||
require.Equal(t, 4, m.Priority)
|
require.Equal(t, 4, m.Priority)
|
||||||
require.True(t, m.Time > time.Now().Unix()+29*60)
|
require.True(t, m.Time > time.Now().Unix()+29*60)
|
||||||
|
|
|
@ -31,7 +31,7 @@ type message struct {
|
||||||
Click string `json:"click,omitempty"`
|
Click string `json:"click,omitempty"`
|
||||||
Actions []*action `json:"actions,omitempty"`
|
Actions []*action `json:"actions,omitempty"`
|
||||||
Attachment *attachment `json:"attachment,omitempty"`
|
Attachment *attachment `json:"attachment,omitempty"`
|
||||||
Icon *icon `json:"icon,omitempty"`
|
Icon string `json:"icon,omitempty"`
|
||||||
PollID string `json:"poll_id,omitempty"`
|
PollID string `json:"poll_id,omitempty"`
|
||||||
Sender string `json:"-"` // IP address of uploader, used for rate limiting
|
Sender string `json:"-"` // IP address of uploader, used for rate limiting
|
||||||
Encoding string `json:"encoding,omitempty"` // empty for raw UTF-8, or "base64" for encoded bytes
|
Encoding string `json:"encoding,omitempty"` // empty for raw UTF-8, or "base64" for encoded bytes
|
||||||
|
@ -45,12 +45,6 @@ type attachment struct {
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type icon struct {
|
|
||||||
URL string `json:"url"`
|
|
||||||
Type string `json:"type,omitempty"`
|
|
||||||
Size int64 `json:"size,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type action struct {
|
type action struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Action string `json:"action"` // "view", "broadcast", or "http"
|
Action string `json:"action"` // "view", "broadcast", or "http"
|
||||||
|
|
Loading…
Reference in a new issue