report.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package http
  2. import (
  3. "io/ioutil"
  4. "mime/multipart"
  5. "net/http"
  6. "strconv"
  7. "go-common/app/interface/main/app-view/model"
  8. "go-common/library/ecode"
  9. "go-common/library/log"
  10. bm "go-common/library/net/http/blademaster"
  11. )
  12. func copyWriter(c *bm.Context) {
  13. params := c.Request.Form
  14. mobiApp := params.Get("mobi_app")
  15. device := params.Get("device")
  16. lang := params.Get("lang")
  17. aid, err := strconv.ParseInt(params.Get("aid"), 10, 64)
  18. if err != nil {
  19. c.JSON(nil, ecode.RequestErr)
  20. return
  21. }
  22. plat := model.Plat(mobiApp, device)
  23. c.JSON(reportSvr.CopyWriter(c, aid, plat, lang))
  24. }
  25. func addReport(c *bm.Context) {
  26. var mid int64
  27. if midInter, ok := c.Get("mid"); ok {
  28. mid = midInter.(int64)
  29. }
  30. params := c.Request.Form
  31. ak := params.Get("access_key")
  32. reason := params.Get("reason")
  33. pics := params.Get("pics")
  34. aid, err := strconv.ParseInt(params.Get("aid"), 10, 64)
  35. if err != nil {
  36. c.JSON(nil, ecode.RequestErr)
  37. return
  38. }
  39. tp, err := strconv.Atoi(params.Get("type"))
  40. if err != nil {
  41. c.JSON(nil, ecode.RequestErr)
  42. return
  43. }
  44. if tp < 0 || tp > 10 {
  45. c.JSON(nil, ecode.RequestErr)
  46. return
  47. }
  48. c.JSON(nil, reportSvr.AddReport(c, mid, aid, tp, ak, reason, pics))
  49. }
  50. func upload(c *bm.Context) {
  51. var (
  52. fileType string
  53. body []byte
  54. file multipart.File
  55. err error
  56. )
  57. if file, _, err = c.Request.FormFile("file"); err != nil {
  58. c.JSON(nil, ecode.RequestErr)
  59. log.Error("c.Request.FormFile(\"file\") error(%v)", err)
  60. return
  61. }
  62. defer file.Close()
  63. if body, err = ioutil.ReadAll(file); err != nil {
  64. c.JSON(nil, ecode.RequestErr)
  65. log.Error("ioutil.ReadAll(c.Request.Body) error(%v)", err)
  66. return
  67. }
  68. fileType = http.DetectContentType(body)
  69. url, err := reportSvr.Upload(c, fileType, body)
  70. c.JSON(struct {
  71. URL string `json:"url"`
  72. }{url}, err)
  73. }