creative.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  1. package http
  2. import (
  3. "encoding/base64"
  4. "io/ioutil"
  5. "net/http"
  6. "net/url"
  7. "strconv"
  8. "strings"
  9. "go-common/app/interface/openplatform/article/conf"
  10. "go-common/app/interface/openplatform/article/model"
  11. "go-common/library/ecode"
  12. "go-common/library/log"
  13. bm "go-common/library/net/http/blademaster"
  14. "go-common/library/net/metadata"
  15. )
  16. func lists(c *bm.Context) {
  17. var (
  18. mid int64
  19. err error
  20. novel bool
  21. list []*model.CreativeList
  22. )
  23. // get mid
  24. midInter, _ := c.Get("mid")
  25. mid = midInter.(int64)
  26. if novel, list, err = artSrv.CreativeUpLists(c, mid); err != nil {
  27. c.JSON(nil, err)
  28. return
  29. }
  30. c.JSON(map[string]interface{}{
  31. "novel": novel,
  32. "lists": list,
  33. "total": len(list),
  34. "limit": conf.Conf.Article.ListLimit,
  35. }, nil)
  36. }
  37. func addList(c *bm.Context) {
  38. var (
  39. mid int64
  40. err error
  41. )
  42. // get mid
  43. midInter, _ := c.Get("mid")
  44. mid = midInter.(int64)
  45. req := new(struct {
  46. Name string `form:"name" validate:"required"`
  47. Summary string `form:"summary" validate:"min=0,max=233"`
  48. ImageURL string `form:"image_url"`
  49. })
  50. if err = c.Bind(req); err != nil {
  51. c.JSON(nil, ecode.RequestErr)
  52. return
  53. }
  54. if req.ImageURL != "" && !model.CheckBFSImage(req.ImageURL) {
  55. c.JSON(nil, ecode.RequestErr)
  56. return
  57. }
  58. c.JSON(artSrv.CreativeAddList(c, mid, req.Name, req.Summary, req.ImageURL))
  59. }
  60. func delList(c *bm.Context) {
  61. var (
  62. mid, id int64
  63. )
  64. // get mid
  65. midInter, _ := c.Get("mid")
  66. mid = midInter.(int64)
  67. id, _ = strconv.ParseInt(c.Request.Form.Get("id"), 10, 64)
  68. if id <= 0 {
  69. c.JSON(nil, ecode.RequestErr)
  70. return
  71. }
  72. c.JSON(nil, artSrv.CreativeDelList(c, mid, id))
  73. }
  74. func updateArticleList(c *bm.Context) {
  75. var (
  76. mid int64
  77. )
  78. // get mid
  79. midInter, _ := c.Get("mid")
  80. mid = midInter.(int64)
  81. listID, _ := strconv.ParseInt(c.Request.Form.Get("list_id"), 10, 64)
  82. if listID < 0 {
  83. c.JSON(nil, ecode.RequestErr)
  84. return
  85. }
  86. articleID, _ := strconv.ParseInt(c.Request.Form.Get("article_id"), 10, 64)
  87. if articleID <= 0 {
  88. c.JSON(nil, ecode.RequestErr)
  89. return
  90. }
  91. c.JSON(nil, artSrv.CreativeUpdateArticleList(c, mid, articleID, listID, true))
  92. }
  93. func listAllArticles(c *bm.Context) {
  94. var (
  95. mid, id int64
  96. err error
  97. list *model.List
  98. arts []*model.ListArtMeta
  99. )
  100. // get mid
  101. midInter, _ := c.Get("mid")
  102. mid = midInter.(int64)
  103. id, _ = strconv.ParseInt(c.Request.Form.Get("id"), 10, 64)
  104. if id <= 0 {
  105. c.JSON(nil, ecode.RequestErr)
  106. return
  107. }
  108. if list, arts, err = artSrv.CreativeListAllArticles(c, mid, id); err != nil {
  109. c.JSON(nil, err)
  110. return
  111. }
  112. c.JSON(map[string]interface{}{
  113. "list": list,
  114. "articles": arts,
  115. "total": len(arts),
  116. "limit": conf.Conf.Article.ListArtsLimit,
  117. }, nil)
  118. }
  119. func updateListArticles(c *bm.Context) {
  120. var (
  121. mid int64
  122. list *model.List
  123. err error
  124. )
  125. // get mid
  126. midInter, _ := c.Get("mid")
  127. mid = midInter.(int64)
  128. if err != nil {
  129. c.JSON(nil, ecode.RequestErr)
  130. return
  131. }
  132. req := new(struct {
  133. ListID int64 `form:"list_id" validate:"min=0"`
  134. Name string `form:"name" validate:"required"`
  135. Summary string `form:"summary" validate:"min=0,max=233"`
  136. ImageURL string `form:"image_url"`
  137. OnlyList bool `form:"only_list"`
  138. IDs []int64 `form:"ids,split"`
  139. })
  140. if err = c.Bind(req); err != nil {
  141. c.JSON(nil, ecode.RequestErr)
  142. return
  143. }
  144. if req.ImageURL != "" && !model.CheckBFSImage(req.ImageURL) {
  145. c.JSON(nil, ecode.RequestErr)
  146. return
  147. }
  148. if list, err = artSrv.CreativeUpdateListArticles(c, req.ListID, req.Name, req.ImageURL, req.Summary, req.OnlyList, mid, req.IDs); err != nil {
  149. c.JSON(nil, err)
  150. return
  151. }
  152. c.JSON(map[string]interface{}{"list": list}, nil)
  153. }
  154. func canAddArts(c *bm.Context) {
  155. var (
  156. mid int64
  157. err error
  158. arts []*model.ListArtMeta
  159. )
  160. // get mid
  161. midInter, _ := c.Get("mid")
  162. mid = midInter.(int64)
  163. if arts, err = artSrv.CreativeCanAddArticles(c, mid); err != nil {
  164. c.JSON(nil, err)
  165. return
  166. }
  167. c.JSON(map[string]interface{}{"articles": arts}, nil)
  168. }
  169. func webSubArticle(c *bm.Context) {
  170. params := c.Request.Form
  171. aidStr := params.Get("aid")
  172. title := params.Get("title")
  173. content := params.Get("content")
  174. summary := params.Get("summary")
  175. bannerURL := params.Get("banner_url")
  176. tidStr := params.Get("tid")
  177. categoryStr := params.Get("category")
  178. reprintStr := params.Get("reprint")
  179. tags := params.Get("tags")
  180. imageURLs := params.Get("image_urls")
  181. wordsStr := params.Get("words")
  182. actIDStr := params.Get("act_id")
  183. scoreStr := params.Get("score")
  184. mediaIDStr := params.Get("media_id")
  185. spoilerStr := params.Get("spoiler")
  186. dynamicIntrosStr := params.Get("dynamic_intro")
  187. originImageURLs := params.Get("origin_image_urls")
  188. ip := metadata.String(c, metadata.RemoteIP)
  189. ck := c.Request.Header.Get("cookie")
  190. // check params
  191. midI, _ := c.Get("mid")
  192. mid, _ := midI.(int64)
  193. var (
  194. spoiler int64
  195. aid int64
  196. actID int64
  197. mediaID int64
  198. score int64
  199. err1, err2, err3 error
  200. )
  201. if aidStr != "" {
  202. id, err := strconv.ParseInt(aidStr, 10, 64)
  203. if err != nil || id <= 0 {
  204. c.JSON(nil, ecode.RequestErr)
  205. return
  206. }
  207. aid = id
  208. }
  209. if actIDStr != "" {
  210. actid, err := strconv.ParseInt(actIDStr, 10, 64)
  211. if err != nil || actid <= 0 {
  212. c.JSON(nil, ecode.RequestErr)
  213. return
  214. }
  215. actID = actid
  216. }
  217. listIDStr := params.Get("list_id")
  218. var listID int64
  219. if listIDStr != "" {
  220. lid, err := strconv.ParseInt(listIDStr, 10, 64)
  221. if err != nil || lid < 0 {
  222. c.JSON(nil, ecode.RequestErr)
  223. return
  224. }
  225. listID = lid
  226. }
  227. if mediaIDStr != "" {
  228. mediaID, err1 = strconv.ParseInt(mediaIDStr, 10, 64)
  229. if err1 != nil || mediaID < 0 {
  230. c.JSON(nil, ecode.RequestErr)
  231. return
  232. }
  233. }
  234. if mediaID > 0 {
  235. score, err2 = strconv.ParseInt(scoreStr, 10, 64)
  236. spoiler, err3 = strconv.ParseInt(spoilerStr, 10, 32)
  237. if err2 != nil || err3 != nil || spoiler < 0 || (score < 1 || score > 10 || score%2 != 0) {
  238. c.JSON(nil, ecode.RequestErr)
  239. return
  240. }
  241. if ok, err := artSrv.LevelRequired(c, mid); err != nil || !ok {
  242. c.JSON(nil, ecode.ArtLevelFailedErr)
  243. return
  244. }
  245. if id, err := artSrv.MediaArticle(c, mediaID, mid); err != nil || id > 0 {
  246. c.JSON(nil, ecode.ArtMediaExistedErr)
  247. return
  248. }
  249. }
  250. words, _ := strconv.ParseInt(wordsStr, 10, 64)
  251. artParam, err := artSrv.ParseParam(c, categoryStr, reprintStr, tidStr, imageURLs, originImageURLs)
  252. if err != nil {
  253. c.JSON(nil, err)
  254. return
  255. }
  256. // params
  257. art := &model.ArtParam{
  258. AID: aid,
  259. MID: mid,
  260. Title: title,
  261. Content: content,
  262. Summary: summary,
  263. BannerURL: bannerURL,
  264. Tags: tags,
  265. ImageURLs: artParam.ImageURLs,
  266. OriginImageURLs: artParam.OriginImageURLs,
  267. RealIP: ip,
  268. Category: artParam.Category,
  269. TemplateID: artParam.TemplateID,
  270. Reprint: artParam.Reprint,
  271. Words: words,
  272. DynamicIntro: dynamicIntrosStr,
  273. ActivityID: actID,
  274. ListID: listID,
  275. MediaID: mediaID,
  276. Spoiler: int32(spoiler),
  277. }
  278. // submit
  279. id, err := artSrv.CreativeSubArticle(c, mid, art, "", ck, metadata.String(c, metadata.RemoteIP))
  280. if err != nil {
  281. c.JSON(nil, err)
  282. return
  283. }
  284. // 番剧评分
  285. if mediaID > 0 {
  286. artSrv.SetMediaScore(c, score, id, mediaID, mid)
  287. }
  288. c.JSON(map[string]int64{"aid": id}, nil)
  289. }
  290. func webUpdateArticle(c *bm.Context) {
  291. params := c.Request.Form
  292. aidStr := params.Get("aid")
  293. title := params.Get("title")
  294. content := params.Get("content")
  295. summary := params.Get("summary")
  296. bannerURL := params.Get("banner_url")
  297. tidStr := params.Get("tid")
  298. categoryStr := params.Get("category")
  299. reprintStr := params.Get("reprint")
  300. tags := params.Get("tags")
  301. imageURLs := params.Get("image_urls")
  302. wordsStr := params.Get("words")
  303. spoilerStr := params.Get("spoiler")
  304. dynamicIntrosStr := params.Get("dynamic_intro")
  305. originImageURLs := params.Get("origin_image_urls")
  306. scoreStr := params.Get("score")
  307. mediaIDStr := params.Get("media_id")
  308. ip := metadata.String(c, metadata.RemoteIP)
  309. ck := c.Request.Header.Get("cookie")
  310. // check params
  311. midI, _ := c.Get("mid")
  312. mid, _ := midI.(int64)
  313. aid, err := strconv.ParseInt(aidStr, 10, 64)
  314. if err != nil || aid <= 0 {
  315. c.JSON(nil, ecode.RequestErr)
  316. return
  317. }
  318. words, _ := strconv.ParseInt(wordsStr, 10, 64)
  319. artParam, err := artSrv.ParseParam(c, categoryStr, reprintStr, tidStr, imageURLs, originImageURLs)
  320. if err != nil {
  321. c.JSON(nil, err)
  322. return
  323. }
  324. listIDStr := params.Get("list_id")
  325. var listID int64
  326. if listIDStr != "" {
  327. lid, err := strconv.ParseInt(listIDStr, 10, 64)
  328. if err != nil || lid < 0 {
  329. c.JSON(nil, ecode.RequestErr)
  330. return
  331. }
  332. listID = lid
  333. }
  334. var (
  335. spoiler int64
  336. mediaID int64
  337. score int64
  338. err1, err2, err3 error
  339. )
  340. if mediaIDStr != "" {
  341. mediaID, err1 = strconv.ParseInt(mediaIDStr, 10, 64)
  342. if err1 != nil || mediaID < 0 {
  343. c.JSON(nil, ecode.RequestErr)
  344. return
  345. }
  346. }
  347. if mediaID > 0 {
  348. score, err2 = strconv.ParseInt(scoreStr, 10, 64)
  349. spoiler, err3 = strconv.ParseInt(spoilerStr, 10, 32)
  350. if err2 != nil || err3 != nil || spoiler < 0 || (score < 1 || score > 10 || score%2 != 0) {
  351. c.JSON(nil, ecode.RequestErr)
  352. return
  353. }
  354. if mediaid, err := artSrv.MediaIDByID(c, aid); err != nil || mediaid != mediaID {
  355. c.JSON(nil, ecode.RequestErr)
  356. return
  357. }
  358. }
  359. // params
  360. art := &model.ArtParam{
  361. AID: aid,
  362. MID: mid,
  363. Title: title,
  364. Content: content,
  365. Summary: summary,
  366. BannerURL: bannerURL,
  367. Tags: tags,
  368. ImageURLs: artParam.ImageURLs,
  369. OriginImageURLs: artParam.OriginImageURLs,
  370. RealIP: ip,
  371. Category: artParam.Category,
  372. TemplateID: artParam.TemplateID,
  373. Reprint: artParam.Reprint,
  374. Words: words,
  375. DynamicIntro: dynamicIntrosStr,
  376. ListID: listID,
  377. Spoiler: int32(spoiler),
  378. MediaID: mediaID,
  379. }
  380. if err = artSrv.CreativeUpdateArticle(c, mid, art, "", ck, ip); err != nil {
  381. c.JSON(nil, err)
  382. return
  383. }
  384. // 番剧评分
  385. if mediaID > 0 {
  386. artSrv.SetMediaScore(c, score, aid, mediaID, mid)
  387. }
  388. c.JSON(nil, nil)
  389. }
  390. func webSubmitDraft(c *bm.Context) {
  391. params := c.Request.Form
  392. aidStr := params.Get("aid")
  393. title := params.Get("title")
  394. content := params.Get("content")
  395. summary := params.Get("summary")
  396. bannerURL := params.Get("banner_url")
  397. tidStr := params.Get("tid")
  398. categoryStr := params.Get("category")
  399. reprintStr := params.Get("reprint")
  400. tags := params.Get("tags")
  401. imageURLs := params.Get("image_urls")
  402. wordsStr := params.Get("words")
  403. mediaIDStr := params.Get("media_id")
  404. spoilerStr := params.Get("spoiler")
  405. dynamicIntrosStr := params.Get("dynamic_intro")
  406. originImageURLs := params.Get("origin_image_urls")
  407. ip := metadata.String(c, metadata.RemoteIP)
  408. // check params
  409. midI, _ := c.Get("mid")
  410. mid, _ := midI.(int64)
  411. var (
  412. did int64
  413. mediaID int64
  414. spoiler int64
  415. err1, err2 error
  416. )
  417. if aidStr != "" {
  418. var err error
  419. did, err = strconv.ParseInt(aidStr, 10, 64)
  420. if err != nil || did <= 0 {
  421. c.JSON(nil, ecode.RequestErr)
  422. return
  423. }
  424. }
  425. words, _ := strconv.ParseInt(wordsStr, 10, 64)
  426. artParam, err := artSrv.ParseDraftParam(c, categoryStr, reprintStr, tidStr, imageURLs, originImageURLs)
  427. if err != nil {
  428. c.JSON(nil, err)
  429. return
  430. }
  431. listIDStr := params.Get("list_id")
  432. var listID int64
  433. if listIDStr != "" {
  434. var lid int64
  435. lid, err = strconv.ParseInt(listIDStr, 10, 64)
  436. if err != nil || lid < 0 {
  437. c.JSON(nil, ecode.RequestErr)
  438. return
  439. }
  440. listID = lid
  441. }
  442. if mediaIDStr != "" {
  443. mediaID, err1 = strconv.ParseInt(mediaIDStr, 10, 64)
  444. spoiler, err2 = strconv.ParseInt(spoilerStr, 10, 32)
  445. if err1 != nil || err2 != nil || mediaID < 0 || spoiler < 0 {
  446. c.JSON(nil, ecode.RequestErr)
  447. return
  448. }
  449. }
  450. // params
  451. art := &model.ArtParam{
  452. AID: did,
  453. MID: mid,
  454. Title: title,
  455. Content: content,
  456. Summary: summary,
  457. BannerURL: bannerURL,
  458. Tags: tags,
  459. ImageURLs: artParam.ImageURLs,
  460. OriginImageURLs: artParam.OriginImageURLs,
  461. RealIP: ip,
  462. Category: artParam.Category,
  463. TemplateID: artParam.TemplateID,
  464. Reprint: artParam.Reprint,
  465. Words: words,
  466. DynamicIntro: dynamicIntrosStr,
  467. ListID: listID,
  468. MediaID: mediaID,
  469. Spoiler: int32(spoiler),
  470. }
  471. // add draft
  472. id, err := artSrv.CreativeAddDraft(c, mid, art)
  473. if err != nil {
  474. c.JSON(nil, err)
  475. return
  476. }
  477. c.JSON(map[string]int64{"aid": id}, nil)
  478. }
  479. func webArticleList(c *bm.Context) {
  480. params := c.Request.Form
  481. pnStr := params.Get("pn")
  482. psStr := params.Get("ps")
  483. sortStr := params.Get("sort")
  484. groupStr := params.Get("group")
  485. categoryStr := params.Get("category")
  486. ip := metadata.String(c, metadata.RemoteIP)
  487. // check
  488. midI, _ := c.Get("mid")
  489. mid, _ := midI.(int64)
  490. pn, err := strconv.Atoi(pnStr)
  491. if err != nil || pn < 1 {
  492. pn = 1
  493. }
  494. ps, err := strconv.Atoi(psStr)
  495. if err != nil || ps <= 10 {
  496. ps = 20
  497. }
  498. sort, err := strconv.Atoi(sortStr)
  499. if err != nil || sort < 0 {
  500. sort = 0
  501. }
  502. group, err := strconv.Atoi(groupStr)
  503. if err != nil || group < 0 {
  504. group = 0
  505. }
  506. category, err := strconv.Atoi(categoryStr)
  507. if err != nil || category < 0 {
  508. category = 0
  509. }
  510. arts, err := artSrv.CreativeArticles(c, mid, int(pn), int(ps), sort, group, category, ip)
  511. if err != nil {
  512. c.JSON(nil, err)
  513. return
  514. }
  515. c.JSONMap(map[string]interface{}{"artlist": arts}, nil)
  516. }
  517. func webDraftList(c *bm.Context) {
  518. params := c.Request.Form
  519. pnStr := params.Get("pn")
  520. psStr := params.Get("ps")
  521. ip := metadata.String(c, metadata.RemoteIP)
  522. // check
  523. midI, _ := c.Get("mid")
  524. mid, _ := midI.(int64)
  525. pn, err := strconv.Atoi(pnStr)
  526. if err != nil || pn < 1 {
  527. pn = 1
  528. }
  529. ps, err := strconv.Atoi(psStr)
  530. if err != nil || ps <= 10 {
  531. ps = 20
  532. }
  533. arts, err := artSrv.CreativeDrafts(c, mid, pn, ps, ip)
  534. if err != nil {
  535. c.JSON(nil, err)
  536. return
  537. }
  538. c.JSONMap(map[string]interface{}{"artlist": arts}, nil)
  539. }
  540. func webDraft(c *bm.Context) {
  541. params := c.Request.Form
  542. aidStr := params.Get("aid")
  543. ip := metadata.String(c, metadata.RemoteIP)
  544. // check params
  545. midI, _ := c.Get("mid")
  546. mid, _ := midI.(int64)
  547. aid, err := strconv.ParseInt(aidStr, 10, 64)
  548. if err != nil || aid <= 0 {
  549. c.JSON(nil, ecode.RequestErr)
  550. return
  551. }
  552. c.JSON(artSrv.CreativeDraft(c, aid, mid, ip))
  553. }
  554. func webArticle(c *bm.Context) {
  555. params := c.Request.Form
  556. aidStr := params.Get("aid")
  557. ip := metadata.String(c, metadata.RemoteIP)
  558. // check params
  559. midI, _ := c.Get("mid")
  560. mid, _ := midI.(int64)
  561. aid, err := strconv.ParseInt(aidStr, 10, 64)
  562. if err != nil || aid <= 0 {
  563. c.JSON(nil, ecode.RequestErr)
  564. return
  565. }
  566. c.JSON(artSrv.CreativeView(c, aid, mid, ip))
  567. }
  568. func creatorArticlePre(c *bm.Context) {
  569. var (
  570. isAuthor int
  571. url string
  572. mid int64
  573. )
  574. // get mid
  575. midInter, _ := c.Get("mid")
  576. mid = midInter.(int64)
  577. ia, _, err := artSrv.IsAuthor(c, mid)
  578. if err != nil {
  579. c.JSON(nil, err)
  580. return
  581. }
  582. if ia {
  583. isAuthor = 1
  584. url = "https://member.bilibili.com/article-text/mobile"
  585. } else {
  586. isAuthor = 0
  587. url = "https://www.bilibili.com/read/apply/"
  588. }
  589. c.JSON(map[string]interface{}{
  590. "is_author": isAuthor,
  591. "reason": "", // 保持接口不变
  592. "submit_url": url,
  593. }, nil)
  594. }
  595. func uploadImage(c *bm.Context) {
  596. var (
  597. bs []byte
  598. mid int64
  599. )
  600. midI, _ := c.Get("mid")
  601. mid = midI.(int64)
  602. log.Infov(c, log.KV("log", "creative: upload image"), log.KV("mid", mid))
  603. dataURI := c.Request.FormValue("file")
  604. if dataURI != "" {
  605. dataURI = strings.Split(dataURI, ",")[1]
  606. bs, _ = base64.StdEncoding.DecodeString(dataURI)
  607. } else {
  608. file, _, err := c.Request.FormFile("file")
  609. if err != nil {
  610. c.JSON(nil, ecode.RequestErr)
  611. return
  612. }
  613. defer file.Close()
  614. bs, err = ioutil.ReadAll(file)
  615. if err != nil {
  616. c.JSON(nil, ecode.RequestErr)
  617. return
  618. }
  619. }
  620. ftype := http.DetectContentType(bs)
  621. if ftype != "image/jpeg" && ftype != "image/jpg" && ftype != "image/png" && ftype != "image/gif" {
  622. log.Error("creative: file type not allow file type(%s, mid: %v)", ftype, mid)
  623. c.JSON(nil, ecode.CreativeArticleImageTypeErr)
  624. return
  625. }
  626. url, err := artSrv.ArticleUpCover(c, ftype, bs)
  627. if err != nil {
  628. c.JSON(nil, err)
  629. return
  630. }
  631. c.JSON(map[string]interface{}{
  632. "url": url,
  633. "size": len(bs),
  634. }, nil)
  635. }
  636. func deleteDraft(c *bm.Context) {
  637. params := c.Request.Form
  638. aidStr := params.Get("aid")
  639. // check params
  640. midI, ok := c.Get("mid")
  641. if !ok {
  642. c.JSON(nil, ecode.NoLogin)
  643. return
  644. }
  645. mid, ok := midI.(int64)
  646. if !ok || mid <= 0 {
  647. c.JSON(nil, ecode.NoLogin)
  648. return
  649. }
  650. aid, err := strconv.ParseInt(aidStr, 10, 64)
  651. if err != nil || aid <= 0 {
  652. c.JSON(nil, ecode.RequestErr)
  653. return
  654. }
  655. c.JSON(nil, artSrv.DelArtDraft(c, aid, mid))
  656. }
  657. func delArticle(c *bm.Context) {
  658. params := c.Request.Form
  659. aidStr := params.Get("aid")
  660. // check params
  661. midI, ok := c.Get("mid")
  662. if !ok {
  663. c.JSON(nil, ecode.NoLogin)
  664. return
  665. }
  666. mid, ok := midI.(int64)
  667. if !ok || mid <= 0 {
  668. c.JSON(nil, ecode.NoLogin)
  669. return
  670. }
  671. aid, err := strconv.ParseInt(aidStr, 10, 64)
  672. if err != nil || aid <= 0 {
  673. c.JSON(nil, ecode.RequestErr)
  674. return
  675. }
  676. c.JSON(nil, artSrv.DelArticle(c, aid, mid))
  677. }
  678. func withdrawArticle(c *bm.Context) {
  679. params := c.Request.Form
  680. aidStr := params.Get("aid")
  681. // check params
  682. midI, ok := c.Get("mid")
  683. if !ok {
  684. c.JSON(nil, ecode.NoLogin)
  685. return
  686. }
  687. mid, ok := midI.(int64)
  688. if !ok || mid <= 0 {
  689. c.JSON(nil, ecode.NoLogin)
  690. return
  691. }
  692. aid, err := strconv.ParseInt(aidStr, 10, 64)
  693. if err != nil || aid <= 0 {
  694. c.JSON(nil, ecode.RequestErr)
  695. return
  696. }
  697. c.JSON(nil, artSrv.CreationWithdrawArticle(c, mid, aid))
  698. }
  699. func draftCount(c *bm.Context) {
  700. midI, _ := c.Get("mid")
  701. mid, _ := midI.(int64)
  702. count := artSrv.CreativeDraftCount(c, mid)
  703. c.JSONMap(map[string]interface{}{"count": count}, nil)
  704. }
  705. func articleCapture(c *bm.Context) {
  706. params := c.Request.Form
  707. originURL := params.Get("url")
  708. // check params
  709. midI, ok := c.Get("mid")
  710. if !ok {
  711. c.JSON(nil, ecode.NoLogin)
  712. return
  713. }
  714. mid, ok := midI.(int64)
  715. if !ok || mid <= 0 {
  716. c.JSON(nil, ecode.NoLogin)
  717. return
  718. }
  719. if originURL == "" {
  720. c.JSON(nil, ecode.RequestErr)
  721. return
  722. }
  723. log.Info("capture mid(%d) origin imageURL (%s)", mid, originURL)
  724. _, err := url.ParseRequestURI(originURL)
  725. if err != nil {
  726. log.Error("capture check url(%s) format error(%v)", originURL, err)
  727. c.JSON(nil, ecode.RequestErr)
  728. return
  729. }
  730. imgURL, size, err := artSrv.ArticleCapture(c, originURL)
  731. if err != nil {
  732. c.JSON(nil, err)
  733. return
  734. }
  735. c.JSON(map[string]interface{}{
  736. "url": imgURL,
  737. "size": size,
  738. }, nil)
  739. }