123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557 |
- package http
- import (
- "context"
- "strconv"
- "time"
- "go-common/app/interface/main/app-view/model"
- "go-common/app/interface/main/app-view/model/view"
- resource "go-common/app/service/main/resource/model"
- "go-common/library/ecode"
- bm "go-common/library/net/http/blademaster"
- "go-common/library/net/metadata"
- )
- const (
- _viewPath = "/x/v2/view"
- _viewPagePath = "/x/v2/view/page"
- _headerBuvid = "Buvid"
- )
- var (
- _rate = []int64{564, 1328, 2592, 4192}
- _formats = map[int]string{1: "mp4", 2: "hdmp4", 3: "flv", 4: "flv"}
- _dislike = []*view.Dislike{
- {
- ID: 5,
- Name: "标题党/封面党",
- },
- {
- ID: 6,
- Name: "内容质量差",
- },
- {
- ID: 7,
- Name: "内容/封面令人不适",
- },
- {
- ID: 8,
- Name: "营销广告",
- },
- }
- )
- // viewIndex view handler
- func viewIndex(c *bm.Context) {
- var (
- mid, aid, movieID int64
- err error
- parentMode int
- )
- params := c.Request.Form
- header := c.Request.Header
- // get params
- aidStr := params.Get("aid")
- movieidStr := params.Get("movie_id")
- mobiApp := params.Get("mobi_app")
- device := params.Get("device")
- ak := params.Get("access_key")
- buildStr := params.Get("build")
- from := params.Get("from")
- trackid := params.Get("trackid")
- network := params.Get("network")
- adExtra := params.Get("ad_extra")
- parentModeStr := params.Get("parent_mode")
- parentMode, _ = strconv.Atoi(parentModeStr)
- qnStr := params.Get("qn")
- qn, _ := strconv.Atoi(qnStr)
- fnverStr := params.Get("fnver")
- fnver, _ := strconv.Atoi(fnverStr)
- fnvalStr := params.Get("fnval")
- fnval, _ := strconv.Atoi(fnvalStr)
- forceHost, _ := strconv.Atoi(params.Get("force_host"))
- spmid := params.Get("spmid")
- fromSpmid := params.Get("from_spmid")
- // check params
- if aidStr == "" && movieidStr == "" {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if aidStr != "" && aidStr != "0" {
- if aid, err = strconv.ParseInt(aidStr, 10, 64); err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- } else if movieidStr != "" && movieidStr != "0" {
- if movieID, err = strconv.ParseInt(movieidStr, 10, 64); err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- }
- if aid < 1 && movieID < 1 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- build, err := strconv.Atoi(buildStr)
- if err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- plat := model.Plat(mobiApp, device)
- buvid := header.Get("Buvid")
- disid := header.Get("Display-ID")
- cdnIP := header.Get("X-Cache-Server-Addr")
- if midInter, ok := c.Get("mid"); ok {
- mid = midInter.(int64)
- }
- autoplay, _ := strconv.Atoi(params.Get("autoplay"))
- now := time.Now()
- // view
- ip := metadata.String(c, metadata.RemoteIP)
- viewSvr.ViewInfoc(mid, int(plat), trackid, aidStr, ip, _viewPath, buildStr, buvid, disid, from, now, err, autoplay, spmid, fromSpmid)
- data, err := viewSvr.View(c, mid, aid, movieID, plat, build, qn, fnver, fnval, forceHost, parentMode, ak, mobiApp, device, buvid, cdnIP, network, adExtra, from, now)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- data.Dislikes = _dislike
- compMeta(data, build)
- if mid == 0 && data.Duration > 360 {
- data.Paster, _ = viewSvr.Paster(c, plat, resource.VdoAdsTypeNologin, aidStr, strconv.Itoa(int(data.TypeID)), buvid)
- }
- c.JSON(data, nil)
- viewSvr.RelateInfoc(mid, aid, int(plat), trackid, buildStr, buvid, disid, ip, _viewPath, data.ReturnCode, data.UserFeature, from, data.Relates, now, data.IsRec)
- }
- // viewPage view page handler.
- func viewPage(c *bm.Context) {
- var (
- mid, aid int64
- build int
- err error
- )
- params := c.Request.Form
- header := c.Request.Header
- // get params
- aidStr := params.Get("aid")
- mobiApp := params.Get("mobi_app")
- device := params.Get("device")
- ak := params.Get("access_key")
- buildStr := params.Get("build")
- from := params.Get("from")
- trackid := params.Get("trackid")
- spmid := params.Get("spmid")
- fromSpmid := params.Get("from_spmid")
- // check params
- if aid, err = strconv.ParseInt(aidStr, 10, 64); err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if aid < 1 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if build, err = strconv.Atoi(buildStr); err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- plat := model.Plat(mobiApp, device)
- buvid := header.Get("Buvid")
- disid := header.Get("Display-ID")
- cdnIP := header.Get("X-Cache-Server-Addr")
- if midInter, ok := c.Get("mid"); ok {
- mid = midInter.(int64)
- }
- autoplay, _ := strconv.Atoi(params.Get("autoplay"))
- ip := metadata.String(c, metadata.RemoteIP)
- now := time.Now()
- // view page
- viewSvr.ViewInfoc(mid, int(plat), trackid, aidStr, ip, _viewPagePath, buildStr, buvid, disid, from, now, err, autoplay, spmid, fromSpmid)
- data, err := viewSvr.ViewPage(c, mid, aid, 0, plat, build, ak, mobiApp, device, cdnIP, false, now)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- compMeta(data, build)
- c.JSON(data, nil)
- }
- // videoShot video shot .
- func videoShot(c *bm.Context) {
- var aid, cid int64
- params := c.Request.Form
- if aid, _ = strconv.ParseInt(params.Get("aid"), 10, 64); aid < 1 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if cid, _ = strconv.ParseInt(params.Get("cid"), 10, 64); cid < 1 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- c.JSON(viewSvr.Shot(c, aid, cid))
- }
- // addShare add a share.
- func addShare(c *bm.Context) {
- params := c.Request.Form
- mobiApp := params.Get("mobi_app")
- buvid := c.Request.Header.Get("Buvid")
- from := params.Get("from")
- build := params.Get("build")
- // check
- aidStr := params.Get("aid")
- aid, err := strconv.ParseInt(aidStr, 10, 64)
- if err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- var mid int64
- if midInter, ok := c.Get("mid"); ok {
- mid = midInter.(int64)
- }
- share, isReport, upID, err := viewSvr.AddShare(c, aid, mid, metadata.String(c, metadata.RemoteIP))
- c.JSON(struct {
- Aid int64 `json:"aid"`
- Count int `json:"count"`
- }{aid, share}, err)
- if err != nil {
- return
- }
- // for ai big data
- sendUserAct(mid, mobiApp, buvid, from, build, aidStr, "av", "share")
- if collector != nil && isReport {
- collector.InfoAntiCheat2(c, strconv.FormatInt(upID, 10), strconv.FormatInt(aid, 10), strconv.FormatInt(mid, 10), strconv.FormatInt(aid, 10), "av", "share", "")
- }
- }
- func addCoin(c *bm.Context) {
- var (
- mid, aid, upID int64
- avType int64
- actLike = "cointolike"
- actCoin = "coin"
- )
- params := c.Request.Form
- // check
- mobiApp := params.Get("mobi_app")
- buvid := c.Request.Header.Get("Buvid")
- from := params.Get("from")
- build := params.Get("build")
- aidStr := params.Get("aid")
- upIDStr := params.Get("upid")
- ak := params.Get("access_key")
- multiStr := params.Get("multiply")
- selectLikeStr := params.Get("select_like")
- selectLike, _ := strconv.Atoi(selectLikeStr)
- aid, _ = strconv.ParseInt(aidStr, 10, 64)
- upID, _ = strconv.ParseInt(upIDStr, 10, 64)
- multiply, err := strconv.ParseInt(multiStr, 10, 64)
- if err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if avType, _ = strconv.ParseInt(params.Get("avtype"), 10, 64); avType == 0 {
- avType = 1
- }
- if midInter, ok := c.Get("mid"); ok {
- mid = midInter.(int64)
- }
- // for ai big data
- sendUserAct(mid, mobiApp, buvid, from, build, aidStr, "av", actCoin)
- if selectLike == 1 {
- sendUserAct(mid, mobiApp, buvid, from, build, aidStr, "av", actLike)
- }
- prompt, like, err := viewSvr.AddCoin(c, aid, mid, upID, avType, multiply, ak, selectLike)
- c.JSON(struct {
- Prompt bool `json:"prompt,omitempty"`
- Like bool `json:"like"`
- }{Prompt: prompt, Like: like}, err)
- if err != nil {
- return
- }
- if collector != nil {
- var itemType = "archive"
- if avType == 2 {
- itemType = "article"
- }
- collector.InfoAntiCheat2(c, strconv.FormatInt(upID, 10), strconv.FormatInt(aid, 10), strconv.FormatInt(mid, 10), strconv.FormatInt(aid, 10), itemType, actCoin, "")
- if like {
- collector.InfoAntiCheat2(c, strconv.FormatInt(upID, 10), strconv.FormatInt(aid, 10), strconv.FormatInt(mid, 10), strconv.FormatInt(aid, 10), "av", actLike, "")
- }
- }
- }
- func like(c *bm.Context) {
- var mid int64
- params := c.Request.Form
- // check
- mobiApp := params.Get("mobi_app")
- buvid := c.Request.Header.Get("Buvid")
- from := params.Get("from")
- build := params.Get("build")
- aidStr := params.Get("aid")
- aid, err := strconv.ParseInt(aidStr, 10, 64)
- if err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- like, err := strconv.Atoi(params.Get("like"))
- if err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if like != 0 && like != 1 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if midInter, ok := c.Get("mid"); ok {
- mid = midInter.(int64)
- }
- upperID, toast, err := viewSvr.Like(c, aid, mid, int8(like))
- c.JSON(struct {
- Toast string `json:"toast"`
- }{Toast: toast}, err)
- if err != nil {
- return
- }
- // for ai big data
- action := "like"
- if like == 1 {
- action = "like_cancel"
- }
- sendUserAct(mid, mobiApp, buvid, from, build, aidStr, "av", action)
- if collector != nil {
- collector.InfoAntiCheat2(c, strconv.FormatInt(upperID, 10), strconv.FormatInt(aid, 10), strconv.FormatInt(mid, 10), strconv.FormatInt(aid, 10), "av", action, "")
- }
- }
- func dislike(c *bm.Context) {
- var mid int64
- params := c.Request.Form
- mobiApp := params.Get("mobi_app")
- buvid := c.Request.Header.Get("Buvid")
- from := params.Get("from")
- build := params.Get("build")
- // check
- aidStr := params.Get("aid")
- aid, err := strconv.ParseInt(aidStr, 10, 64)
- if err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- dislike, err := strconv.Atoi(params.Get("dislike"))
- if err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if dislike != 0 && dislike != 1 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if midInter, ok := c.Get("mid"); ok {
- mid = midInter.(int64)
- }
- upperID, err := viewSvr.Dislike(c, aid, mid, int8(dislike))
- c.JSON(nil, err)
- if err != nil {
- return
- }
- // for ai big data
- action := "dislike"
- if dislike == 1 {
- action = "dislike_cancel"
- }
- sendUserAct(mid, mobiApp, buvid, from, build, aidStr, "av", action)
- if collector != nil {
- collector.InfoAntiCheat2(c, strconv.FormatInt(upperID, 10), strconv.FormatInt(aid, 10), strconv.FormatInt(mid, 10), strconv.FormatInt(aid, 10), "av", action, "")
- }
- }
- func addFav(c *bm.Context) {
- var (
- mid int64
- vmid int64
- fid int64
- aid int64
- err error
- )
- params := c.Request.Form
- if midI, ok := c.Get("mid"); ok {
- mid = midI.(int64)
- }
- // check
- if aid, err = strconv.ParseInt(params.Get("aid"), 10, 64); err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if vmid, err = strconv.ParseInt(params.Get("vmid"), 10, 64); err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if fid, err = strconv.ParseInt(params.Get("fid"), 10, 64); err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- ak := params.Get("access_key")
- prompt, err := viewSvr.AddFav(c, mid, vmid, []int64{fid}, aid, ak)
- c.JSON(struct {
- Prompt bool `json:"prompt,omitempty"`
- }{Prompt: prompt}, err)
- }
- // adDislike ad dislike
- func adDislike(c *bm.Context) {
- var mid int64
- params := c.Request.Form
- header := c.Request.Header
- if midInter, ok := c.Get("mid"); ok {
- mid = midInter.(int64)
- }
- gt := params.Get("goto")
- id, _ := strconv.ParseInt(params.Get("id"), 10, 64)
- reasonID, _ := strconv.ParseInt(params.Get("reason_id"), 10, 64)
- cmreasonID, _ := strconv.ParseInt(params.Get("cm_reason_id"), 10, 64)
- rid, _ := strconv.ParseInt(params.Get("rid"), 10, 64)
- tagID, _ := strconv.ParseInt(params.Get("tag_id"), 10, 64)
- adcb := params.Get("ad_cb")
- buvid := header.Get("Buvid")
- if buvid == "" && mid == 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- // for ad data
- err := dislikePub.Send(context.TODO(), strconv.FormatInt(mid, 10), &cmDislike{
- ID: id,
- Buvid: buvid,
- Goto: gt,
- Mid: mid,
- ReasonID: reasonID,
- CMReasonID: cmreasonID,
- UpperID: 0,
- Rid: rid,
- TagID: tagID,
- ADCB: adcb,
- })
- c.JSON(nil, err)
- }
- func compMeta(v *view.View, build int) {
- if build == 5800 || build == 508000 {
- for _, vp := range v.Pages {
- metas := make([]*view.Meta, 0, 4)
- for i, r := range _rate {
- meta := &view.Meta{
- Quality: i + 1,
- Size: int64(float64(r*v.Duration) * 1.1 / 8.0),
- Format: _formats[i+1],
- }
- metas = append(metas, meta)
- }
- vp.Metas = metas
- }
- }
- }
- // vipPlayURL get big-member token.
- func vipPlayURL(c *bm.Context) {
- var mid int64
- if midInter, ok := c.Get("mid"); ok {
- mid = midInter.(int64)
- }
- params := c.Request.Form
- aid, err := strconv.ParseInt(params.Get("aid"), 10, 64)
- if err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- cid, _ := strconv.ParseInt(params.Get("cid"), 10, 64)
- if aid == 0 || cid == 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- c.JSON(viewSvr.VipPlayURL(c, aid, cid, mid))
- }
- // follow check if follow.
- func follow(c *bm.Context) {
- var mid int64
- if midInter, ok := c.Get("mid"); ok {
- mid = midInter.(int64)
- }
- params := c.Request.Form
- vmid, err := strconv.ParseInt(params.Get("vmid"), 10, 64)
- if err != nil || vmid <= 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- c.JSON(viewSvr.Follow(c, vmid, mid))
- }
- func upperRecmd(c *bm.Context) {
- var (
- mid int64
- vmid int64
- header = c.Request.Header
- params = c.Request.Form
- )
- if midInter, ok := c.Get("mid"); ok {
- mid = midInter.(int64)
- }
- mobiApp := params.Get("mobi_app")
- device := params.Get("device")
- platform := params.Get("platform")
- buildStr := params.Get("build")
- build, err := strconv.Atoi(buildStr)
- if err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if vmid, err = strconv.ParseInt(params.Get("vmid"), 10, 64); err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- plat := model.Plat(mobiApp, device)
- buvid := header.Get(_headerBuvid)
- data, err := viewSvr.UpperRecmd(c, plat, platform, mobiApp, device, buvid, build, mid, vmid)
- c.JSON(data, err)
- }
- func likeTriple(c *bm.Context) {
- var (
- mid int64
- actTriple = "triplelike"
- )
- params := &view.TripleParam{}
- if err := c.Bind(params); err != nil {
- return
- }
- buvid := c.Request.Header.Get("Buvid")
- if midInter, ok := c.Get("mid"); ok {
- mid = midInter.(int64)
- }
- // for ai big data
- sendUserAct(mid, params.MobiApp, buvid, params.From, params.Build, strconv.FormatInt(params.AID, 10), "av", actTriple)
- triple, err := viewSvr.LikeTriple(c, params.AID, mid, params.Ak)
- c.JSON(triple, err)
- if err != nil {
- return
- }
- if collector != nil && triple.Anticheat {
- collector.InfoAntiCheat2(c, strconv.FormatInt(triple.UpID, 10), strconv.FormatInt(params.AID, 10), strconv.FormatInt(mid, 10), strconv.FormatInt(params.AID, 10), "av", actTriple, "")
- }
- }
- func sendUserAct(mid int64, mobiApp, buvid, from, build, itemID, itemType, action string) {
- userActPub.Send(context.TODO(), strconv.FormatInt(mid, 10), &userAct{
- Client: mobiApp,
- Buvid: buvid,
- Mid: mid,
- Time: time.Now().Unix(),
- From: from,
- Build: build,
- ItemID: itemID,
- ItemType: itemType,
- Action: action,
- })
- }
|