archive.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/interface/main/web/model"
  5. "go-common/library/ecode"
  6. bm "go-common/library/net/http/blademaster"
  7. )
  8. const (
  9. _buvid = "buvid3"
  10. )
  11. func view(c *bm.Context) {
  12. var (
  13. aid, mid, cid int64
  14. cookieStr string
  15. err error
  16. rs *model.View
  17. )
  18. cookieStr = c.Request.Header.Get("Cookie")
  19. aidStr := c.Request.Form.Get("aid")
  20. if aid, err = strconv.ParseInt(aidStr, 10, 64); err != nil || aid <= 0 {
  21. c.JSON(nil, ecode.RequestErr)
  22. return
  23. }
  24. // get mid
  25. if midInter, ok := c.Get("mid"); ok {
  26. mid = midInter.(int64)
  27. }
  28. cidStr := c.Request.Form.Get("cid")
  29. if cidStr != "" {
  30. if cid, err = strconv.ParseInt(cidStr, 10, 64); err != nil || cid < 0 {
  31. c.JSON(nil, ecode.RequestErr)
  32. return
  33. }
  34. }
  35. cdnIP := c.Request.Header.Get("X-Cache-Server-Addr")
  36. if rs, err = webSvc.View(c, aid, cid, mid, cdnIP, cookieStr); err != nil {
  37. c.JSON(nil, err)
  38. return
  39. }
  40. c.JSON(rs, nil)
  41. }
  42. func archiveStat(c *bm.Context) {
  43. var (
  44. aid int64
  45. err error
  46. )
  47. aidStr := c.Request.Form.Get("aid")
  48. if aid, err = strconv.ParseInt(aidStr, 10, 64); err != nil || aid <= 0 {
  49. c.JSON(nil, ecode.RequestErr)
  50. return
  51. }
  52. c.JSON(webSvc.ArchiveStat(c, aid))
  53. }
  54. func addShare(c *bm.Context) {
  55. var (
  56. aid, mid int64
  57. err error
  58. buvid, sid string
  59. )
  60. aidStr := c.Request.Form.Get("aid")
  61. if aid, err = strconv.ParseInt(aidStr, 10, 64); err != nil || aid <= 0 {
  62. c.JSON(nil, ecode.RequestErr)
  63. return
  64. }
  65. // get mid
  66. if midInter, ok := c.Get("mid"); ok {
  67. mid = midInter.(int64)
  68. }
  69. if bdCookie, _ := c.Request.Cookie(_buvid); bdCookie != nil {
  70. buvid = bdCookie.Value
  71. }
  72. if sidCookie, _ := c.Request.Cookie("sid"); sidCookie != nil {
  73. sid = sidCookie.Value
  74. }
  75. c.JSON(webSvc.AddShare(c, aid, mid, c.Request.UserAgent(), c.Request.Referer(), c.Request.URL.Path, buvid, sid))
  76. }
  77. func description(c *bm.Context) {
  78. var (
  79. aid, page int64
  80. err error
  81. )
  82. params := c.Request.Form
  83. aidStr := params.Get("aid")
  84. if aid, err = strconv.ParseInt(aidStr, 10, 64); err != nil || aid <= 0 {
  85. c.JSON(nil, ecode.RequestErr)
  86. return
  87. }
  88. pstr := params.Get("page")
  89. if pstr != "" {
  90. if page, err = strconv.ParseInt(pstr, 10, 64); err != nil || page < 0 {
  91. c.JSON(nil, ecode.RequestErr)
  92. return
  93. }
  94. }
  95. c.JSON(webSvc.Description(c, aid, page))
  96. }
  97. func arcReport(c *bm.Context) {
  98. var (
  99. aid, mid, tp int64
  100. err error
  101. params = c.Request.Form
  102. )
  103. midStr, _ := c.Get("mid")
  104. mid = midStr.(int64)
  105. aidStr := params.Get("aid")
  106. tpStr := params.Get("type")
  107. reason := params.Get("reason")
  108. pics := params.Get("pics")
  109. if aid, err = strconv.ParseInt(aidStr, 10, 64); err != nil {
  110. c.JSON(nil, ecode.RequestErr)
  111. return
  112. }
  113. if tp, err = strconv.ParseInt(tpStr, 10, 64); err != nil {
  114. c.JSON(nil, ecode.RequestErr)
  115. return
  116. }
  117. c.JSON(nil, webSvc.ArcReport(c, mid, aid, tp, reason, pics))
  118. }
  119. func appealTags(c *bm.Context) {
  120. c.JSON(webSvc.AppealTags(c))
  121. }
  122. func arcAppeal(c *bm.Context) {
  123. var (
  124. mid int64
  125. err error
  126. )
  127. params := c.Request.Form
  128. midStr, _ := c.Get("mid")
  129. mid = midStr.(int64)
  130. data := make(map[string]string)
  131. for name := range params {
  132. switch name {
  133. case "tid":
  134. tidStr := params.Get("tid")
  135. if _, err = strconv.ParseInt(tidStr, 10, 64); err != nil {
  136. c.JSON(nil, ecode.RequestErr)
  137. return
  138. }
  139. data["tid"] = tidStr
  140. case "aid":
  141. aidStr := params.Get("aid")
  142. if _, err = strconv.ParseInt(aidStr, 10, 64); err != nil {
  143. c.JSON(nil, ecode.RequestErr)
  144. return
  145. }
  146. data["oid"] = aidStr
  147. case "desc":
  148. desc := params.Get("desc")
  149. if desc == "" {
  150. c.JSON(nil, ecode.RequestErr)
  151. return
  152. }
  153. data["description"] = desc
  154. default:
  155. data[name] = params.Get(name)
  156. }
  157. }
  158. c.JSON(nil, webSvc.ArcAppeal(c, mid, data))
  159. }
  160. func authorRecommend(c *bm.Context) {
  161. var (
  162. aid int64
  163. err error
  164. )
  165. params := c.Request.Form
  166. aidStr := params.Get("aid")
  167. if aid, err = strconv.ParseInt(aidStr, 10, 64); err != nil || aid <= 0 {
  168. c.JSON(nil, ecode.RequestErr)
  169. return
  170. }
  171. c.JSON(webSvc.AuthorRecommend(c, aid))
  172. }
  173. func relatedArcs(c *bm.Context) {
  174. v := new(struct {
  175. Aid int64 `form:"aid" validate:"min=1"`
  176. })
  177. if err := c.Bind(v); err != nil {
  178. return
  179. }
  180. c.JSON(webSvc.RelatedArcs(c, v.Aid))
  181. }
  182. func detail(c *bm.Context) {
  183. var (
  184. mid int64
  185. err error
  186. rs *model.Detail
  187. )
  188. v := new(struct {
  189. Aid int64 `form:"aid" validate:"min=1"`
  190. })
  191. if err = c.Bind(v); err != nil {
  192. return
  193. }
  194. if midStr, ok := c.Get("mid"); ok {
  195. mid = midStr.(int64)
  196. }
  197. cdnIP := c.Request.Header.Get("X-Cache-Server-Addr")
  198. if rs, err = webSvc.Detail(c, v.Aid, mid, cdnIP, c.Request.Header.Get("Cookie")); err != nil {
  199. c.JSON(nil, err)
  200. return
  201. }
  202. c.JSON(rs, nil)
  203. }
  204. func arcUGCPay(c *bm.Context) {
  205. v := new(struct {
  206. Aid int64 `form:"aid" validate:"min=1"`
  207. })
  208. if err := c.Bind(v); err != nil {
  209. return
  210. }
  211. midStr, _ := c.Get("mid")
  212. mid := midStr.(int64)
  213. c.JSON(webSvc.ArcUGCPay(c, mid, v.Aid))
  214. }
  215. func arcRelation(c *bm.Context) {
  216. v := new(struct {
  217. Aid int64 `form:"aid" validate:"min=1"`
  218. })
  219. if err := c.Bind(v); err != nil {
  220. return
  221. }
  222. midStr, _ := c.Get("mid")
  223. mid := midStr.(int64)
  224. c.JSON(webSvc.ArcRelation(c, mid, v.Aid))
  225. }