video.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. package http
  2. import (
  3. "strconv"
  4. "strings"
  5. "go-common/app/interface/main/favorite/conf"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. "go-common/library/log/infoc"
  9. bm "go-common/library/net/http/blademaster"
  10. "go-common/library/xstr"
  11. )
  12. // videoFolders get all favorite folders
  13. func videoFolders(c *bm.Context) {
  14. var (
  15. uid int64
  16. mid int64
  17. vmid int64
  18. aid int64
  19. err error
  20. isSelf bool
  21. mediaList bool
  22. fromWeb bool
  23. )
  24. req := c.Request
  25. if midI, ok := c.Get("mid"); ok {
  26. mid = midI.(int64)
  27. }
  28. if req.Form.Get("medialist") == "1" {
  29. mediaList = true
  30. }
  31. params := req.URL.Query()
  32. app := params.Get("mobi_app")
  33. build, _ := strconv.ParseInt(params.Get("build"), 10, 64)
  34. device := params.Get("device")
  35. if (app == "android" && build >= 5360001 && build <= 5361000) || (app == "iphone" && build == 8300 && device == "phone") {
  36. mediaList = true
  37. }
  38. if app == "" {
  39. fromWeb = true
  40. }
  41. vmidStr := req.Form.Get("vmid")
  42. if vmidStr != "" {
  43. uid, err = strconv.ParseInt(vmidStr, 10, 64)
  44. if err != nil {
  45. c.JSON(nil, err)
  46. return
  47. }
  48. if uid <= 0 {
  49. c.JSON(nil, ecode.RequestErr)
  50. return
  51. }
  52. isSelf = mid == uid
  53. vmid = uid
  54. } else if mid != 0 {
  55. uid = mid
  56. isSelf = true
  57. } else {
  58. c.JSON(nil, ecode.RequestErr)
  59. return
  60. }
  61. aidStr := req.Form.Get("aid")
  62. if aidStr != "" {
  63. if aid, err = strconv.ParseInt(aidStr, 10, 64); err != nil {
  64. log.Error("strconv.ParseInt(aid:%s)", aidStr)
  65. return
  66. }
  67. }
  68. data, err := favSvc.FavFolders(c, mid, vmid, uid, aid, isSelf, mediaList, fromWeb)
  69. c.JSON(data, err)
  70. }
  71. // addVideoFolder add a folder.
  72. func addVideoFolder(c *bm.Context) {
  73. mid, _ := c.Get("mid")
  74. params := c.Request.Form
  75. name := params.Get("name")
  76. pubStr := params.Get("public")
  77. if name == "" || len([]rune(name)) > conf.Conf.Fav.MaxNameLen {
  78. log.Warn("arg name(%s) is empty or it's length more than %d", name, conf.Conf.Fav.MaxNameLen)
  79. c.JSON(nil, ecode.FavNameTooLong)
  80. return
  81. }
  82. var (
  83. pub int64
  84. err error
  85. )
  86. if pubStr != "" {
  87. if pub, err = strconv.ParseInt(pubStr, 10, 64); err != nil || pub < 0 || pub > 1 {
  88. pub = 0
  89. }
  90. }
  91. var fid int64
  92. if fid, err = favSvc.AddFavFolder(c, mid.(int64), name, c.Request.Header.Get("Cookie"), params.Get("access_key"), int32(pub)); err != nil {
  93. c.JSON(nil, err)
  94. return
  95. }
  96. data := map[string]int64{
  97. "fid": fid,
  98. }
  99. c.JSON(data, nil)
  100. }
  101. // renameVideoFolder rename folder.
  102. func renameVideoFolder(c *bm.Context) {
  103. mid, _ := c.Get("mid")
  104. params := c.Request.Form
  105. fidStr := params.Get("fid")
  106. name := params.Get("name")
  107. if fidStr == "" {
  108. log.Warn("arg fid is empty")
  109. c.JSON(nil, ecode.RequestErr)
  110. return
  111. }
  112. if name == "" || len([]rune(name)) > conf.Conf.Fav.MaxNameLen {
  113. log.Warn("arg name(%s) is empty or it's length more than %d", name, conf.Conf.Fav.MaxNameLen)
  114. c.JSON(nil, ecode.FavNameTooLong)
  115. return
  116. }
  117. fid, err := strconv.ParseInt(fidStr, 10, 64)
  118. if err != nil {
  119. log.Error("strconv.ParseInt(%s) error(%v)", fidStr, err)
  120. c.JSON(nil, ecode.RequestErr)
  121. return
  122. }
  123. err = favSvc.UpFavName(c, mid.(int64), fid, name, c.Request.Header.Get("Cookie"), params.Get("access_key"))
  124. c.JSON(nil, err)
  125. }
  126. // upStateVideoFolder update folder's state.
  127. func upStateVideoFolder(c *bm.Context) {
  128. mid, _ := c.Get("mid")
  129. params := c.Request.Form
  130. fidStr := params.Get("fid")
  131. pubStr := params.Get("public")
  132. if fidStr == "" || pubStr == "" {
  133. log.Warn("method fid(%s) public(%s) is empty", fidStr, pubStr)
  134. c.JSON(nil, ecode.RequestErr)
  135. return
  136. }
  137. fid, err := strconv.ParseInt(fidStr, 10, 64)
  138. if err != nil {
  139. log.Error("strconv.ParseInt(%s) error(%v)", fidStr, err)
  140. c.JSON(nil, ecode.RequestErr)
  141. return
  142. }
  143. public, err := strconv.Atoi(pubStr)
  144. if err != nil {
  145. log.Error("strconv.ParseInt(%s) error(%v)", pubStr, err)
  146. c.JSON(nil, ecode.RequestErr)
  147. return
  148. }
  149. err = favSvc.UpFavState(c, mid.(int64), fid, int32(public), c.Request.Header.Get("Cookie"), params.Get("access_key"))
  150. c.JSON(nil, err)
  151. }
  152. // delVideoFolder delete folder.
  153. func delVideoFolder(c *bm.Context) {
  154. mid, _ := c.Get("mid")
  155. params := c.Request.Form
  156. fidStr := params.Get("fid")
  157. if fidStr == "" {
  158. log.Warn("method fid(%s) is empty", fidStr)
  159. c.JSON(nil, ecode.RequestErr)
  160. return
  161. }
  162. fid, err := strconv.ParseInt(fidStr, 10, 64)
  163. if err != nil {
  164. log.Error("strconv.ParseInt(%s) error(%v)", fidStr, err)
  165. c.JSON(nil, ecode.RequestErr)
  166. return
  167. }
  168. err = favSvc.DelVideoFolder(c, mid.(int64), fid)
  169. c.JSON(nil, err)
  170. }
  171. // sortFavFolders sort all favorite folders
  172. func sortVideoFolders(c *bm.Context) {
  173. var (
  174. fids []int64
  175. err error
  176. )
  177. params := c.Request.Form
  178. fidStr := params.Get("fids")
  179. mid, _ := c.Get("mid")
  180. if fidStr == "" {
  181. log.Error("arg fids is empty")
  182. c.JSON(nil, ecode.RequestErr)
  183. return
  184. }
  185. fids, err = xstr.SplitInts(fidStr)
  186. if err != nil {
  187. log.Error("xstr.SplitInts(%s) error(%v)", fidStr, err)
  188. c.JSON(nil, ecode.RequestErr)
  189. return
  190. }
  191. err = favSvc.SetVideoFolderSort(c, mid.(int64), fids)
  192. c.JSON(nil, err)
  193. }
  194. // favVideo return all videos in the fid folder.
  195. func favVideo(c *bm.Context) {
  196. // params
  197. params := c.Request.Form
  198. vmidStr := params.Get("vmid")
  199. fidStr := params.Get("fid")
  200. tidStr := params.Get("tid")
  201. keywordStr := params.Get("keyword")
  202. orderStr := params.Get("order")
  203. pnStr := params.Get("pn")
  204. psStr := params.Get("ps")
  205. var (
  206. err error
  207. mid int64
  208. vmid int64
  209. uid int64
  210. )
  211. if midI, ok := c.Get("mid"); ok {
  212. mid = midI.(int64)
  213. }
  214. if vmidStr != "" {
  215. if uid, err = strconv.ParseInt(vmidStr, 10, 64); err != nil || uid <= 0 {
  216. log.Error("vmid(%s) need a number > 0 error(%v)", vmidStr, err)
  217. c.JSON(nil, ecode.RequestErr)
  218. return
  219. }
  220. vmid = uid
  221. } else if mid != 0 {
  222. uid = mid
  223. } else {
  224. log.Warn("mid(%d) && vmidStr(%s)) is empty", mid, vmidStr)
  225. c.JSON(nil, ecode.RequestErr)
  226. return
  227. }
  228. fid, _ := strconv.ParseInt(fidStr, 10, 64)
  229. tid, err := strconv.Atoi(tidStr)
  230. if err != nil {
  231. tid = 0
  232. }
  233. pn, err := strconv.Atoi(pnStr)
  234. if err != nil || pn < 1 {
  235. pn = 1
  236. }
  237. ps, err := strconv.Atoi(psStr)
  238. if err != nil || ps > conf.Conf.Fav.MaxPagesize || ps <= 0 {
  239. ps = conf.Conf.Fav.MaxPagesize
  240. }
  241. // fav video
  242. data, err := favSvc.FavVideo(c, mid, vmid, uid, fid, keywordStr, orderStr, tid, pn, ps)
  243. if err != nil {
  244. c.JSON(nil, err)
  245. return
  246. }
  247. c.JSON(data, nil)
  248. }
  249. // tidList return all tids in the fid folder.
  250. func tidList(c *bm.Context) {
  251. // params
  252. params := c.Request.Form
  253. vmidStr := params.Get("vmid")
  254. fidStr := params.Get("fid")
  255. var (
  256. err error
  257. mid int64
  258. vmid int64
  259. uid int64
  260. )
  261. if midI, ok := c.Get("mid"); ok {
  262. mid = midI.(int64)
  263. }
  264. if vmidStr != "" {
  265. if uid, err = strconv.ParseInt(vmidStr, 10, 64); err != nil || uid <= 0 {
  266. log.Error("vmid(%s) need a number > 0 error(%v)", vmidStr, err)
  267. c.JSON(nil, ecode.RequestErr)
  268. return
  269. }
  270. vmid = uid
  271. } else if mid != 0 {
  272. uid = mid
  273. } else {
  274. log.Warn("mid(%d) && vmidStr(%s)) is empty", mid, vmidStr)
  275. c.JSON(nil, ecode.RequestErr)
  276. return
  277. }
  278. fid, _ := strconv.ParseInt(fidStr, 10, 64)
  279. // fav video
  280. data, err := favSvc.TidList(c, mid, vmid, uid, fid)
  281. if err != nil {
  282. c.JSON(nil, err)
  283. return
  284. }
  285. c.JSON(data, nil)
  286. }
  287. // favVideoNewest return the newest videos in the all folder.
  288. func favVideoNewest(c *bm.Context) {
  289. midIf, _ := c.Get("mid")
  290. mid := midIf.(int64)
  291. params := c.Request.URL.Query()
  292. pnStr := params.Get("pn")
  293. psStr := params.Get("ps")
  294. pn, err := strconv.Atoi(pnStr)
  295. if err != nil || pn < 1 {
  296. pn = 1
  297. }
  298. ps, err := strconv.Atoi(psStr)
  299. if err != nil || ps > conf.Conf.Fav.MaxPagesize || ps <= 0 {
  300. ps = conf.Conf.Fav.MaxPagesize
  301. }
  302. data, err := favSvc.RecentArcs(c, mid, pn, ps)
  303. if err != nil {
  304. c.JSON(nil, err)
  305. return
  306. }
  307. c.JSON(data, nil)
  308. }
  309. // addFavVideo add a video into folder.
  310. func addFavVideo(c *bm.Context) {
  311. midIf, _ := c.Get("mid")
  312. mid := midIf.(int64)
  313. params := c.Request.Form
  314. fidsStr := params.Get("fid")
  315. aidStr := params.Get("aid")
  316. if aidStr == "" {
  317. log.Warn("params aid(%s) is empty", aidStr)
  318. c.JSON(nil, ecode.RequestErr)
  319. return
  320. }
  321. fids, err := xstr.SplitInts(fidsStr)
  322. if err != nil {
  323. log.Warn("xstr.PlitInts(fids:%s) err(%v)", fidsStr, err)
  324. }
  325. aid, err := strconv.ParseInt(aidStr, 10, 64)
  326. if err != nil {
  327. log.Error("strconv.ParseInt(%s) error(%v)", aidStr, err)
  328. c.JSON(nil, ecode.RequestErr)
  329. return
  330. }
  331. if len(fids) == 0 {
  332. if err = favSvc.AddArc(c, mid, 0, aid, c.Request.Header.Get("Cookie"), params.Get("access_key")); err != nil {
  333. c.JSON(nil, err)
  334. return
  335. }
  336. }
  337. for _, fid := range fids {
  338. if err = favSvc.AddArc(c, mid, fid, aid, c.Request.Header.Get("Cookie"), params.Get("access_key")); err != nil {
  339. c.JSON(nil, err)
  340. return
  341. }
  342. }
  343. if collector != nil {
  344. collector.InfoAntiCheat2(c, "", aidStr, strconv.FormatInt(mid, 10), fidsStr, infoc.ItemTypeAv, infoc.ActionFav, "")
  345. }
  346. c.JSON(nil, err)
  347. }
  348. // delFavVideo delete a video from folder.
  349. func delFavVideo(c *bm.Context) {
  350. midIf, _ := c.Get("mid")
  351. mid := midIf.(int64)
  352. params := c.Request.Form
  353. fidsStr := params.Get("fid")
  354. aidStr := params.Get("aid")
  355. if aidStr == "" {
  356. log.Warn("method aid(%s) is empty", aidStr)
  357. c.JSON(nil, ecode.RequestErr)
  358. return
  359. }
  360. fids, err := xstr.SplitInts(fidsStr)
  361. if err != nil {
  362. log.Warn("xstr.SplitInts(fidsStr:%v) err(%v)", fidsStr, err)
  363. }
  364. aid, err := strconv.ParseInt(aidStr, 10, 64)
  365. if err != nil {
  366. log.Error("strconv.ParseInt(%s) error(%v)", aidStr, err)
  367. c.JSON(nil, ecode.RequestErr)
  368. return
  369. }
  370. if len(fids) == 0 {
  371. err = favSvc.DelArc(c, mid, 0, aid)
  372. c.JSON(nil, err)
  373. return
  374. }
  375. for _, fid := range fids {
  376. err = favSvc.DelArc(c, mid, fid, aid)
  377. }
  378. c.JSON(nil, err)
  379. }
  380. // moveFavVideos move some video into other folder.
  381. func moveFavVideos(c *bm.Context) {
  382. mid, _ := c.Get("mid")
  383. params := c.Request.Form
  384. ofidStr := params.Get("old_fid")
  385. nfidStr := params.Get("new_fid")
  386. aidsStr := params.Get("aids")
  387. if aidsStr == "" || ofidStr == "" || nfidStr == "" {
  388. log.Warn("method aids(%s) old_fid(%s) new_fid(%s) is empty", aidsStr, ofidStr, nfidStr)
  389. c.JSON(nil, ecode.RequestErr)
  390. return
  391. }
  392. if ofidStr == nfidStr {
  393. log.Warn("move videos to the same folder...")
  394. c.JSON(nil, ecode.FavFolderSame)
  395. return
  396. }
  397. ofid, err := strconv.ParseInt(ofidStr, 10, 64)
  398. if err != nil {
  399. log.Error("strconv.ParseInt(%s) error(%v)", ofidStr, err)
  400. c.JSON(nil, ecode.RequestErr)
  401. return
  402. }
  403. nfid, err := strconv.ParseInt(nfidStr, 10, 64)
  404. if err != nil {
  405. log.Error("strconv.ParseInt(%s) error(%v)", nfidStr, err)
  406. c.JSON(nil, ecode.RequestErr)
  407. return
  408. }
  409. aidArr := strings.Split(aidsStr, ",")
  410. if len(aidArr) == 0 {
  411. c.JSON(nil, ecode.RequestErr)
  412. return
  413. }
  414. if len(aidArr) > conf.Conf.Fav.MaxOperationNum {
  415. c.JSON(nil, ecode.FavMaxOperNum)
  416. return
  417. }
  418. aids := make([]int64, len(aidArr))
  419. var aid int64
  420. for i, aidStr := range aidArr {
  421. aid, err = strconv.ParseInt(aidStr, 10, 64)
  422. if err != nil {
  423. log.Error("strconv.ParseInt(%s) error(%v)", aidStr, err)
  424. c.JSON(nil, ecode.RequestErr)
  425. return
  426. }
  427. aids[i] = aid
  428. }
  429. err = favSvc.MoveArcs(c, mid.(int64), ofid, nfid, aids)
  430. c.JSON(nil, err)
  431. }
  432. // copyFavVideos move some video into other folder.
  433. func copyFavVideos(c *bm.Context) {
  434. midIf, _ := c.Get("mid")
  435. mid := midIf.(int64)
  436. params := c.Request.Form
  437. omidStr := params.Get("old_mid")
  438. ofidStr := params.Get("old_fid")
  439. nfidStr := params.Get("new_fid")
  440. aidsStr := params.Get("aids")
  441. if aidsStr == "" || ofidStr == "" || nfidStr == "" {
  442. log.Warn("method aids(%s) old_fid(%s) new_mid(%s) is empty", aidsStr, ofidStr, nfidStr)
  443. c.JSON(nil, ecode.RequestErr)
  444. return
  445. }
  446. if ofidStr == nfidStr {
  447. log.Warn("copy videos to the same folder...")
  448. c.JSON(nil, ecode.FavFolderSame)
  449. return
  450. }
  451. omid, err := strconv.ParseInt(omidStr, 10, 64)
  452. if err != nil {
  453. log.Warn("strconv.ParseInt(%s) error(%v)", omidStr, err)
  454. omid = mid
  455. }
  456. ofid, err := strconv.ParseInt(ofidStr, 10, 64)
  457. if err != nil {
  458. log.Error("strconv.ParseInt(%s) error(%v)", ofidStr, err)
  459. c.JSON(nil, ecode.RequestErr)
  460. return
  461. }
  462. nfid, err := strconv.ParseInt(nfidStr, 10, 64)
  463. if err != nil {
  464. log.Error("strconv.ParseInt(%s) error(%v)", nfidStr, err)
  465. c.JSON(nil, ecode.RequestErr)
  466. return
  467. }
  468. aidArr := strings.Split(aidsStr, ",")
  469. if len(aidArr) == 0 {
  470. c.JSON(nil, ecode.RequestErr)
  471. return
  472. }
  473. if len(aidArr) > conf.Conf.Fav.MaxOperationNum {
  474. c.JSON(nil, ecode.FavMaxOperNum)
  475. return
  476. }
  477. aids := make([]int64, len(aidArr))
  478. var aid int64
  479. for i, aidStr := range aidArr {
  480. aid, err = strconv.ParseInt(aidStr, 10, 64)
  481. if err != nil {
  482. log.Error("strconv.ParseInt(%s) error(%v)", aidStr, err)
  483. c.JSON(nil, ecode.RequestErr)
  484. return
  485. }
  486. aids[i] = aid
  487. }
  488. err = favSvc.CopyArcs(c, mid, omid, ofid, nfid, aids)
  489. c.JSON(nil, err)
  490. }
  491. // delVideos delete some video from folder.
  492. func delFavVideos(c *bm.Context) {
  493. mid, _ := c.Get("mid")
  494. params := c.Request.Form
  495. fidStr := params.Get("fid")
  496. aidsStr := params.Get("aids")
  497. if aidsStr == "" {
  498. log.Warn("method aid(%s) is empty", aidsStr)
  499. c.JSON(nil, ecode.RequestErr)
  500. return
  501. }
  502. fid, err := strconv.ParseInt(fidStr, 10, 64)
  503. if err != nil {
  504. log.Warn("strconv.ParseInt(%s) error(%v)", fidStr, err)
  505. }
  506. aidArr := strings.Split(aidsStr, ",")
  507. if len(aidArr) == 0 {
  508. c.JSON(nil, ecode.RequestErr)
  509. return
  510. }
  511. if len(aidArr) > conf.Conf.Fav.MaxOperationNum {
  512. c.JSON(nil, ecode.FavMaxOperNum)
  513. return
  514. }
  515. aids := make([]int64, len(aidArr))
  516. var aid int64
  517. for i, aidStr := range aidArr {
  518. aid, err = strconv.ParseInt(aidStr, 10, 64)
  519. if err != nil {
  520. log.Error("strconv.ParseInt(%s) error(%v)", aidStr, err)
  521. c.JSON(nil, ecode.RequestErr)
  522. return
  523. }
  524. aids[i] = aid
  525. }
  526. err = favSvc.DelArcs(c, mid.(int64), fid, aids)
  527. c.JSON(nil, err)
  528. }
  529. // isFavoured detemine video whether or not favoured by mid.
  530. func isFavoured(c *bm.Context) {
  531. mid, _ := c.Get("mid")
  532. params := c.Request.URL.Query()
  533. aidStr := params.Get("aid")
  534. aid, err := strconv.ParseInt(aidStr, 10, 64)
  535. if err != nil {
  536. log.Error("strconv.ParseInt(%s) error(%v)", aidStr, err)
  537. c.JSON(nil, ecode.RequestErr)
  538. return
  539. }
  540. faved, count, err := favSvc.IsFaved(c, mid.(int64), aid)
  541. if err != nil {
  542. log.Error("favSvr.IsFaved() err(%v)", err)
  543. return
  544. }
  545. data := map[string]interface{}{"favoured": faved, "count": count}
  546. c.JSON(data, nil)
  547. }
  548. // isFavoureds detemine video whether or not favoured by mid.
  549. func isFavoureds(c *bm.Context) {
  550. var (
  551. aids []int64
  552. err error
  553. )
  554. mid, _ := c.Get("mid")
  555. params := c.Request.URL.Query()
  556. aidStr := params.Get("aids")
  557. if aidStr == "" {
  558. log.Warn("method aid(%s) is empty", aidStr)
  559. c.JSON(nil, ecode.RequestErr)
  560. return
  561. }
  562. aids, err = xstr.SplitInts(aidStr)
  563. if err != nil {
  564. log.Error("strconv.ParseInt(%s) error(%v)", aidStr, err)
  565. c.JSON(nil, ecode.RequestErr)
  566. return
  567. }
  568. faved, _ := favSvc.IsFaveds(c, mid.(int64), aids)
  569. c.JSON(faved, nil)
  570. }
  571. // inDefaultFav detemine video whether or not favoured in default folder.
  572. func inDefaultFav(c *bm.Context) {
  573. mid, _ := c.Get("mid")
  574. params := c.Request.URL.Query()
  575. aidStr := params.Get("aid")
  576. if aidStr == "" {
  577. log.Warn("method aid(%s) is empty", aidStr)
  578. c.JSON(nil, ecode.RequestErr)
  579. return
  580. }
  581. aid, err := strconv.ParseInt(aidStr, 10, 64)
  582. if err != nil {
  583. log.Error("strconv.ParseInt(%s) error(%v)", aidStr, err)
  584. c.JSON(nil, ecode.RequestErr)
  585. return
  586. }
  587. var isIn bool
  588. isIn, err = favSvc.InDef(c, mid.(int64), aid)
  589. data := map[string]bool{"default": isIn}
  590. c.JSON(data, err)
  591. }
  592. // isCleaned check the clean action's cool down time and access
  593. func isCleaned(c *bm.Context) {
  594. mid, _ := c.Get("mid")
  595. params := c.Request.URL.Query()
  596. fidStr := params.Get("fid")
  597. fid, err := strconv.ParseInt(fidStr, 10, 64)
  598. if err != nil {
  599. log.Error("strconv.ParseInt(%s) error(%v)", fidStr, err)
  600. c.JSON(nil, ecode.RequestErr)
  601. return
  602. }
  603. cleanState, err := favSvc.CleanState(c, mid.(int64), fid)
  604. if err != nil {
  605. log.Error("favSvc.IsCleaned(%d,%d) error(%v)", mid, fid, err)
  606. c.JSON(nil, err)
  607. return
  608. }
  609. data := map[string]interface{}{"state": cleanState}
  610. c.JSON(data, nil)
  611. }
  612. func cleanInvalidArcs(c *bm.Context) {
  613. mid, _ := c.Get("mid")
  614. params := c.Request.Form
  615. fidStr := params.Get("fid")
  616. fid, err := strconv.ParseInt(fidStr, 10, 64)
  617. if err != nil {
  618. log.Error("strconv.ParseInt(%s) error(%v)", fidStr, err)
  619. c.JSON(nil, ecode.RequestErr)
  620. return
  621. }
  622. if err = favSvc.CleanInvalidArcs(c, mid.(int64), fid); err != nil {
  623. log.Error("favSvc.CleanInvalidArcs(%d,%d) error(%v)", mid, fid, err)
  624. }
  625. c.JSON(nil, err)
  626. }