123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- package http
- import (
- "strconv"
- rsmdl "go-common/app/interface/main/web-show/model/resource"
- "go-common/library/ecode"
- "go-common/library/log"
- bm "go-common/library/net/http/blademaster"
- )
- const (
- _headerBuvid = "Buvid"
- _buvid = "buvid3"
- )
- func resources(c *bm.Context) {
- arg := new(rsmdl.ArgRess)
- if err := c.Bind(arg); err != nil {
- return
- }
- arg.Mid, arg.Sid, arg.Buvid = device(c)
- data, count, err := resSvc.Resources(c, arg)
- if err != nil {
- log.Error("resSvc.Resource error(%v)", err)
- c.JSON(nil, ecode.Degrade)
- return
- }
- c.JSONMap(map[string]interface{}{
- "count": count,
- "data": data,
- }, nil)
- }
- func resource(c *bm.Context) {
- arg := new(rsmdl.ArgRes)
- if err := c.Bind(arg); err != nil {
- return
- }
- arg.Mid, arg.Sid, arg.Buvid = device(c)
- data, count, err := resSvc.Resource(c, arg)
- if err != nil {
- log.Error("resSvc.Resource error(%v)", err)
- c.JSON(nil, ecode.Degrade)
- return
- }
- c.JSONMap(map[string]interface{}{
- "count": count,
- "data": data,
- }, nil)
- }
- func relation(c *bm.Context) {
- arg := new(rsmdl.ArgAid)
- if err := c.Bind(arg); err != nil {
- return
- }
- arg.Mid, arg.Sid, arg.Buvid = device(c)
- c.JSON(resSvc.Relation(c, arg))
- }
- func advideo(c *bm.Context) {
- arg := new(rsmdl.ArgAid)
- if err := c.Bind(arg); err != nil {
- return
- }
- midTemp, ok := c.Get("mid")
- if !ok {
- log.Info("mid not exist")
- arg.Mid = 0
- } else {
- arg.Mid = midTemp.(int64)
- }
- c.JSON(resSvc.VideoAd(c, arg), nil)
- }
- func urlMonitor(c *bm.Context) {
- params := c.Request.Form
- pfStr := params.Get("pf")
- pf, _ := strconv.Atoi(pfStr)
- c.JSON(resSvc.URLMonitor(c, pf), nil)
- }
- func device(c *bm.Context) (mid int64, sid, buvid string) {
- midTemp, ok := c.Get("mid")
- buvid = c.Request.Header.Get(_headerBuvid)
- if buvid == "" {
- cookie, _ := c.Request.Cookie(_buvid)
- if cookie != nil {
- buvid = cookie.Value
- }
- }
- if !ok {
- if sidCookie, err := c.Request.Cookie("sid"); err == nil {
- sid = sidCookie.Value
- }
- } else {
- mid = midTemp.(int64)
- }
- return
- }
|