fav.go 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257
  1. package http
  2. import (
  3. "strconv"
  4. "strings"
  5. "go-common/app/service/main/favorite/conf"
  6. "go-common/app/service/main/favorite/model"
  7. "go-common/library/ecode"
  8. "go-common/library/log"
  9. bm "go-common/library/net/http/blademaster"
  10. "go-common/library/xstr"
  11. )
  12. // userFolders return user's all folders
  13. func userFolders(c *bm.Context) {
  14. params := c.Request.Form
  15. typeStr := params.Get("type")
  16. midStr := params.Get("mid")
  17. vmidStr := params.Get("vmid")
  18. oidStr := params.Get("oid")
  19. var (
  20. err error
  21. mid int64
  22. vmid int64
  23. )
  24. if midStr != "" {
  25. mid, err = strconv.ParseInt(midStr, 10, 64)
  26. if err != nil {
  27. c.JSON(nil, err)
  28. return
  29. }
  30. }
  31. if vmidStr != "" {
  32. vmid, err = strconv.ParseInt(vmidStr, 10, 64)
  33. if err != nil {
  34. c.JSON(nil, err)
  35. return
  36. }
  37. if vmid <= 0 {
  38. c.JSON(nil, ecode.RequestErr)
  39. return
  40. }
  41. } else if mid == 0 {
  42. c.JSON(nil, ecode.RequestErr)
  43. return
  44. }
  45. if typeStr == "" {
  46. log.Warn("params typeStr(%s) is empty", typeStr)
  47. c.JSON(nil, ecode.RequestErr)
  48. return
  49. }
  50. typ, err := strconv.ParseInt(typeStr, 10, 8)
  51. if err != nil {
  52. log.Error("strconv.ParseInt(%s) error(%v)", typeStr, err)
  53. c.JSON(nil, ecode.RequestErr)
  54. return
  55. }
  56. var oid int64
  57. if oidStr != "" {
  58. oid, err = strconv.ParseInt(oidStr, 10, 64)
  59. if err != nil {
  60. c.JSON(nil, ecode.RequestErr)
  61. return
  62. }
  63. }
  64. data, err := favSvc.UserFolders(c, int8(typ), mid, vmid, oid, int8(typ))
  65. if err != nil {
  66. c.JSON(nil, err)
  67. return
  68. }
  69. c.JSON(data, nil)
  70. }
  71. // folders return multi folders.
  72. func folders(c *bm.Context) {
  73. params := c.Request.Form
  74. typeStr := params.Get("type")
  75. midStr := params.Get("mid")
  76. fvmidsStr := params.Get("fvmids")
  77. var (
  78. err error
  79. mid int64
  80. fid int64
  81. vmid int64
  82. fvmids []*model.ArgFVmid
  83. )
  84. if midStr != "" {
  85. if mid, err = strconv.ParseInt(midStr, 10, 64); err != nil {
  86. log.Error("strconv.ParseInt(%s) error(%v)", midStr, err)
  87. c.JSON(nil, ecode.RequestErr)
  88. return
  89. }
  90. }
  91. if typeStr == "" || fvmidsStr == "" {
  92. log.Warn("params typeStr(%s) or fvmidsStr(%s) is empty", typeStr, fvmidsStr)
  93. c.JSON(nil, ecode.RequestErr)
  94. return
  95. }
  96. tp, err := strconv.ParseInt(typeStr, 10, 8)
  97. if err != nil {
  98. log.Error("strconv.ParseInt(%s) error(%v)", typeStr, err)
  99. c.JSON(nil, ecode.RequestErr)
  100. return
  101. }
  102. fvmidsArr := strings.Split(fvmidsStr, ",")
  103. for _, fvmidStr := range fvmidsArr {
  104. fvmidArr := strings.Split(fvmidStr, "-")
  105. if len(fvmidArr) != 2 {
  106. c.JSON(nil, ecode.RequestErr)
  107. return
  108. }
  109. fid, err = strconv.ParseInt(fvmidArr[0], 10, 64)
  110. if err != nil {
  111. c.JSON(nil, ecode.RequestErr)
  112. return
  113. }
  114. vmid, err = strconv.ParseInt(fvmidArr[1], 10, 64)
  115. if err != nil {
  116. c.JSON(nil, ecode.RequestErr)
  117. return
  118. }
  119. fvmid := &model.ArgFVmid{
  120. Fid: fid,
  121. Vmid: vmid,
  122. }
  123. fvmids = append(fvmids, fvmid)
  124. }
  125. data, err := favSvc.Folders(c, int8(tp), mid, fvmids)
  126. if err != nil {
  127. c.JSON(nil, err)
  128. return
  129. }
  130. c.JSON(data, nil)
  131. }
  132. // folderInfo return folders & pages.
  133. func folderInfo(c *bm.Context) {
  134. // params
  135. params := c.Request.Form
  136. typeStr := params.Get("type")
  137. midStr := params.Get("mid")
  138. vmidStr := params.Get("vmid")
  139. fidStr := params.Get("fid")
  140. var (
  141. err error
  142. mid, uid, fid int64
  143. )
  144. if midStr != "" {
  145. if mid, err = strconv.ParseInt(midStr, 10, 64); err != nil || mid <= 0 {
  146. log.Error("mid(%s) need a number > 0 error(%v)", midStr, err)
  147. c.JSON(nil, ecode.RequestErr)
  148. return
  149. }
  150. }
  151. if vmidStr != "" {
  152. if uid, err = strconv.ParseInt(vmidStr, 10, 64); err != nil || uid <= 0 {
  153. log.Error("vmid(%s) need a number > 0 error(%v)", vmidStr, err)
  154. c.JSON(nil, ecode.RequestErr)
  155. return
  156. }
  157. }
  158. if mid <= 0 && uid <= 0 {
  159. log.Warn("method (mid=0 && vmid(%s)) is empty", vmidStr)
  160. c.JSON(nil, ecode.RequestErr)
  161. return
  162. }
  163. if typeStr == "" || fidStr == "" {
  164. log.Warn("params typeStr(%s) or fidStr(%s) is empty", typeStr, fidStr)
  165. c.JSON(nil, ecode.RequestErr)
  166. return
  167. }
  168. tp, err := strconv.ParseInt(typeStr, 10, 8)
  169. if err != nil {
  170. log.Error("strconv.ParseInt(%s) error(%v)", typeStr, err)
  171. c.JSON(nil, ecode.RequestErr)
  172. return
  173. }
  174. fid, err = strconv.ParseInt(fidStr, 10, 64)
  175. if err != nil || fid == 0 {
  176. log.Error("strconv.ParseInt(%s) error(%v)", typeStr, err)
  177. c.JSON(nil, ecode.RequestErr)
  178. return
  179. }
  180. data, err := favSvc.Folder(c, int8(tp), mid, uid, fid)
  181. if err != nil {
  182. c.JSON(nil, err)
  183. return
  184. }
  185. c.JSON(data, nil)
  186. }
  187. // folders add a new folder.
  188. func addFolder(c *bm.Context) {
  189. mid, _ := c.Get("mid")
  190. params := c.Request.Form
  191. typeStr := params.Get("type")
  192. name := params.Get("name")
  193. description := params.Get("description")
  194. cover := params.Get("cover")
  195. publicStr := params.Get("public")
  196. if typeStr == "" || name == "" {
  197. log.Error("params typeStr(%s) or name(%s) is empty", typeStr, name)
  198. c.JSON(nil, ecode.RequestErr)
  199. return
  200. }
  201. tp, err := strconv.ParseInt(typeStr, 10, 8)
  202. if err != nil {
  203. log.Error("strconv.ParseInt(%s) error(%v)", typeStr, err)
  204. c.JSON(nil, ecode.RequestErr)
  205. return
  206. }
  207. var public int64
  208. if publicStr != "" {
  209. public, err = strconv.ParseInt(publicStr, 10, 8)
  210. if err != nil {
  211. log.Error("strconv.ParseInt(%s) error(%v)", publicStr, err)
  212. c.JSON(nil, ecode.RequestErr)
  213. return
  214. }
  215. if public > 1 {
  216. public = 0
  217. }
  218. }
  219. fid, err := favSvc.AddFolder(c, int8(tp), mid.(int64), name, description, cover, int32(public), c.Request.Header.Get("Cookie"), params.Get("access_key"))
  220. if err != nil {
  221. c.JSON(nil, err)
  222. return
  223. }
  224. data := map[string]int64{
  225. "fid": fid,
  226. }
  227. c.JSON(data, nil)
  228. }
  229. // updateFolder update folder info.
  230. func updateFolder(c *bm.Context) {
  231. mid, _ := c.Get("mid")
  232. params := c.Request.Form
  233. typeStr := params.Get("type")
  234. name := params.Get("name")
  235. description := params.Get("description")
  236. cover := params.Get("cover")
  237. publicStr := params.Get("public")
  238. fidStr := params.Get("fid")
  239. if typeStr == "" || fidStr == "" || name == "" {
  240. log.Error("params typeStr(%s) or fidStr(%s) or name(%s) is empty", typeStr, fidStr, name)
  241. c.JSON(nil, ecode.RequestErr)
  242. return
  243. }
  244. tp, err := strconv.ParseInt(typeStr, 10, 8)
  245. if err != nil {
  246. log.Error("strconv.ParseInt(%s) error(%v)", typeStr, err)
  247. c.JSON(nil, ecode.RequestErr)
  248. return
  249. }
  250. fid, err := strconv.ParseInt(fidStr, 10, 64)
  251. if err != nil {
  252. log.Error("strconv.ParseInt(%s) error(%v)", fidStr, err)
  253. c.JSON(nil, ecode.RequestErr)
  254. return
  255. }
  256. var public int64
  257. if publicStr != "" {
  258. public, err = strconv.ParseInt(publicStr, 10, 8)
  259. if err != nil {
  260. log.Error("strconv.ParseInt(%s) error(%v)", publicStr, err)
  261. c.JSON(nil, ecode.RequestErr)
  262. return
  263. }
  264. }
  265. err = favSvc.UpdateFolder(c, int8(tp), fid, mid.(int64), name, description, cover, int32(public), nil, nil)
  266. c.JSON(nil, err)
  267. }
  268. // delFolder del one folder.
  269. func delFolder(c *bm.Context) {
  270. mid, _ := c.Get("mid")
  271. params := c.Request.Form
  272. typeStr := params.Get("type")
  273. tp, err := strconv.ParseInt(typeStr, 10, 8)
  274. if err != nil {
  275. log.Error("strconv.ParseInt(%s) error(%v)", typeStr, err)
  276. c.JSON(nil, ecode.RequestErr)
  277. return
  278. }
  279. fidStr := params.Get("fid")
  280. if fidStr == "" {
  281. log.Warn("method fid(%s) is empty", fidStr)
  282. c.JSON(nil, ecode.RequestErr)
  283. return
  284. }
  285. fid, err := strconv.ParseInt(fidStr, 10, 64)
  286. if err != nil {
  287. log.Error("strconv.ParseInt(%s) error(%v)", fidStr, err)
  288. c.JSON(nil, ecode.RequestErr)
  289. return
  290. }
  291. err = favSvc.DelFolder(c, int8(tp), mid.(int64), fid)
  292. c.JSON(nil, err)
  293. }
  294. // cntUserFolders del one folder.
  295. func cntUserFolders(c *bm.Context) {
  296. params := c.Request.Form
  297. typeStr := params.Get("type")
  298. midStr := params.Get("mid")
  299. vmidStr := params.Get("vmid")
  300. tp, err := strconv.ParseInt(typeStr, 10, 8)
  301. if err != nil {
  302. log.Error("strconv.ParseInt(%s) error(%v)", typeStr, err)
  303. c.JSON(nil, ecode.RequestErr)
  304. return
  305. }
  306. var mid int64
  307. if midStr != "" {
  308. if mid, err = strconv.ParseInt(midStr, 10, 64); err != nil || mid <= 0 {
  309. log.Error("mid(%s) need a number > 0 error(%v)", midStr, err)
  310. c.JSON(nil, ecode.RequestErr)
  311. return
  312. }
  313. }
  314. var uid int64
  315. if vmidStr != "" {
  316. if uid, err = strconv.ParseInt(vmidStr, 10, 64); err != nil || uid <= 0 {
  317. log.Error("vmid(%s) need a number > 0 error(%v)", vmidStr, err)
  318. c.JSON(nil, ecode.RequestErr)
  319. return
  320. }
  321. }
  322. if mid <= 0 && uid <= 0 {
  323. log.Warn("method (mid=0 && vmid(%s)) is empty", vmidStr)
  324. c.JSON(nil, ecode.RequestErr)
  325. return
  326. }
  327. count, err := favSvc.CntUserFolders(c, int8(tp), mid, uid)
  328. if err != nil {
  329. log.Error("favSvr.IsFaved() err(%v)", err)
  330. return
  331. }
  332. data := map[string]interface{}{"count": count}
  333. c.JSON(data, nil)
  334. }
  335. // Favorites return all objects in the fid folder.
  336. func Favorites(c *bm.Context) {
  337. // params
  338. params := c.Request.Form
  339. typeStr := params.Get("type")
  340. midStr := params.Get("mid")
  341. vmidStr := params.Get("vmid")
  342. fidStr := params.Get("fid")
  343. tidStr := params.Get("tid")
  344. keyword := params.Get("keyword")
  345. order := params.Get("order")
  346. tvStr := params.Get("tv")
  347. pnStr := params.Get("pn")
  348. psStr := params.Get("ps")
  349. var (
  350. err error
  351. mid int64
  352. uid int64
  353. fid int64
  354. tid int
  355. tv int
  356. )
  357. if midStr != "" {
  358. mid, err = strconv.ParseInt(midStr, 10, 64)
  359. if err != nil {
  360. c.JSON(nil, err)
  361. return
  362. }
  363. }
  364. if vmidStr != "" {
  365. uid, err = strconv.ParseInt(vmidStr, 10, 64)
  366. if err != nil {
  367. c.JSON(nil, err)
  368. return
  369. }
  370. if uid <= 0 {
  371. c.JSON(nil, ecode.RequestErr)
  372. return
  373. }
  374. } else if mid <= 0 {
  375. log.Warn("mid(%d) && vmidStr(%s) is empty", mid, vmidStr)
  376. c.JSON(nil, ecode.RequestErr)
  377. return
  378. }
  379. if typeStr == "" {
  380. log.Warn("params typeStr(%s) is empty", typeStr)
  381. c.JSON(nil, ecode.RequestErr)
  382. return
  383. }
  384. tp, err := strconv.ParseInt(typeStr, 10, 8)
  385. if err != nil {
  386. log.Error("strconv.ParseInt(%s) error(%v)", typeStr, err)
  387. c.JSON(nil, ecode.RequestErr)
  388. return
  389. }
  390. if fidStr != "" {
  391. if fid, err = strconv.ParseInt(fidStr, 10, 64); err != nil {
  392. log.Error("strconv.ParseInt(%s) error(%v)", fidStr, err)
  393. c.JSON(nil, ecode.RequestErr)
  394. return
  395. }
  396. }
  397. if tvStr != "" {
  398. if tv, err = strconv.Atoi(tvStr); err != nil {
  399. log.Error("strconv.Atoi(%s) error(%v)", tvStr, err)
  400. c.JSON(nil, ecode.RequestErr)
  401. return
  402. }
  403. }
  404. if tidStr != "" {
  405. if tid, err = strconv.Atoi(tidStr); err != nil {
  406. log.Error("strconv.Atoi(%s) error(%v)", tidStr, err)
  407. c.JSON(nil, ecode.RequestErr)
  408. return
  409. }
  410. }
  411. pn, err := strconv.Atoi(pnStr)
  412. if err != nil || pn < 1 {
  413. pn = 1
  414. }
  415. ps, err := strconv.Atoi(psStr)
  416. if err != nil || ps > conf.Conf.Fav.MaxPagesize || ps <= 0 {
  417. ps = conf.Conf.Fav.MaxPagesize
  418. }
  419. // fav objects
  420. data, err := favSvc.Favorites(c, int8(tp), mid, uid, fid, tid, tv, pn, ps, keyword, order)
  421. if err != nil {
  422. c.JSON(nil, err)
  423. return
  424. }
  425. c.JSON(data, nil)
  426. }
  427. // tlist return all video's type list.
  428. func tlists(c *bm.Context) {
  429. // params
  430. params := c.Request.Form
  431. typeStr := params.Get("type")
  432. midStr := params.Get("mid")
  433. vmidStr := params.Get("vmid")
  434. fidStr := params.Get("fid")
  435. var (
  436. err error
  437. mid int64
  438. uid int64
  439. fid int64
  440. )
  441. if midStr != "" {
  442. mid, err = strconv.ParseInt(midStr, 10, 64)
  443. if err != nil {
  444. c.JSON(nil, err)
  445. return
  446. }
  447. }
  448. if vmidStr != "" {
  449. uid, err = strconv.ParseInt(vmidStr, 10, 64)
  450. if err != nil {
  451. c.JSON(nil, err)
  452. return
  453. }
  454. if uid <= 0 {
  455. c.JSON(nil, ecode.RequestErr)
  456. return
  457. }
  458. } else if mid <= 0 {
  459. log.Warn("mid(%d) && vmidStr(%s) is empty", mid, vmidStr)
  460. c.JSON(nil, ecode.RequestErr)
  461. return
  462. }
  463. if typeStr == "" {
  464. log.Warn("params typeStr(%s) is empty", typeStr)
  465. c.JSON(nil, ecode.RequestErr)
  466. return
  467. }
  468. typ, err := strconv.Atoi(typeStr)
  469. if err != nil {
  470. log.Error("strconv.Aoti(%s) error(%v)", typeStr, err)
  471. c.JSON(nil, ecode.RequestErr)
  472. return
  473. }
  474. if fidStr != "" {
  475. if fid, err = strconv.ParseInt(fidStr, 10, 64); err != nil {
  476. log.Error("strconv.ParseInt(%s) error(%v)", fidStr, err)
  477. c.JSON(nil, ecode.RequestErr)
  478. return
  479. }
  480. }
  481. data, err := favSvc.Tlists(c, int8(typ), mid, uid, fid)
  482. if err != nil {
  483. c.JSON(nil, err)
  484. return
  485. }
  486. c.JSON(data, nil)
  487. }
  488. // recentFavs return user's recent favs.
  489. func recentFavs(c *bm.Context) {
  490. // params
  491. params := c.Request.Form
  492. typeStr := params.Get("type")
  493. midStr := params.Get("mid")
  494. sizeStr := params.Get("size")
  495. if typeStr == "" || midStr == "" {
  496. log.Warn("params typeStr(%s) or midStr(%s) is empty", typeStr, midStr)
  497. c.JSON(nil, ecode.RequestErr)
  498. return
  499. }
  500. typ, err := strconv.ParseInt(typeStr, 10, 8)
  501. if err != nil {
  502. log.Error("strconv.ParseInt(%s) error(%v)", typeStr, err)
  503. c.JSON(nil, ecode.RequestErr)
  504. return
  505. }
  506. mid, err := strconv.ParseInt(midStr, 10, 64)
  507. if err != nil {
  508. log.Error("strconv.ParseInt(%s) error(%v)", midStr, err)
  509. c.JSON(nil, err)
  510. return
  511. }
  512. size, err := strconv.Atoi(sizeStr)
  513. if err != nil {
  514. log.Error("strconv.Atoi(%s) error(%v)", sizeStr, err)
  515. c.JSON(nil, err)
  516. return
  517. }
  518. data, err := favSvc.RecentFavs(c, int8(typ), mid, size)
  519. if err != nil {
  520. c.JSON(nil, err)
  521. return
  522. }
  523. c.JSON(data, nil)
  524. }
  525. // batchFavs return all objects in the fid folder.
  526. func batchFavs(c *bm.Context) {
  527. // params
  528. params := c.Request.Form
  529. typeStr := params.Get("type")
  530. midStr := params.Get("mid")
  531. if typeStr == "" || midStr == "" {
  532. log.Warn("params typeStr(%s) or midStr(%s) is empty", typeStr, midStr)
  533. c.JSON(nil, ecode.RequestErr)
  534. return
  535. }
  536. typ, err := strconv.ParseInt(typeStr, 10, 8)
  537. if err != nil {
  538. log.Error("strconv.ParseInt(%s) error(%v)", typeStr, err)
  539. c.JSON(nil, ecode.RequestErr)
  540. return
  541. }
  542. mid, err := strconv.ParseInt(midStr, 10, 64)
  543. if err != nil {
  544. log.Error("strconv.ParseInt(%s) error(%v)", midStr, err)
  545. c.JSON(nil, err)
  546. return
  547. }
  548. data, err := favSvc.BatchFavs(c, int8(typ), mid, conf.Conf.Fav.MaxBatchSize)
  549. if err != nil {
  550. c.JSON(nil, err)
  551. return
  552. }
  553. c.JSON(data, nil)
  554. }
  555. // addFav add a object into folder.
  556. func addFav(c *bm.Context) {
  557. mid, _ := c.Get("mid")
  558. params := c.Request.Form
  559. typeStr := params.Get("type")
  560. oidStr := params.Get("oid")
  561. fidsStr := params.Get("fid")
  562. if typeStr == "" {
  563. log.Warn("params typeStr(%s) is empty", typeStr)
  564. c.JSON(nil, ecode.RequestErr)
  565. return
  566. }
  567. if oidStr == "" {
  568. log.Warn("params oid(%s) is empty", oidStr)
  569. c.JSON(nil, ecode.RequestErr)
  570. return
  571. }
  572. tp, err := strconv.ParseInt(typeStr, 10, 8)
  573. if err != nil {
  574. log.Error("strconv.ParseInt(%s) error(%v)", typeStr, err)
  575. c.JSON(nil, ecode.RequestErr)
  576. return
  577. }
  578. oid, err := strconv.ParseInt(oidStr, 10, 64)
  579. if err != nil {
  580. log.Error("strconv.ParseInt(%s) error(%v)", oidStr, err)
  581. c.JSON(nil, ecode.RequestErr)
  582. return
  583. }
  584. var fids []int64
  585. if fidsStr != "" {
  586. fids, err = xstr.SplitInts(fidsStr)
  587. if err != nil {
  588. log.Warn("xstr.PlitInts(fids:%s) err(%v)", fidsStr, err)
  589. }
  590. }
  591. if len(fids) == 0 {
  592. fids = []int64{0}
  593. }
  594. for _, fid := range fids {
  595. err = favSvc.AddFav(c, int8(tp), mid.(int64), fid, oid, int8(tp))
  596. }
  597. c.JSON(nil, err)
  598. }
  599. // delFav delete a object from folder.
  600. func delFav(c *bm.Context) {
  601. mid, _ := c.Get("mid")
  602. params := c.Request.Form
  603. typeStr := params.Get("type")
  604. oidStr := params.Get("oid")
  605. fidsStr := params.Get("fid")
  606. if typeStr == "" {
  607. log.Warn("params typeStr(%s) is empty", typeStr)
  608. c.JSON(nil, ecode.RequestErr)
  609. return
  610. }
  611. if oidStr == "" {
  612. log.Warn("method oid(%s) is empty", oidStr)
  613. c.JSON(nil, ecode.RequestErr)
  614. return
  615. }
  616. tp, err := strconv.ParseInt(typeStr, 10, 8)
  617. if err != nil {
  618. log.Error("strconv.ParseInt(%s) error(%v)", typeStr, err)
  619. c.JSON(nil, ecode.RequestErr)
  620. return
  621. }
  622. oid, err := strconv.ParseInt(oidStr, 10, 64)
  623. if err != nil {
  624. log.Error("strconv.ParseInt(%s) error(%v)", oidStr, err)
  625. c.JSON(nil, ecode.RequestErr)
  626. return
  627. }
  628. fids, err := xstr.SplitInts(fidsStr)
  629. if err != nil {
  630. log.Warn("xstr.SplitInts(fidsStr:%v) err(%v)", fidsStr, err)
  631. }
  632. if len(fids) == 0 {
  633. fids = []int64{0}
  634. }
  635. for _, fid := range fids {
  636. err = favSvc.DelFav(c, int8(tp), mid.(int64), fid, oid, int8(tp))
  637. }
  638. c.JSON(nil, err)
  639. }
  640. // multiAddFav add multiple object from folder.
  641. func multiAddFavs(c *bm.Context) {
  642. mid, _ := c.Get("mid")
  643. params := c.Request.Form
  644. typeStr := params.Get("type")
  645. fidStr := params.Get("fid")
  646. oidsStr := params.Get("oids")
  647. if typeStr == "" {
  648. log.Warn("params typeStr(%s) is empty", typeStr)
  649. c.JSON(nil, ecode.RequestErr)
  650. return
  651. }
  652. if oidsStr == "" {
  653. log.Warn("method oid(%s) is empty", oidsStr)
  654. c.JSON(nil, ecode.RequestErr)
  655. return
  656. }
  657. tp, err := strconv.ParseInt(typeStr, 10, 8)
  658. if err != nil {
  659. log.Error("strconv.ParseInt(%s) error(%v)", typeStr, err)
  660. c.JSON(nil, ecode.RequestErr)
  661. return
  662. }
  663. fid, err := strconv.ParseInt(fidStr, 10, 64)
  664. if err != nil {
  665. log.Error("strconv.ParseInt(%s) error(%v)", fidStr, err)
  666. c.JSON(nil, ecode.RequestErr)
  667. return
  668. }
  669. oidsArr := strings.Split(oidsStr, ",")
  670. if len(oidsArr) > conf.Conf.Fav.MaxOperationNum {
  671. c.JSON(nil, ecode.FavMaxOperNum)
  672. return
  673. }
  674. var oid int64
  675. oids := make([]int64, len(oidsArr))
  676. for i, oidStr := range oidsArr {
  677. oid, err = strconv.ParseInt(oidStr, 10, 64)
  678. if err != nil {
  679. log.Error("strconv.ParseInt(%s) error(%v)", oidStr, err)
  680. c.JSON(nil, ecode.RequestErr)
  681. return
  682. }
  683. oids[i] = oid
  684. }
  685. err = favSvc.MultiAddFavs(c, int8(tp), mid.(int64), fid, oids)
  686. c.JSON(nil, err)
  687. }
  688. // multiDelFav delete multiple object from folder.
  689. func multiDelFavs(c *bm.Context) {
  690. mid, _ := c.Get("mid")
  691. params := c.Request.Form
  692. typeStr := params.Get("type")
  693. fidStr := params.Get("fid")
  694. oidsStr := params.Get("oids")
  695. if typeStr == "" {
  696. log.Warn("params typeStr(%s) is empty", typeStr)
  697. c.JSON(nil, ecode.RequestErr)
  698. return
  699. }
  700. if oidsStr == "" {
  701. log.Warn("method oid(%s) is empty", oidsStr)
  702. c.JSON(nil, ecode.RequestErr)
  703. return
  704. }
  705. tp, err := strconv.ParseInt(typeStr, 10, 8)
  706. if err != nil {
  707. log.Error("strconv.ParseInt(%s) error(%v)", typeStr, err)
  708. c.JSON(nil, ecode.RequestErr)
  709. return
  710. }
  711. fid, err := strconv.ParseInt(fidStr, 10, 64)
  712. if err != nil {
  713. log.Error("strconv.ParseInt(%s) error(%v)", fidStr, err)
  714. c.JSON(nil, ecode.RequestErr)
  715. return
  716. }
  717. oidsArr := strings.Split(oidsStr, ",")
  718. if len(oidsArr) > conf.Conf.Fav.MaxOperationNum {
  719. c.JSON(nil, ecode.FavMaxOperNum)
  720. return
  721. }
  722. oids := make([]int64, len(oidsArr))
  723. var oid int64
  724. for i, oidStr := range oidsArr {
  725. oid, err = strconv.ParseInt(oidStr, 10, 64)
  726. if err != nil {
  727. log.Error("strconv.ParseInt(%s) error(%v)", oidStr, err)
  728. c.JSON(nil, ecode.RequestErr)
  729. return
  730. }
  731. oids[i] = oid
  732. }
  733. if err != nil {
  734. log.Warn("xstr.SplitInts(fidsStr:%v) err(%v)", oidsStr, err)
  735. }
  736. err = favSvc.MultiDelFavs(c, int8(tp), mid.(int64), fid, oids)
  737. c.JSON(nil, err)
  738. }
  739. // isFavored detemine object whether or not favored by mid.
  740. func isFavored(c *bm.Context) {
  741. mid, _ := c.Get("mid")
  742. params := c.Request.URL.Query()
  743. typeStr := params.Get("type")
  744. oidStr := params.Get("oid")
  745. if typeStr == "" {
  746. log.Warn("params typeStr(%s) is empty", typeStr)
  747. c.JSON(nil, ecode.RequestErr)
  748. return
  749. }
  750. if oidStr == "" {
  751. log.Warn("method oid(%s) is empty", oidStr)
  752. c.JSON(nil, ecode.RequestErr)
  753. return
  754. }
  755. tp, err := strconv.ParseInt(typeStr, 10, 8)
  756. if err != nil {
  757. log.Error("strconv.ParseInt(%s) error(%v)", typeStr, err)
  758. c.JSON(nil, ecode.RequestErr)
  759. return
  760. }
  761. oid, err := strconv.ParseInt(oidStr, 10, 64)
  762. if err != nil {
  763. log.Error("strconv.ParseInt(%s) error(%v)", oidStr, err)
  764. c.JSON(nil, ecode.RequestErr)
  765. return
  766. }
  767. favored, err := favSvc.IsFavored(c, int8(tp), mid.(int64), oid)
  768. if err != nil {
  769. log.Error("favSvr.IsFaved() err(%v)", err)
  770. return
  771. }
  772. data := map[string]interface{}{"favored": favored}
  773. c.JSON(data, nil)
  774. }
  775. // isFavoreds detemine objects whether or not favored by mid.
  776. func isFavoreds(c *bm.Context) {
  777. mid, _ := c.Get("mid")
  778. params := c.Request.URL.Query()
  779. typeStr := params.Get("type")
  780. oidsStr := params.Get("oids")
  781. if typeStr == "" {
  782. log.Warn("params typeStr(%s) is empty", typeStr)
  783. c.JSON(nil, ecode.RequestErr)
  784. return
  785. }
  786. if oidsStr == "" {
  787. log.Warn("method oid(%s) is empty", oidsStr)
  788. c.JSON(nil, ecode.RequestErr)
  789. return
  790. }
  791. typ, err := strconv.ParseInt(typeStr, 10, 8)
  792. if err != nil {
  793. log.Error("strconv.ParseInt(%s) error(%v)", typeStr, err)
  794. c.JSON(nil, ecode.RequestErr)
  795. return
  796. }
  797. oids, err := xstr.SplitInts(oidsStr)
  798. if err != nil {
  799. log.Error("xstr.SplitInts(%s) error(%v)", oidsStr, err)
  800. c.JSON(nil, ecode.RequestErr)
  801. return
  802. }
  803. favoreds, err := favSvc.IsFavoreds(c, int8(typ), mid.(int64), oids)
  804. if err != nil {
  805. log.Error("favSvr.IsFaved() err(%v)", err)
  806. return
  807. }
  808. c.JSON(favoreds, nil)
  809. }
  810. // sortFolders sort all user's folders
  811. func sortFolders(c *bm.Context) {
  812. var (
  813. fids []int64
  814. err error
  815. )
  816. params := c.Request.Form
  817. fidStr := params.Get("fids")
  818. typeStr := params.Get("type")
  819. mid, _ := c.Get("mid")
  820. if fidStr == "" || typeStr == "" {
  821. log.Error("arg fids or type is empty")
  822. c.JSON(nil, ecode.RequestErr)
  823. return
  824. }
  825. typ, err := strconv.ParseInt(typeStr, 10, 8)
  826. if err != nil {
  827. log.Error("strconv.ParseInt(%s) error(%v)", typeStr, err)
  828. c.JSON(nil, ecode.RequestErr)
  829. return
  830. }
  831. fids, err = xstr.SplitInts(fidStr)
  832. if err != nil {
  833. log.Error("xstr.SplitInts(%s) error(%v)", fidStr, err)
  834. c.JSON(nil, ecode.RequestErr)
  835. return
  836. }
  837. err = favSvc.SetFolderSort(c, int8(typ), mid.(int64), fids)
  838. c.JSON(nil, err)
  839. }
  840. // renameFolder rename folder.
  841. func renameFolder(c *bm.Context) {
  842. mid, _ := c.Get("mid")
  843. params := c.Request.Form
  844. fidStr := params.Get("fid")
  845. typeStr := params.Get("type")
  846. name := params.Get("name")
  847. if fidStr == "" || typeStr == "" || name == "" {
  848. log.Warn("arg fid or type is empty")
  849. c.JSON(nil, ecode.RequestErr)
  850. return
  851. }
  852. if len([]rune(name)) > conf.Conf.Fav.MaxNameLen {
  853. log.Warn("arg name(%s) is empty or it's length more than %d", name, conf.Conf.Fav.MaxNameLen)
  854. c.JSON(nil, ecode.FavNameTooLong)
  855. return
  856. }
  857. typ, err := strconv.ParseInt(typeStr, 10, 8)
  858. if err != nil {
  859. log.Error("strconv.ParseInt(%s) error(%v)", typeStr, err)
  860. c.JSON(nil, ecode.RequestErr)
  861. return
  862. }
  863. fid, err := strconv.ParseInt(fidStr, 10, 64)
  864. if err != nil {
  865. log.Error("strconv.ParseInt(%s) error(%v)", fidStr, err)
  866. c.JSON(nil, ecode.RequestErr)
  867. return
  868. }
  869. err = favSvc.UpFolderName(c, int8(typ), mid.(int64), fid, name, c.Request.Header.Get("Cookie"), params.Get("access_key"))
  870. c.JSON(nil, err)
  871. }
  872. // upAttrFolder update folder's attr.
  873. func upAttrFolder(c *bm.Context) {
  874. mid, _ := c.Get("mid")
  875. params := c.Request.Form
  876. typeStr := params.Get("type")
  877. fidStr := params.Get("fid")
  878. pubStr := params.Get("public")
  879. if fidStr == "" || pubStr == "" || typeStr == "" {
  880. log.Warn("args fid(%s) or public(%s) or type(%s) is empty", fidStr, pubStr, typeStr)
  881. c.JSON(nil, ecode.RequestErr)
  882. return
  883. }
  884. fid, err := strconv.ParseInt(fidStr, 10, 64)
  885. if err != nil {
  886. log.Error("strconv.ParseInt(%s) error(%v)", fidStr, err)
  887. c.JSON(nil, ecode.RequestErr)
  888. return
  889. }
  890. typ, err := strconv.ParseInt(typeStr, 10, 64)
  891. if err != nil {
  892. log.Error("strconv.ParseInt(%s) error(%v)", typeStr, err)
  893. c.JSON(nil, ecode.RequestErr)
  894. return
  895. }
  896. public, err := strconv.Atoi(pubStr)
  897. if err != nil {
  898. log.Error("strconv.ParseInt(%s) error(%v)", pubStr, err)
  899. c.JSON(nil, ecode.RequestErr)
  900. return
  901. }
  902. err = favSvc.UpFolderAttr(c, int8(typ), mid.(int64), fid, int32(public))
  903. c.JSON(nil, err)
  904. }
  905. // moveFavs move some video into other folder.
  906. func moveFavs(c *bm.Context) {
  907. mid, _ := c.Get("mid")
  908. params := c.Request.Form
  909. typeStr := params.Get("type")
  910. ofidStr := params.Get("old_fid")
  911. nfidStr := params.Get("new_fid")
  912. oidsStr := params.Get("oids")
  913. if oidsStr == "" || ofidStr == "" || nfidStr == "" || typeStr == "" {
  914. log.Warn("args oids(%s) old_fid(%s) new_fid(%s) type(%s) is empty", oidsStr, ofidStr, nfidStr, typeStr)
  915. c.JSON(nil, ecode.RequestErr)
  916. return
  917. }
  918. if ofidStr == nfidStr {
  919. log.Warn("move favs to the same folder...")
  920. c.JSON(nil, ecode.FavFolderSame)
  921. return
  922. }
  923. ofid, err := strconv.ParseInt(ofidStr, 10, 64)
  924. if err != nil {
  925. log.Error("strconv.ParseInt(%s) error(%v)", ofidStr, err)
  926. c.JSON(nil, ecode.RequestErr)
  927. return
  928. }
  929. nfid, err := strconv.ParseInt(nfidStr, 10, 64)
  930. if err != nil {
  931. log.Error("strconv.ParseInt(%s) error(%v)", nfidStr, err)
  932. c.JSON(nil, ecode.RequestErr)
  933. return
  934. }
  935. typ, err := strconv.ParseInt(typeStr, 10, 64)
  936. if err != nil {
  937. log.Error("strconv.ParseInt(%s) error(%v)", typeStr, err)
  938. c.JSON(nil, ecode.RequestErr)
  939. return
  940. }
  941. oidStrs := strings.Split(oidsStr, ",")
  942. if len(oidStrs) == 0 {
  943. c.JSON(nil, ecode.RequestErr)
  944. return
  945. }
  946. if len(oidStrs) > conf.Conf.Fav.MaxOperationNum {
  947. c.JSON(nil, ecode.FavMaxOperNum)
  948. return
  949. }
  950. oids := make([]int64, len(oidStrs))
  951. var oid int64
  952. for i, oidStr := range oidStrs {
  953. oid, err = strconv.ParseInt(oidStr, 10, 64)
  954. if err != nil {
  955. log.Error("strconv.ParseInt(%s) error(%v)", oidStr, err)
  956. c.JSON(nil, ecode.RequestErr)
  957. return
  958. }
  959. oids[i] = oid
  960. }
  961. err = favSvc.MoveFavs(c, int8(typ), mid.(int64), ofid, nfid, oids)
  962. c.JSON(nil, err)
  963. }
  964. // copyFavs copy resources into other folder.
  965. func copyFavs(c *bm.Context) {
  966. mid, _ := c.Get("mid")
  967. params := c.Request.Form
  968. typeStr := params.Get("type")
  969. omidStr := params.Get("old_mid")
  970. ofidStr := params.Get("old_fid")
  971. nfidStr := params.Get("new_fid")
  972. oidsStr := params.Get("oids")
  973. if oidsStr == "" || ofidStr == "" || nfidStr == "" || typeStr == "" {
  974. log.Warn("args oids(%s) old_fid(%s) new_fid(%s) type(%s) is empty", oidsStr, ofidStr, nfidStr, typeStr)
  975. c.JSON(nil, ecode.RequestErr)
  976. return
  977. }
  978. if ofidStr == nfidStr {
  979. log.Warn("move favs to the same folder...")
  980. c.JSON(nil, ecode.FavFolderSame)
  981. return
  982. }
  983. var (
  984. err error
  985. omid int64
  986. )
  987. if omidStr != "" {
  988. omid, err = strconv.ParseInt(omidStr, 10, 64)
  989. if err != nil {
  990. log.Error("strconv.ParseInt(%s) error(%v)", omidStr, err)
  991. c.JSON(nil, ecode.RequestErr)
  992. return
  993. }
  994. }
  995. ofid, err := strconv.ParseInt(ofidStr, 10, 64)
  996. if err != nil {
  997. log.Error("strconv.ParseInt(%s) error(%v)", ofidStr, err)
  998. c.JSON(nil, ecode.RequestErr)
  999. return
  1000. }
  1001. nfid, err := strconv.ParseInt(nfidStr, 10, 64)
  1002. if err != nil {
  1003. log.Error("strconv.ParseInt(%s) error(%v)", nfidStr, err)
  1004. c.JSON(nil, ecode.RequestErr)
  1005. return
  1006. }
  1007. typ, err := strconv.ParseInt(typeStr, 10, 64)
  1008. if err != nil {
  1009. log.Error("strconv.ParseInt(%s) error(%v)", typeStr, err)
  1010. c.JSON(nil, ecode.RequestErr)
  1011. return
  1012. }
  1013. oidStrs := strings.Split(oidsStr, ",")
  1014. if len(oidStrs) == 0 {
  1015. c.JSON(nil, ecode.RequestErr)
  1016. return
  1017. }
  1018. if len(oidStrs) > conf.Conf.Fav.MaxOperationNum {
  1019. c.JSON(nil, ecode.FavMaxOperNum)
  1020. return
  1021. }
  1022. oids := make([]int64, len(oidStrs))
  1023. var oid int64
  1024. for i, oidStr := range oidStrs {
  1025. oid, err = strconv.ParseInt(oidStr, 10, 64)
  1026. if err != nil {
  1027. log.Error("strconv.ParseInt(%s) error(%v)", oidStr, err)
  1028. c.JSON(nil, ecode.RequestErr)
  1029. return
  1030. }
  1031. oids[i] = oid
  1032. }
  1033. err = favSvc.CopyFavs(c, int8(typ), omid, mid.(int64), ofid, nfid, oids)
  1034. c.JSON(nil, err)
  1035. }
  1036. // inDefaultFolder detemine resource whether or not favored in default folder.
  1037. func inDefaultFolder(c *bm.Context) {
  1038. mid, _ := c.Get("mid")
  1039. params := c.Request.URL.Query()
  1040. typeStr := params.Get("type")
  1041. oidStr := params.Get("oid")
  1042. if oidStr == "" || typeStr == "" {
  1043. log.Warn("oid(%s) or type(%s) is empty", oidStr, typeStr)
  1044. c.JSON(nil, ecode.RequestErr)
  1045. return
  1046. }
  1047. typ, err := strconv.ParseInt(typeStr, 10, 8)
  1048. if err != nil {
  1049. log.Error("strconv.ParseInt(%s) error(%v)", typeStr, err)
  1050. c.JSON(nil, ecode.RequestErr)
  1051. return
  1052. }
  1053. oid, err := strconv.ParseInt(oidStr, 10, 64)
  1054. if err != nil {
  1055. log.Error("strconv.ParseInt(%s) error(%v)", oidStr, err)
  1056. c.JSON(nil, ecode.RequestErr)
  1057. return
  1058. }
  1059. var isIn bool
  1060. isIn, err = favSvc.InDefaultFolder(c, int8(typ), mid.(int64), oid)
  1061. data := map[string]bool{"default": isIn}
  1062. c.JSON(data, err)
  1063. }
  1064. // userList return all objects in the fid folder.
  1065. func userList(c *bm.Context) {
  1066. // params
  1067. params := c.Request.Form
  1068. typeStr := params.Get("type")
  1069. oidStr := params.Get("oid")
  1070. pnStr := params.Get("pn")
  1071. psStr := params.Get("ps")
  1072. var (
  1073. err error
  1074. oid int64
  1075. )
  1076. if typeStr == "" || oidStr == "" {
  1077. c.JSON(nil, ecode.RequestErr)
  1078. return
  1079. }
  1080. typ, err := strconv.ParseInt(typeStr, 10, 8)
  1081. if err != nil {
  1082. log.Error("strconv.ParseInt(%s) error(%v)", typeStr, err)
  1083. c.JSON(nil, ecode.RequestErr)
  1084. return
  1085. }
  1086. if oid, err = strconv.ParseInt(oidStr, 10, 64); err != nil {
  1087. log.Error("strconv.ParseInt(%s) error(%v)", oidStr, err)
  1088. c.JSON(nil, ecode.RequestErr)
  1089. return
  1090. }
  1091. pn, err := strconv.Atoi(pnStr)
  1092. if err != nil || pn < 1 {
  1093. pn = 1
  1094. }
  1095. ps, err := strconv.Atoi(psStr)
  1096. if err != nil || ps > conf.Conf.Fav.MaxBatchSize || ps <= 0 {
  1097. ps = conf.Conf.Fav.MaxBatchSize
  1098. }
  1099. // fav users
  1100. data, err := favSvc.UserList(c, int8(typ), oid, pn, ps)
  1101. if err != nil {
  1102. c.JSON(nil, err)
  1103. return
  1104. }
  1105. c.JSON(data, nil)
  1106. }
  1107. // oidCount return oid's fav stats.
  1108. func oidCount(c *bm.Context) {
  1109. // params
  1110. params := c.Request.Form
  1111. typeStr := params.Get("type")
  1112. oidStr := params.Get("oid")
  1113. var (
  1114. err error
  1115. oid int64
  1116. )
  1117. if typeStr == "" || oidStr == "" {
  1118. c.JSON(nil, ecode.RequestErr)
  1119. return
  1120. }
  1121. typ, err := strconv.ParseInt(typeStr, 10, 8)
  1122. if err != nil {
  1123. log.Error("strconv.ParseInt(%s) error(%v)", typeStr, err)
  1124. c.JSON(nil, ecode.RequestErr)
  1125. return
  1126. }
  1127. if oid, err = strconv.ParseInt(oidStr, 10, 64); err != nil {
  1128. log.Error("strconv.ParseInt(%s) error(%v)", oidStr, err)
  1129. c.JSON(nil, ecode.RequestErr)
  1130. return
  1131. }
  1132. // fav users
  1133. data, err := favSvc.OidCount(c, int8(typ), oid)
  1134. if err != nil {
  1135. c.JSON(nil, err)
  1136. return
  1137. }
  1138. c.JSON(data, nil)
  1139. }
  1140. // oidsCount return oid's fav stats.
  1141. func oidsCount(c *bm.Context) {
  1142. // params
  1143. params := c.Request.Form
  1144. typeStr := params.Get("type")
  1145. oidsStr := params.Get("oids")
  1146. var err error
  1147. if typeStr == "" || oidsStr == "" {
  1148. c.JSON(nil, ecode.RequestErr)
  1149. return
  1150. }
  1151. typ, err := strconv.ParseInt(typeStr, 10, 8)
  1152. if err != nil {
  1153. log.Error("strconv.ParseInt(%s) error(%v)", typeStr, err)
  1154. c.JSON(nil, ecode.RequestErr)
  1155. return
  1156. }
  1157. oids, err := xstr.SplitInts(oidsStr)
  1158. if err != nil {
  1159. log.Error("xstr.SplitInts(oidsStr:%v) err(%v)", oidsStr, err)
  1160. return
  1161. }
  1162. data, err := favSvc.OidsCount(c, int8(typ), oids)
  1163. if err != nil {
  1164. c.JSON(nil, err)
  1165. return
  1166. }
  1167. c.JSON(data, nil)
  1168. }
  1169. // isCleaned check the clean action's cool down time and access
  1170. func isCleaned(c *bm.Context) {
  1171. mid, _ := c.Get("mid")
  1172. params := c.Request.URL.Query()
  1173. typeStr := params.Get("type")
  1174. fidStr := params.Get("fid")
  1175. if fidStr == "" || typeStr == "" {
  1176. log.Error("arg fids or type is empty")
  1177. c.JSON(nil, ecode.RequestErr)
  1178. return
  1179. }
  1180. typ, err := strconv.ParseInt(typeStr, 10, 8)
  1181. if err != nil {
  1182. log.Error("strconv.ParseInt(%s) error(%v)", typeStr, err)
  1183. c.JSON(nil, ecode.RequestErr)
  1184. return
  1185. }
  1186. fid, err := strconv.ParseInt(fidStr, 10, 64)
  1187. if err != nil {
  1188. log.Error("strconv.ParseInt(%s) error(%v)", fidStr, err)
  1189. c.JSON(nil, ecode.RequestErr)
  1190. return
  1191. }
  1192. cleanState, err := favSvc.CleanState(c, int8(typ), mid.(int64), fid)
  1193. if err != nil {
  1194. log.Error("favSvc.IsCleaned(%d,%d) error(%v)", mid, fid, err)
  1195. c.JSON(nil, err)
  1196. return
  1197. }
  1198. data := map[string]interface{}{"state": cleanState}
  1199. c.JSON(data, nil)
  1200. }
  1201. func cleanInvalidFavs(c *bm.Context) {
  1202. mid, _ := c.Get("mid")
  1203. params := c.Request.Form
  1204. typeStr := params.Get("type")
  1205. fidStr := params.Get("fid")
  1206. if fidStr == "" || typeStr == "" {
  1207. log.Error("arg fids or type is empty")
  1208. c.JSON(nil, ecode.RequestErr)
  1209. return
  1210. }
  1211. typ, err := strconv.ParseInt(typeStr, 10, 8)
  1212. if err != nil {
  1213. log.Error("strconv.ParseInt(%s) error(%v)", typeStr, err)
  1214. c.JSON(nil, ecode.RequestErr)
  1215. return
  1216. }
  1217. fid, err := strconv.ParseInt(fidStr, 10, 64)
  1218. if err != nil {
  1219. log.Error("strconv.ParseInt(%s) error(%v)", fidStr, err)
  1220. c.JSON(nil, ecode.RequestErr)
  1221. return
  1222. }
  1223. if err = favSvc.CleanInvalidArcs(c, int8(typ), mid.(int64), fid); err != nil {
  1224. log.Error("favSvc.CleanInvalidArcs(%d,%d,%d) error(%v)", typ, mid, fid, err)
  1225. }
  1226. c.JSON(nil, err)
  1227. }