123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- package http
- import (
- "strconv"
- "go-common/app/interface/main/web/model"
- "go-common/library/ecode"
- bm "go-common/library/net/http/blademaster"
- )
- const (
- _buvid = "buvid3"
- )
- func view(c *bm.Context) {
- var (
- aid, mid, cid int64
- cookieStr string
- err error
- rs *model.View
- )
- cookieStr = c.Request.Header.Get("Cookie")
- aidStr := c.Request.Form.Get("aid")
- if aid, err = strconv.ParseInt(aidStr, 10, 64); err != nil || aid <= 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- // get mid
- if midInter, ok := c.Get("mid"); ok {
- mid = midInter.(int64)
- }
- cidStr := c.Request.Form.Get("cid")
- if cidStr != "" {
- if cid, err = strconv.ParseInt(cidStr, 10, 64); err != nil || cid < 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- }
- cdnIP := c.Request.Header.Get("X-Cache-Server-Addr")
- if rs, err = webSvc.View(c, aid, cid, mid, cdnIP, cookieStr); err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(rs, nil)
- }
- func archiveStat(c *bm.Context) {
- var (
- aid int64
- err error
- )
- aidStr := c.Request.Form.Get("aid")
- if aid, err = strconv.ParseInt(aidStr, 10, 64); err != nil || aid <= 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- c.JSON(webSvc.ArchiveStat(c, aid))
- }
- func addShare(c *bm.Context) {
- var (
- aid, mid int64
- err error
- buvid, sid string
- )
- aidStr := c.Request.Form.Get("aid")
- if aid, err = strconv.ParseInt(aidStr, 10, 64); err != nil || aid <= 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- // get mid
- if midInter, ok := c.Get("mid"); ok {
- mid = midInter.(int64)
- }
- if bdCookie, _ := c.Request.Cookie(_buvid); bdCookie != nil {
- buvid = bdCookie.Value
- }
- if sidCookie, _ := c.Request.Cookie("sid"); sidCookie != nil {
- sid = sidCookie.Value
- }
- c.JSON(webSvc.AddShare(c, aid, mid, c.Request.UserAgent(), c.Request.Referer(), c.Request.URL.Path, buvid, sid))
- }
- func description(c *bm.Context) {
- var (
- aid, page int64
- err error
- )
- params := c.Request.Form
- aidStr := params.Get("aid")
- if aid, err = strconv.ParseInt(aidStr, 10, 64); err != nil || aid <= 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- pstr := params.Get("page")
- if pstr != "" {
- if page, err = strconv.ParseInt(pstr, 10, 64); err != nil || page < 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- }
- c.JSON(webSvc.Description(c, aid, page))
- }
- func arcReport(c *bm.Context) {
- var (
- aid, mid, tp int64
- err error
- params = c.Request.Form
- )
- midStr, _ := c.Get("mid")
- mid = midStr.(int64)
- aidStr := params.Get("aid")
- tpStr := params.Get("type")
- reason := params.Get("reason")
- pics := params.Get("pics")
- if aid, err = strconv.ParseInt(aidStr, 10, 64); err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if tp, err = strconv.ParseInt(tpStr, 10, 64); err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- c.JSON(nil, webSvc.ArcReport(c, mid, aid, tp, reason, pics))
- }
- func appealTags(c *bm.Context) {
- c.JSON(webSvc.AppealTags(c))
- }
- func arcAppeal(c *bm.Context) {
- var (
- mid int64
- err error
- )
- params := c.Request.Form
- midStr, _ := c.Get("mid")
- mid = midStr.(int64)
- data := make(map[string]string)
- for name := range params {
- switch name {
- case "tid":
- tidStr := params.Get("tid")
- if _, err = strconv.ParseInt(tidStr, 10, 64); err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- data["tid"] = tidStr
- case "aid":
- aidStr := params.Get("aid")
- if _, err = strconv.ParseInt(aidStr, 10, 64); err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- data["oid"] = aidStr
- case "desc":
- desc := params.Get("desc")
- if desc == "" {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- data["description"] = desc
- default:
- data[name] = params.Get(name)
- }
- }
- c.JSON(nil, webSvc.ArcAppeal(c, mid, data))
- }
- func authorRecommend(c *bm.Context) {
- var (
- aid int64
- err error
- )
- params := c.Request.Form
- aidStr := params.Get("aid")
- if aid, err = strconv.ParseInt(aidStr, 10, 64); err != nil || aid <= 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- c.JSON(webSvc.AuthorRecommend(c, aid))
- }
- func relatedArcs(c *bm.Context) {
- v := new(struct {
- Aid int64 `form:"aid" validate:"min=1"`
- })
- if err := c.Bind(v); err != nil {
- return
- }
- c.JSON(webSvc.RelatedArcs(c, v.Aid))
- }
- func detail(c *bm.Context) {
- var (
- mid int64
- err error
- rs *model.Detail
- )
- v := new(struct {
- Aid int64 `form:"aid" validate:"min=1"`
- })
- if err = c.Bind(v); err != nil {
- return
- }
- if midStr, ok := c.Get("mid"); ok {
- mid = midStr.(int64)
- }
- cdnIP := c.Request.Header.Get("X-Cache-Server-Addr")
- if rs, err = webSvc.Detail(c, v.Aid, mid, cdnIP, c.Request.Header.Get("Cookie")); err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(rs, nil)
- }
- func arcUGCPay(c *bm.Context) {
- v := new(struct {
- Aid int64 `form:"aid" validate:"min=1"`
- })
- if err := c.Bind(v); err != nil {
- return
- }
- midStr, _ := c.Get("mid")
- mid := midStr.(int64)
- c.JSON(webSvc.ArcUGCPay(c, mid, v.Aid))
- }
- func arcRelation(c *bm.Context) {
- v := new(struct {
- Aid int64 `form:"aid" validate:"min=1"`
- })
- if err := c.Bind(v); err != nil {
- return
- }
- midStr, _ := c.Get("mid")
- mid := midStr.(int64)
- c.JSON(webSvc.ArcRelation(c, mid, v.Aid))
- }
|