apply.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package http
  2. import (
  3. "go-common/app/interface/openplatform/article/conf"
  4. "go-common/library/ecode"
  5. bm "go-common/library/net/http/blademaster"
  6. "strconv"
  7. )
  8. func applyInfo(c *bm.Context) {
  9. var (
  10. mid int64
  11. )
  12. // get mid
  13. if midInter, ok := c.Get("mid"); ok {
  14. mid = midInter.(int64)
  15. }
  16. c.JSON(artSrv.ApplyInfo(c, mid))
  17. }
  18. func apply(c *bm.Context) {
  19. var (
  20. mid int64
  21. request = c.Request
  22. params = request.Form
  23. content, category string
  24. )
  25. // get mid
  26. midInter, _ := c.Get("mid")
  27. mid = midInter.(int64)
  28. content = params.Get("content")
  29. if int64(len([]rune(content))) > conf.Conf.Article.MaxApplyContentLimit {
  30. c.JSON(nil, ecode.RequestErr)
  31. return
  32. }
  33. category = params.Get("category")
  34. if int64(len([]rune(category))) > conf.Conf.Article.MaxApplyCategoryLimit {
  35. c.JSON(nil, ecode.RequestErr)
  36. return
  37. }
  38. c.JSON(nil, artSrv.Apply(c, mid, content, category))
  39. }
  40. func isAuthor(c *bm.Context) {
  41. var (
  42. mid, mediaID int64
  43. err error
  44. author, forbid bool
  45. id int64
  46. level = true
  47. canEdit = true
  48. )
  49. // get mid
  50. midInter, _ := c.Get("mid")
  51. mid = midInter.(int64)
  52. mediaIDStr := c.Request.Form.Get("media_id")
  53. if mediaIDStr != "" {
  54. mediaID, err = strconv.ParseInt(mediaIDStr, 10, 64)
  55. if err != nil || mediaID < 0 {
  56. c.JSON(nil, ecode.RequestErr)
  57. return
  58. }
  59. }
  60. if mediaID > 0 {
  61. if level, err = artSrv.LevelRequired(c, mid); err != nil {
  62. c.JSON(nil, ecode.RequestErr)
  63. return
  64. }
  65. if id, err = artSrv.MediaArticle(c, mediaID, mid); err != nil {
  66. c.JSON(nil, ecode.RequestErr)
  67. return
  68. }
  69. if id > 0 && artSrv.EditTimes(c, id) <= 0 {
  70. canEdit = false
  71. }
  72. }
  73. if author, forbid, err = artSrv.IsAuthor(c, mid); err != nil {
  74. c.JSON(nil, err)
  75. return
  76. }
  77. c.JSON(map[string]interface{}{"is_author": author, "forbid": forbid, "level": level, "id": id, "can_edit": canEdit}, nil)
  78. }
  79. func addAuthor(c *bm.Context) {
  80. var (
  81. mid int64
  82. )
  83. midInter, _ := c.Get("mid")
  84. mid = midInter.(int64)
  85. c.JSON(nil, artSrv.AddAuthor(c, mid))
  86. }