123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459 |
- package http
- import (
- "strconv"
- "go-common/library/ecode"
- "go-common/library/log"
- bm "go-common/library/net/http/blademaster"
- "go-common/library/net/metadata"
- "go-common/library/xstr"
- )
- func webListDmPurchases(c *bm.Context) {
- midI, ok := c.Get("mid")
- if !ok {
- c.JSON(nil, ecode.NoLogin)
- return
- }
- mid, _ := midI.(int64)
- ip := metadata.String(c, metadata.RemoteIP)
- danmus, err := danmuSvc.AdvDmPurchaseList(c, mid, ip)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(danmus, nil)
- }
- func webPassDmPurchase(c *bm.Context) {
- params := c.Request.Form
- midI, ok := c.Get("mid")
- if !ok {
- c.JSON(nil, ecode.NoLogin)
- return
- }
- mid, _ := midI.(int64)
- danmuIDStr := params.Get("id")
- danmuID, err := strconv.ParseInt(danmuIDStr, 10, 64)
- if err != nil || danmuID == 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- ip := metadata.String(c, metadata.RemoteIP)
- err = danmuSvc.PassDmPurchase(c, mid, danmuID, ip)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(nil, nil)
- }
- func webDenyDmPurchase(c *bm.Context) {
- params := c.Request.Form
- midI, ok := c.Get("mid")
- if !ok {
- c.JSON(nil, ecode.NoLogin)
- return
- }
- mid, _ := midI.(int64)
- danmuIDStr := params.Get("id")
- danmuID, err := strconv.ParseInt(danmuIDStr, 10, 64)
- if err != nil || danmuID == 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- ip := metadata.String(c, metadata.RemoteIP)
- err = danmuSvc.DenyDmPurchase(c, mid, danmuID, ip)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(nil, nil)
- }
- func webCancelDmPurchase(c *bm.Context) {
- params := c.Request.Form
- midI, ok := c.Get("mid")
- if !ok {
- c.JSON(nil, ecode.NoLogin)
- return
- }
- mid, _ := midI.(int64)
- danmuIDStr := params.Get("id")
- danmuID, err := strconv.ParseInt(danmuIDStr, 10, 64)
- if err != nil || danmuID == 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- ip := metadata.String(c, metadata.RemoteIP)
- err = danmuSvc.CancelDmPurchase(c, mid, danmuID, ip)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(nil, nil)
- }
- func webDmList(c *bm.Context) {
- params := c.Request.Form
- pnStr := params.Get("pn")
- psStr := params.Get("ps")
- idStr := params.Get("id")
- pool := params.Get("pool")
- aidStr := params.Get("aid")
- midStr := params.Get("mid")
- midI, ok := c.Get("mid")
- if !ok {
- c.JSON(nil, ecode.NoLogin)
- return
- }
- mid, _ := midI.(int64)
- id, err := strconv.ParseInt(idStr, 10, 64)
- if err != nil || id <= 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- aid, err := strconv.ParseInt(aidStr, 10, 64)
- if err != nil || aid <= 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- pn, err := strconv.Atoi(pnStr)
- if err != nil || pn <= 0 {
- pn = 1
- }
- ps, err := strconv.Atoi(psStr)
- if err != nil || ps <= 0 {
- ps = 20
- }
- ip := metadata.String(c, metadata.RemoteIP)
- order := "progress"
- orderStr := params.Get("order")
- if orderStr != order {
- order = "ctime"
- }
- list, err := danmuSvc.List(c, mid, aid, id, pn, ps, order, pool, midStr, ip)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(list, nil)
- }
- func webDmEdit(c *bm.Context) {
- params := c.Request.Form
- idStr := params.Get("cid")
- dmidsStr := params.Get("dmids")
- stateStr := params.Get("state")
- midI, ok := c.Get("mid")
- if !ok {
- c.JSON(nil, ecode.NoLogin)
- return
- }
- mid, _ := midI.(int64)
- id, err := strconv.ParseInt(idStr, 10, 64)
- if err != nil || id <= 0 {
- err = ecode.RequestErr
- return
- }
- state, err := strconv.Atoi(stateStr)
- if err != nil {
- err = ecode.RequestErr
- return
- }
- var dmids []int64
- if dmids, err = xstr.SplitInts(dmidsStr); err != nil {
- c.JSON(nil, ecode.RequestErr)
- log.Error("xstr.SplitInts(dmidsStr %v) err(%v)", dmidsStr, err)
- return
- }
- for _, dmid := range dmids {
- if dmid <= 0 {
- c.JSON(nil, ecode.RequestErr)
- log.Error("dmids range err (dmid %d) err(%v)", dmid, err)
- return
- }
- }
- ip := metadata.String(c, metadata.RemoteIP)
- err = danmuSvc.Edit(c, mid, id, int8(state), dmids, ip)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(nil, nil)
- }
- func webDmDistri(c *bm.Context) {
- midI, ok := c.Get("mid")
- if !ok {
- c.JSON(nil, ecode.NoLogin)
- return
- }
- mid, _ := midI.(int64)
- params := c.Request.Form
- cidStr := params.Get("cid")
- cid, err := strconv.ParseInt(cidStr, 10, 64)
- if err != nil || cid <= 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- aidStr := params.Get("aid")
- aid, err := strconv.ParseInt(aidStr, 10, 64)
- if err != nil || aid <= 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- ip := metadata.String(c, metadata.RemoteIP)
- v, err := arcSvc.Video(c, mid, aid, cid, ip)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- list := make(map[int64]int64)
- if v.From == "vupload" {
- list, err = danmuSvc.Distri(c, mid, cid, ip)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- }
- c.JSON(map[string]interface{}{
- "duration": v.Duration * 1000,
- "type": v.From,
- "list": list,
- }, nil)
- }
- func webDmTransfer(c *bm.Context) {
- params := c.Request.Form
- fromCIDStr := params.Get("from_cid")
- toCIDStr := params.Get("to_cid")
- offsetStr := params.Get("offset")
- offset, err := strconv.ParseFloat(offsetStr, 64)
- if err != nil {
- offset = float64(0)
- }
- midI, ok := c.Get("mid")
- if !ok {
- c.JSON(nil, ecode.NoLogin)
- return
- }
- mid, _ := midI.(int64)
- fromCID, err := strconv.ParseInt(fromCIDStr, 10, 64)
- if err != nil || fromCID <= 0 {
- err = ecode.RequestErr
- return
- }
- toCID, err := strconv.ParseInt(toCIDStr, 10, 64)
- if err != nil || toCID <= 0 {
- err = ecode.RequestErr
- return
- }
- ip := metadata.String(c, metadata.RemoteIP)
- ck := c.Request.Header.Get("cookie")
- ak := params.Get("access_key")
- err = danmuSvc.Transfer(c, mid, fromCID, toCID, offset, ak, ck, ip)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(nil, nil)
- }
- func webDmUpPool(c *bm.Context) {
- params := c.Request.Form
- idStr := params.Get("cid")
- dmidsStr := params.Get("dmids")
- poolStr := params.Get("pool")
- midI, ok := c.Get("mid")
- if !ok {
- c.JSON(nil, ecode.NoLogin)
- return
- }
- mid, _ := midI.(int64)
- id, err := strconv.ParseInt(idStr, 10, 64)
- if err != nil || id <= 0 {
- err = ecode.RequestErr
- return
- }
- pool, err := strconv.Atoi(poolStr)
- if err != nil {
- err = ecode.RequestErr
- return
- }
- var dmids []int64
- if dmids, err = xstr.SplitInts(dmidsStr); err != nil {
- c.JSON(nil, ecode.RequestErr)
- log.Error("xstr.SplitInts(dmidsStr %v) err(%v)", dmidsStr, err)
- return
- }
- for _, dmid := range dmids {
- if dmid <= 0 {
- c.JSON(nil, ecode.RequestErr)
- log.Error("dmids range err (dmid %d) err(%v)", dmid, err)
- return
- }
- }
- ip := metadata.String(c, metadata.RemoteIP)
- err = danmuSvc.UpPool(c, id, dmids, int8(pool), mid, ip)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(nil, nil)
- }
- func webDmReportCheck(c *bm.Context) {
- var err error
- params := c.Request.Form
- cidStr := params.Get("cid")
- cid, err := strconv.ParseInt(cidStr, 10, 64)
- if err != nil {
- err = ecode.RequestErr
- return
- }
- dmidStr := params.Get("dmid")
- dmid, err := strconv.ParseInt(dmidStr, 10, 64)
- if err != nil {
- err = ecode.RequestErr
- return
- }
- opStr := params.Get("op")
- op, err := strconv.ParseInt(opStr, 10, 64)
- if err != nil {
- err = ecode.RequestErr
- return
- }
- midI, ok := c.Get("mid")
- if !ok {
- c.JSON(nil, ecode.NoLogin)
- return
- }
- mid, _ := midI.(int64)
- ip := metadata.String(c, metadata.RemoteIP)
- err = danmuSvc.DmReportCheck(c, mid, cid, dmid, op, ip)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(nil, nil)
- }
- func webDmProtectArchive(c *bm.Context) {
- midI, ok := c.Get("mid")
- if !ok {
- c.JSON(nil, ecode.NoLogin)
- return
- }
- mid, _ := midI.(int64)
- ip := metadata.String(c, metadata.RemoteIP)
- data, err := danmuSvc.DmProtectArchive(c, mid, ip)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(data, nil)
- }
- func webDmProtectList(c *bm.Context) {
- params := c.Request.Form
- midI, ok := c.Get("mid")
- if !ok {
- c.JSON(nil, ecode.NoLogin)
- return
- }
- sortStr := params.Get("sort")
- if sortStr != "playtime" {
- sortStr = "ctime"
- }
- pnStr := params.Get("page")
- pn, err := strconv.ParseInt(pnStr, 10, 64)
- if err != nil || pn <= 0 {
- pn = 1
- }
- aidStr := params.Get("aid")
- mid, _ := midI.(int64)
- ip := metadata.String(c, metadata.RemoteIP)
- vlist, err := danmuSvc.DmProtectList(c, mid, pn, aidStr, sortStr, ip)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(vlist, nil)
- }
- func webDmProtectOper(c *bm.Context) {
- params := c.Request.Form
- statusStr := params.Get("status")
- status, err := strconv.ParseInt(statusStr, 10, 64)
- if err != nil || status != 1 {
- status = 0
- }
- idsStr := params.Get("ids")
- _, err = xstr.SplitInts(idsStr)
- if err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- midI, ok := c.Get("mid")
- if !ok {
- c.JSON(nil, ecode.NoLogin)
- return
- }
- mid, _ := midI.(int64)
- ip := metadata.String(c, metadata.RemoteIP)
- err = danmuSvc.DmProtectOper(c, mid, status, idsStr, ip)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(nil, nil)
- }
- func webDmReport(c *bm.Context) {
- params := c.Request.Form
- midI, ok := c.Get("mid")
- if !ok {
- c.JSON(nil, ecode.NoLogin)
- return
- }
- pnStr := params.Get("pn")
- psStr := params.Get("ps")
- pn, err := strconv.ParseInt(pnStr, 10, 64)
- if err != nil || pn <= 0 {
- pn = 1
- }
- ps, err := strconv.ParseInt(psStr, 10, 64)
- if err != nil || ps <= 0 {
- ps = 20
- }
- aidStr := params.Get("aid")
- mid, _ := midI.(int64)
- ip := metadata.String(c, metadata.RemoteIP)
- data, err := danmuSvc.DmReportList(c, mid, pn, ps, aidStr, ip)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSON(data, nil)
- }
- func webUserMid(c *bm.Context) {
- params := c.Request.Form
- _, ok := c.Get("mid")
- if !ok {
- c.JSON(nil, ecode.NoLogin)
- return
- }
- nameStr := params.Get("name")
- ip := metadata.String(c, metadata.RemoteIP)
- mid, err := danmuSvc.UserMid(c, nameStr, ip)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- c.JSONMap(map[string]interface{}{
- "mid": mid,
- }, nil)
- }
|