(ctx *gin.Context)
| 41 | c.sendMsg(ctx, token, msg.SoundName(ctx.Query("sound")).SetPriority(parsePriority(ctx.Query("priority"))).SetInterruptionLevel(ctx.Query("interruption-level"))) |
| 42 | } |
| 43 | func (c *Core) handlePostSender(ctx *gin.Context) { |
| 44 | params := &MsgParam{} |
| 45 | params.Token, _ = c.parseToken(getToken(ctx)) |
| 46 | params.Link = ctx.Query("link") |
| 47 | params.Title = ctx.Query("title") |
| 48 | params.Sound = ctx.Query("sound") |
| 49 | params.AutoCopy = ctx.Query("autocopy") |
| 50 | params.CopyText = ctx.Query("copy") |
| 51 | params.Filename = fileBaseName(ctx.Query("filename")) |
| 52 | params.Priority = parsePriority(ctx.Query("priority")) |
| 53 | params.InterruptionLevel = ctx.Query("interruption-level") |
| 54 | params.TimeContent.Code = ctx.Query("timeline-code") |
| 55 | |
| 56 | var err error |
| 57 | var msg *model.Message = nil |
| 58 | var parser func(c *Core, ctx *gin.Context) (*model.Message, error) = nil |
| 59 | |
| 60 | ctype := ctx.Query("content-type") |
| 61 | if len(ctype) <= 0 { |
| 62 | ctype = ctx.ContentType() |
| 63 | } |
| 64 | switch ctype { |
| 65 | case "text/plain", "text": |
| 66 | params.ParsePlainText(ctx) |
| 67 | case "application/json", "json": |
| 68 | params.ParseJSON(c, ctx) |
| 69 | case "multipart/form-data": |
| 70 | parser = params.ParseFormData |
| 71 | case "image/png", "image/jpeg": |
| 72 | parser = params.ParseImage |
| 73 | case "audio/mpeg": |
| 74 | parser = params.ParseAudio |
| 75 | default: |
| 76 | params.ParseForm(c, ctx) |
| 77 | } |
| 78 | if parser != nil { |
| 79 | msg, err = parser(c, ctx) |
| 80 | if err != nil { |
| 81 | return |
| 82 | } |
| 83 | } |
| 84 | if params.Token == nil { |
| 85 | ctx.JSON(http.StatusUnauthorized, gin.H{"res": http.StatusUnauthorized, "msg": "invalid token format"}) |
| 86 | return |
| 87 | } |
| 88 | if msg == nil { |
| 89 | if len(params.Link) > 0 { |
| 90 | msg = model.NewMessage(params.Token).LinkContent(params.Link) |
| 91 | } else if len(params.TimeContent.Code) > 0 { |
| 92 | msg = model.NewMessage(params.Token).TimelineContent(params.TimeContent.Code, params.Title, params.TimeContent.Timestamp, params.TimeContent.Items) |
| 93 | } else if len(params.Text) <= 0 { |
| 94 | ctx.JSON(http.StatusNoContent, gin.H{"res": http.StatusNoContent, "msg": "no message content"}) |
| 95 | return |
| 96 | } else { |
| 97 | var err error |
| 98 | msg, err = c.makeTextContent(model.NewMessage(params.Token), params.Text, params.Title, params.CopyText, params.AutoCopy, params.Actions) |
| 99 | if err != nil { |
| 100 | ctx.JSON(http.StatusRequestEntityTooLarge, gin.H{"res": http.StatusRequestEntityTooLarge, "msg": "too large text content"}) |
nothing calls this directly
no test coverage detected