| 106 | } |
| 107 | |
| 108 | func (c *Core) sendDirect(ctx sendContext, token *model.Token, msg *model.Message) { |
| 109 | uid := token.GetUserID() |
| 110 | key, err := c.logic.GetUserKey(uid) |
| 111 | if err != nil { |
| 112 | ctx.JSON(http.StatusBadRequest, gin.H{"res": http.StatusBadRequest, "msg": "invalid user"}) |
| 113 | return |
| 114 | } |
| 115 | devs, err := c.logic.GetDevices(uid) |
| 116 | if err != nil || len(devs) <= 0 { |
| 117 | ctx.JSON(http.StatusNotFound, gin.H{"res": http.StatusNotFound, "msg": "no devices found"}) |
| 118 | return |
| 119 | } |
| 120 | out := msg.EncryptData(key, uint64(time.Now().UTC().UnixNano())) |
| 121 | if len(out) > 4000 { |
| 122 | ctx.JSON(http.StatusRequestEntityTooLarge, gin.H{"res": http.StatusRequestEntityTooLarge, "msg": "message body too large"}) |
| 123 | return |
| 124 | } |
| 125 | uuid, n := c.logic.SendAPNS(uid, out, devs, int(msg.Priority), "passive", msg.IsTimeline()) |
| 126 | if n <= 0 { |
| 127 | ctx.JSON(http.StatusNotFound, gin.H{"res": http.StatusNotFound, "msg": "no devices send success"}) |
| 128 | return |
| 129 | } |
| 130 | ctx.JSON(http.StatusOK, gin.H{"request-uid": uuid}) |
| 131 | } |
| 132 | |
| 133 | func (c *Core) sendForward(ctx sendContext, token *model.Token, msg *model.Message) { |
| 134 | msg.DisableToken() |