feat: keep compatible with ServerChan (close #63)
This commit is contained in:
+21
-12
@@ -13,6 +13,19 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func keepCompatible(message *model.Message) {
|
||||||
|
// Keep compatible with ServerChan: https://sct.ftqq.com/sendkey
|
||||||
|
if message.Description == "" {
|
||||||
|
message.Description = message.Short
|
||||||
|
}
|
||||||
|
if message.Content == "" {
|
||||||
|
message.Content = message.Desp
|
||||||
|
}
|
||||||
|
if message.To == "" {
|
||||||
|
message.To = message.OpenId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func GetPushMessage(c *gin.Context) {
|
func GetPushMessage(c *gin.Context) {
|
||||||
message := model.Message{
|
message := model.Message{
|
||||||
Title: c.Query("title"),
|
Title: c.Query("title"),
|
||||||
@@ -22,15 +35,11 @@ func GetPushMessage(c *gin.Context) {
|
|||||||
Channel: c.Query("channel"),
|
Channel: c.Query("channel"),
|
||||||
Token: c.Query("token"),
|
Token: c.Query("token"),
|
||||||
To: c.Query("to"),
|
To: c.Query("to"),
|
||||||
|
Desp: c.Query("desp"),
|
||||||
|
Short: c.Query("short"),
|
||||||
|
OpenId: c.Query("openid"),
|
||||||
}
|
}
|
||||||
if message.Description == "" {
|
keepCompatible(&message)
|
||||||
// Keep compatible with ServerChan
|
|
||||||
message.Description = c.Query("desp")
|
|
||||||
}
|
|
||||||
if message.Channel == "" {
|
|
||||||
// Keep compatible with old version
|
|
||||||
message.Channel = c.Query("type")
|
|
||||||
}
|
|
||||||
pushMessageHelper(c, &message)
|
pushMessageHelper(c, &message)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,8 +51,10 @@ func PostPushMessage(c *gin.Context) {
|
|||||||
URL: c.PostForm("url"),
|
URL: c.PostForm("url"),
|
||||||
Channel: c.PostForm("channel"),
|
Channel: c.PostForm("channel"),
|
||||||
Token: c.PostForm("token"),
|
Token: c.PostForm("token"),
|
||||||
Desp: c.PostForm("desp"),
|
|
||||||
To: c.PostForm("to"),
|
To: c.PostForm("to"),
|
||||||
|
Desp: c.PostForm("desp"),
|
||||||
|
Short: c.PostForm("short"),
|
||||||
|
OpenId: c.PostForm("openid"),
|
||||||
}
|
}
|
||||||
if message == (model.Message{}) {
|
if message == (model.Message{}) {
|
||||||
// Looks like the user is using JSON
|
// Looks like the user is using JSON
|
||||||
@@ -56,9 +67,7 @@ func PostPushMessage(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if message.Description == "" {
|
keepCompatible(&message)
|
||||||
message.Description = message.Desp
|
|
||||||
}
|
|
||||||
pushMessageHelper(c, &message)
|
pushMessageHelper(c, &message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -11,7 +11,6 @@ type Message struct {
|
|||||||
UserId int `json:"user_id" gorm:"index"`
|
UserId int `json:"user_id" gorm:"index"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Desp string `json:"desp" gorm:"-:all"` // alias for description
|
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
URL string `json:"url" gorm:"column:url"`
|
URL string `json:"url" gorm:"column:url"`
|
||||||
Channel string `json:"channel"`
|
Channel string `json:"channel"`
|
||||||
@@ -21,6 +20,9 @@ type Message struct {
|
|||||||
Link string `json:"link" gorm:"unique;index"`
|
Link string `json:"link" gorm:"unique;index"`
|
||||||
To string `json:"to" gorm:"column:to"` // if specified, will send to this user(s)
|
To string `json:"to" gorm:"column:to"` // if specified, will send to this user(s)
|
||||||
Status int `json:"status" gorm:"default:0"` // pending, sent, failed
|
Status int `json:"status" gorm:"default:0"` // pending, sent, failed
|
||||||
|
OpenId string `json:"openid" gorm:"-:all"` // alias for to
|
||||||
|
Desp string `json:"desp" gorm:"-:all"` // alias for content
|
||||||
|
Short string `json:"short" gorm:"-:all"` // alias for description
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetMessageById(id int, userId int) (*Message, error) {
|
func GetMessageById(id int, userId int) (*Message, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user