archive.go 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. package http
  2. import (
  3. "encoding/json"
  4. "io/ioutil"
  5. "go-common/app/admin/main/videoup/model/archive"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. bm "go-common/library/net/http/blademaster"
  9. "go-common/library/xstr"
  10. )
  11. // submit second_round submit.
  12. func submit(c *bm.Context) {
  13. var (
  14. req = c.Request
  15. bs []byte
  16. err error
  17. )
  18. if bs, err = ioutil.ReadAll(req.Body); err != nil {
  19. log.Error("ioutil.ReadAll() error(%v)", err)
  20. c.JSON(nil, ecode.RequestErr)
  21. return
  22. }
  23. req.Body.Close()
  24. // params
  25. var ap = &archive.ArcParam{}
  26. if err = json.Unmarshal(bs, ap); err != nil {
  27. log.Error("http submit() json.Unmarshal(%s) error(%v)", string(bs), err)
  28. c.JSON(nil, ecode.RequestErr)
  29. return
  30. }
  31. // TODO check data.
  32. if err = vdaSvc.Submit(c, ap); err != nil {
  33. log.Error("vdaSvc.Submit() error(%v)", err)
  34. c.JSON(nil, err)
  35. return
  36. }
  37. c.JSON(nil, nil)
  38. }
  39. // batchSubmit batch submit by async.
  40. func batchArchive(c *bm.Context) {
  41. var (
  42. req = c.Request
  43. bs []byte
  44. err error
  45. aps []*archive.ArcParam
  46. )
  47. if bs, err = ioutil.ReadAll(req.Body); err != nil {
  48. log.Error("ioutil.ReadAll() error(%v)", err)
  49. c.JSON(nil, ecode.RequestErr)
  50. return
  51. }
  52. req.Body.Close()
  53. // params
  54. if err = json.Unmarshal(bs, &aps); err != nil {
  55. log.Error("http submit() json.Unmarshal(%s) error(%v)", string(bs), err)
  56. c.JSON(nil, ecode.RequestErr)
  57. return
  58. }
  59. if ok := vdaSvc.CheckArchive(aps); !ok {
  60. c.JSON(nil, ecode.RequestErr)
  61. return
  62. }
  63. // TODO check data.
  64. if err = vdaSvc.BatchArchive(c, aps, archive.ActionArchiveSubmit); err != nil {
  65. log.Error("vdaSvc.BatchSubmit() error(%v)", err)
  66. c.JSON(nil, err)
  67. return
  68. }
  69. c.JSON(nil, nil)
  70. }
  71. // batchArchiveSecondRound batch submit by async.
  72. func batchArchiveSecondRound(c *bm.Context) {
  73. var (
  74. req = c.Request
  75. bs []byte
  76. err error
  77. aps []*archive.ArcParam
  78. )
  79. if bs, err = ioutil.ReadAll(req.Body); err != nil {
  80. log.Error("ioutil.ReadAll() error(%v)", err)
  81. c.JSON(nil, ecode.RequestErr)
  82. return
  83. }
  84. req.Body.Close()
  85. // params
  86. if err = json.Unmarshal(bs, &aps); err != nil {
  87. log.Error("http submit() json.Unmarshal(%s) error(%v)", string(bs), err)
  88. c.JSON(nil, ecode.RequestErr)
  89. return
  90. }
  91. if ok := vdaSvc.CheckArchive(aps); !ok {
  92. c.JSON(nil, ecode.RequestErr)
  93. return
  94. }
  95. // TODO check data.
  96. if err = vdaSvc.BatchArchive(c, aps, archive.ActionArchiveSecondRound); err != nil {
  97. log.Error("vdaSvc.BatchSubmit() error(%v)", err)
  98. c.JSON(nil, err)
  99. return
  100. }
  101. c.JSON(nil, nil)
  102. }
  103. // batchAttrs batch attr by async.
  104. func batchAttrs(c *bm.Context) {
  105. var (
  106. req = c.Request
  107. bs []byte
  108. err error
  109. aps []*archive.ArcParam
  110. )
  111. if bs, err = ioutil.ReadAll(req.Body); err != nil {
  112. log.Error("ioutil.ReadAll() error(%v)", err)
  113. c.JSON(nil, ecode.RequestErr)
  114. return
  115. }
  116. req.Body.Close()
  117. // params
  118. if err = json.Unmarshal(bs, &aps); err != nil {
  119. log.Error("http submit() json.Unmarshal(%s) error(%v)", string(bs), err)
  120. c.JSON(nil, ecode.RequestErr)
  121. return
  122. }
  123. if ok := vdaSvc.CheckArchive(aps); !ok {
  124. c.JSON(nil, ecode.RequestErr)
  125. return
  126. }
  127. // TODO check data.
  128. if err = vdaSvc.BatchArchive(c, aps, archive.ActionArchiveAttr); err != nil {
  129. log.Error("vdaSvc.BatchSubmit() error(%v)", err)
  130. c.JSON(nil, err)
  131. return
  132. }
  133. c.JSON(nil, nil)
  134. }
  135. // batchTypeIDs batch typeid by async.
  136. func batchTypeIDs(c *bm.Context) {
  137. var (
  138. req = c.Request
  139. bs []byte
  140. err error
  141. aps []*archive.ArcParam
  142. )
  143. if bs, err = ioutil.ReadAll(req.Body); err != nil {
  144. log.Error("ioutil.ReadAll() error(%v)", err)
  145. c.JSON(nil, ecode.RequestErr)
  146. return
  147. }
  148. req.Body.Close()
  149. // params
  150. if err = json.Unmarshal(bs, &aps); err != nil {
  151. log.Error("http submit() json.Unmarshal(%s) error(%v)", string(bs), err)
  152. c.JSON(nil, ecode.RequestErr)
  153. return
  154. }
  155. if ok := vdaSvc.CheckArchive(aps); !ok {
  156. c.JSON(nil, ecode.RequestErr)
  157. return
  158. }
  159. // TODO check data.
  160. if err = vdaSvc.BatchArchive(c, aps, archive.ActionArchiveTypeID); err != nil {
  161. log.Error("vdaSvc.BatchSubmit() error(%v)", err)
  162. c.JSON(nil, err)
  163. return
  164. }
  165. c.JSON(nil, nil)
  166. }
  167. // // batchZlimit batch modify zlimit.
  168. // func batchZlimit(c wctx.Context) {
  169. // var (
  170. // req = c.Request()
  171. // res = c.Result()
  172. // bs []byte
  173. // err error
  174. // )
  175. // if bs, err = ioutil.ReadAll(req.Body); err != nil {
  176. // log.Error("ioutil.ReadAll() error(%v)", err)
  177. // res["code"] = ecode.RequestErr
  178. // return
  179. // }
  180. // req.Body.Close()
  181. // // params
  182. // var ap = &archive.ArcParam{}
  183. // if err = json.Unmarshal(bs, ap); err != nil {
  184. // log.Error("http submit() json.Unmarshal(%s) error(%v)", string(bs), err)
  185. // res["code"] = ecode.RequestErr
  186. // return
  187. // }
  188. // if len(ap.Aids) == 0 {
  189. // res["code"] = ecode.RequestErr
  190. // return
  191. // }
  192. // if err = vdaSvc.BatchZlimit(c, ap); err != nil {
  193. // log.Error("vdaSvc.submit() error(%v)", err)
  194. // res["code"] = err
  195. // return
  196. // }
  197. // }
  198. // upAuther batch modify zlimit.
  199. func upAuther(c *bm.Context) {
  200. var (
  201. req = c.Request
  202. bs []byte
  203. err error
  204. )
  205. if bs, err = ioutil.ReadAll(req.Body); err != nil {
  206. log.Error("ioutil.ReadAll() error(%v)", err)
  207. c.JSON(nil, ecode.RequestErr)
  208. return
  209. }
  210. req.Body.Close()
  211. // params
  212. var ap = &archive.ArcParam{}
  213. if err = json.Unmarshal(bs, ap); err != nil {
  214. log.Error("http submit() json.Unmarshal(%s) error(%v)", string(bs), err)
  215. c.JSON(nil, ecode.RequestErr)
  216. return
  217. }
  218. if err = vdaSvc.UpAuther(c, ap); err != nil {
  219. log.Error("vdaSvc.UpAuther() error(%v)", err)
  220. c.JSON(nil, err)
  221. return
  222. }
  223. c.JSON(nil, nil)
  224. }
  225. // upAuther batch modify zlimit.
  226. func upAccess(c *bm.Context) {
  227. var (
  228. req = c.Request
  229. bs []byte
  230. err error
  231. )
  232. if bs, err = ioutil.ReadAll(req.Body); err != nil {
  233. log.Error("ioutil.ReadAll() error(%v)", err)
  234. c.JSON(nil, ecode.RequestErr)
  235. return
  236. }
  237. req.Body.Close()
  238. // params
  239. var ap = &archive.ArcParam{}
  240. if err = json.Unmarshal(bs, ap); err != nil {
  241. log.Error("http submit() json.Unmarshal(%s) error(%v)", string(bs), err)
  242. c.JSON(nil, ecode.RequestErr)
  243. return
  244. }
  245. if err = vdaSvc.UpAccess(c, ap); err != nil {
  246. log.Error("vdaSvc.UpAccess() error(%v)", err)
  247. c.JSON(nil, err)
  248. return
  249. }
  250. c.JSON(nil, nil)
  251. }
  252. func upArcTag(c *bm.Context) {
  253. pm := new(archive.TagParam)
  254. if err := c.Bind(pm); err != nil {
  255. c.JSON(nil, err)
  256. return
  257. }
  258. uid, _ := getUIDName(c)
  259. c.JSON(nil, vdaSvc.UpArcTag(c, uid, pm))
  260. }
  261. //通用批量tag接口 添加tag或者删除tag接口
  262. // a.支持频道回查 form_list = channel_review
  263. // b.支持adminBind/upBind(默认走adminBind) is_up_bind=true
  264. // c.支持同步隐藏tag sync_hidden_tag=true
  265. //todo 因为稿件服务不cache tags 也不需要发force_sync.未来计划砍掉审核库archive.tag
  266. func batchTag(c *bm.Context) {
  267. var err error
  268. pm := new(archive.BatchTagParam)
  269. if err = c.Bind(pm); err != nil {
  270. c.JSON(nil, ecode.RequestErr)
  271. return
  272. }
  273. //仅同步隐藏tag时 批量tag操作 pm.tags为空 && SyncHiddenTag = true
  274. if (pm.Action != "" && pm.Action != "add" && pm.Action != "delete") || (pm.Action != "" && pm.Tags == "" && !pm.SyncHiddenTag) {
  275. c.JSON(nil, ecode.RequestErr)
  276. return
  277. }
  278. if pm.Action == "" && pm.Tags == "" && pm.FromList != archive.FromListChannelReview {
  279. c.JSON(nil, nil)
  280. return
  281. }
  282. uid, _ := getUIDName(c)
  283. data := map[string]interface{}{}
  284. data["message"], err = vdaSvc.BatchUpTag(c, uid, pm)
  285. c.JSONMap(data, err)
  286. }
  287. func channelInfo(c *bm.Context) {
  288. aid := c.Request.Form.Get("aid")
  289. aids, err := xstr.SplitInts(aid)
  290. if err != nil {
  291. log.Error("channelInfo xstr.SplitInts(%s) error(%v)", aid, err)
  292. c.JSON(nil, ecode.RequestErr)
  293. return
  294. }
  295. //批量上线50个
  296. if len(aids) > 50 || len(aids) <= 0 {
  297. c.JSON(nil, ecode.RequestErr)
  298. return
  299. }
  300. data := map[string]interface{}{}
  301. data["data"], err = vdaSvc.GetChannelInfo(c, aids)
  302. if err != nil {
  303. data["message"] = "频道查询API异常"
  304. }
  305. c.JSONMap(data, err)
  306. }
  307. func aiTrack(c *bm.Context) {
  308. v := new(struct {
  309. Aid []int64 `form:"aid,split" validate:"required"`
  310. })
  311. if err := c.Bind(v); err != nil {
  312. c.JSON(nil, ecode.RequestErr)
  313. return
  314. }
  315. c.JSON(vdaSvc.AITrack(c, v.Aid))
  316. }