creator_article.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/interface/main/creative/model/article"
  5. "go-common/app/interface/openplatform/article/model"
  6. "go-common/library/ecode"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/net/metadata"
  9. )
  10. func creatorArticlePre(c *bm.Context) {
  11. ip := metadata.String(c, metadata.RemoteIP)
  12. // check user
  13. midStr, _ := c.Get("mid")
  14. mid := midStr.(int64)
  15. if mid <= 0 {
  16. c.JSON(nil, ecode.CreativeNotLogin)
  17. return
  18. }
  19. var (
  20. isAuthor int
  21. reason string
  22. )
  23. ia, err := artSvc.IsAuthor(c, mid, ip)
  24. if err != nil {
  25. c.JSON(nil, err)
  26. return
  27. }
  28. if ia {
  29. isAuthor = 1
  30. } else {
  31. isAuthor = 0
  32. reason = "您还未开通专栏权限,请先在PC上进行申请"
  33. }
  34. c.JSON(map[string]interface{}{
  35. "is_author": isAuthor,
  36. "reason": reason,
  37. "submit_url": "https://member.bilibili.com/article-text/mobile",
  38. }, nil)
  39. }
  40. func creatorArticleList(c *bm.Context) {
  41. params := c.Request.Form
  42. pnStr := params.Get("pn")
  43. psStr := params.Get("ps")
  44. sortStr := params.Get("sort")
  45. groupStr := params.Get("group")
  46. categoryStr := params.Get("category")
  47. ip := metadata.String(c, metadata.RemoteIP)
  48. // check user
  49. midStr, _ := c.Get("mid")
  50. mid := midStr.(int64)
  51. if mid <= 0 {
  52. c.JSON(nil, ecode.CreativeNotLogin)
  53. return
  54. }
  55. pn, err := strconv.Atoi(pnStr)
  56. if err != nil || pn < 1 {
  57. pn = 1
  58. }
  59. ps, err := strconv.Atoi(psStr)
  60. if err != nil || ps <= 10 {
  61. ps = 20
  62. }
  63. sort, err := strconv.Atoi(sortStr)
  64. if err != nil || sort < 0 {
  65. sort = 0
  66. }
  67. group, err := strconv.Atoi(groupStr)
  68. if err != nil || group < 0 {
  69. group = 0
  70. }
  71. category, err := strconv.Atoi(categoryStr)
  72. if err != nil || category < 0 {
  73. category = 0
  74. }
  75. arts, err := artSvc.Articles(c, mid, int(pn), int(ps), sort, group, category, ip)
  76. if ecode.Cause(err) == ecode.ArtCreationNoPrivilege {
  77. err = nil
  78. }
  79. if err != nil {
  80. c.JSON(nil, err)
  81. return
  82. }
  83. if arts == nil {
  84. arts = &article.ArtList{
  85. Articles: []*article.Meta{},
  86. Type: &model.CreationArtsType{},
  87. Page: &model.ArtPage{},
  88. }
  89. }
  90. c.JSON(arts, nil)
  91. }
  92. func creatorArticle(c *bm.Context) {
  93. params := c.Request.Form
  94. aidStr := params.Get("aid")
  95. ip := metadata.String(c, metadata.RemoteIP)
  96. // check user
  97. midStr, _ := c.Get("mid")
  98. mid := midStr.(int64)
  99. if mid <= 0 {
  100. c.JSON(nil, ecode.CreativeNotLogin)
  101. return
  102. }
  103. aid, err := strconv.ParseInt(aidStr, 10, 64)
  104. if err != nil || aid <= 0 {
  105. c.JSON(nil, ecode.RequestErr)
  106. return
  107. }
  108. art, err := artSvc.View(c, aid, mid, ip)
  109. if err != nil {
  110. c.JSON(nil, err)
  111. return
  112. }
  113. c.JSON(art, nil)
  114. }
  115. func creatorDelArticle(c *bm.Context) {
  116. params := c.Request.Form
  117. aidStr := params.Get("aid")
  118. ip := metadata.String(c, metadata.RemoteIP)
  119. // check user
  120. midStr, _ := c.Get("mid")
  121. mid := midStr.(int64)
  122. if mid <= 0 {
  123. c.JSON(nil, ecode.CreativeNotLogin)
  124. return
  125. }
  126. aid, err := strconv.ParseInt(aidStr, 10, 64)
  127. if err != nil || aid <= 0 {
  128. c.JSON(nil, ecode.RequestErr)
  129. return
  130. }
  131. c.JSON(nil, artSvc.DelArticle(c, aid, mid, ip))
  132. }
  133. func creatorWithDrawArticle(c *bm.Context) {
  134. params := c.Request.Form
  135. aidStr := params.Get("aid")
  136. ip := metadata.String(c, metadata.RemoteIP)
  137. // check user
  138. midStr, _ := c.Get("mid")
  139. mid := midStr.(int64)
  140. if mid <= 0 {
  141. c.JSON(nil, ecode.CreativeNotLogin)
  142. return
  143. }
  144. aid, err := strconv.ParseInt(aidStr, 10, 64)
  145. if err != nil || aid <= 0 {
  146. c.JSON(nil, ecode.RequestErr)
  147. return
  148. }
  149. c.JSON(nil, artSvc.WithDrawArticle(c, aid, mid, ip))
  150. }
  151. func creatorDraftList(c *bm.Context) {
  152. params := c.Request.Form
  153. pnStr := params.Get("pn")
  154. psStr := params.Get("ps")
  155. ip := metadata.String(c, metadata.RemoteIP)
  156. // check user
  157. midStr, _ := c.Get("mid")
  158. mid := midStr.(int64)
  159. if mid <= 0 {
  160. c.JSON(nil, ecode.CreativeNotLogin)
  161. return
  162. }
  163. pn, err := strconv.Atoi(pnStr)
  164. if err != nil || pn < 1 {
  165. pn = 1
  166. }
  167. ps, err := strconv.Atoi(psStr)
  168. if err != nil || ps <= 10 {
  169. ps = 20
  170. }
  171. arts, err := artSvc.Drafts(c, mid, pn, ps, ip)
  172. if ecode.Cause(err) == ecode.ArtCreationNoPrivilege {
  173. err = nil
  174. }
  175. if err != nil {
  176. c.JSON(nil, err)
  177. return
  178. }
  179. if arts == nil {
  180. arts = &article.DraftList{
  181. Drafts: []*article.Meta{},
  182. Page: &model.ArtPage{},
  183. }
  184. }
  185. c.JSON(arts, nil)
  186. }