123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- package http
- import (
- "encoding/json"
- "io/ioutil"
- "go-common/app/service/main/videoup/model/archive"
- "go-common/library/ecode"
- "go-common/library/log"
- bm "go-common/library/net/http/blademaster"
- )
- // addByPGC add archive info by PGC.
- func addByPGC(c *bm.Context) {
- req := c.Request
- bs, err := ioutil.ReadAll(req.Body)
- if err != nil {
- log.Error("ioutil.ReadAll() error(%v)", err)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- req.Body.Close()
- // params
- var ap = &archive.ArcParam{}
- if err = json.Unmarshal(bs, ap); err != nil {
- log.Error("http addByPGC() json.Unmarshal(%s) error(%v)", string(bs), err)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if ap.Mid == 0 || ap.TypeID == 0 || ap.Copyright == 0 || ap.Title == "" || ap.Tag == "" || ap.Desc == "" || len(ap.Videos) == 0 {
- log.Error("addByPGC func param is empty (%v)", ap)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if ok := vdpSvc.AllowType(c, ap.TypeID); !ok {
- log.Error("typeId (%d) not exist", ap.TypeID)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if ok := archive.InCopyrights(ap.Copyright); !ok {
- log.Error("Copyright (%d) not in (1,2)", ap.Copyright)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- ap.UpFrom = archive.UpFromPGC
- aid, err := vdpSvc.AddByPGC(c, ap)
- if err != nil {
- log.Error("vdpSvc.AddByPGC() error(%v)", err)
- c.JSON(nil, err)
- return
- }
- c.JSON(map[string]int64{
- "aid": aid,
- }, nil)
- }
- // saddByPGC add secret archive info by PGC.
- func saddByPGC(c *bm.Context) {
- req := c.Request
- bs, err := ioutil.ReadAll(req.Body)
- if err != nil {
- log.Error("ioutil.ReadAll() error(%v)", err)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- req.Body.Close()
- // params
- var ap = &archive.ArcParam{}
- if err = json.Unmarshal(bs, ap); err != nil {
- log.Error("http addByPGC() json.Unmarshal(%s) error(%v)", string(bs), err)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if ap.Mid == 0 || ap.TypeID == 0 || ap.Copyright == 0 || ap.Title == "" || ap.Tag == "" || ap.Desc == "" || len(ap.Videos) == 0 {
- log.Error("addByPGC func param is empty (%v)", ap)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if ok := vdpSvc.AllowType(c, ap.TypeID); !ok {
- log.Error("typeId (%d) not exist", ap.TypeID)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if ok := archive.InCopyrights(ap.Copyright); !ok {
- log.Error("Copyright (%d) not in (1,2)", ap.Copyright)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- ap.UpFrom = archive.UpFromSecretPGC
- aid, err := vdpSvc.AddByPGC(c, ap)
- if err != nil {
- log.Error("vdpSvc.AddByPGC() error(%v)", err)
- c.JSON(nil, err)
- return
- }
- c.JSON(map[string]int64{
- "aid": aid,
- }, nil)
- }
- // editByPGC edit archive info by PGC.
- func editByPGC(c *bm.Context) {
- req := c.Request
- bs, err := ioutil.ReadAll(req.Body)
- if err != nil {
- log.Error("ioutil.ReadAll() error(%v)", err)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- req.Body.Close()
- // params
- var ap = &archive.ArcParam{}
- if err = json.Unmarshal(bs, ap); err != nil {
- log.Error("http editByPGC() json.Unmarshal(%s) error(%v)", string(bs), err)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if ap.Aid == 0 || ap.Mid == 0 || ap.TypeID == 0 || ap.Copyright == 0 || ap.Title == "" || ap.Tag == "" || ap.Desc == "" {
- log.Error("editByPGC func param is empty (%v)", ap)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if ok := vdpSvc.AllowType(c, ap.TypeID); !ok {
- log.Error("typeId (%d) not exist", ap.TypeID)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if ok := archive.InCopyrights(ap.Copyright); !ok {
- log.Error("Copyright (%d) not in (1,2)", ap.Copyright)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- ap.UpFrom = archive.UpFromPGC
- c.JSON(nil, vdpSvc.EditByPGC(c, ap))
- }
- // caddByPGC add coopera archive info by PGC.
- func caddByPGC(c *bm.Context) {
- req := c.Request
- bs, err := ioutil.ReadAll(req.Body)
- if err != nil {
- log.Error("ioutil.ReadAll() error(%v)", err)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- req.Body.Close()
- // params
- var ap = &archive.ArcParam{}
- if err = json.Unmarshal(bs, ap); err != nil {
- log.Error("http addByPGC() json.Unmarshal(%s) error(%v)", string(bs), err)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if ap.Mid == 0 || ap.TypeID == 0 || ap.Copyright == 0 || ap.Title == "" || ap.Tag == "" || ap.Desc == "" || len(ap.Videos) == 0 {
- log.Error("addByPGC func param is empty (%v)", ap)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if ok := vdpSvc.AllowType(c, ap.TypeID); !ok {
- log.Error("typeId (%d) not exist", ap.TypeID)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if ok := archive.InCopyrights(ap.Copyright); !ok {
- log.Error("Copyright (%d) not in (1,2)", ap.Copyright)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- ap.UpFrom = archive.UpFromCoopera
- aid, err := vdpSvc.AddByPGC(c, ap)
- if err != nil {
- log.Error("vdpSvc.AddByPGC() error(%v)", err)
- c.JSON(nil, err)
- return
- }
- c.JSON(map[string]int64{
- "aid": aid,
- }, nil)
- }
- // ceditByPGC edit coopera archive info by PGC.
- func ceditByPGC(c *bm.Context) {
- req := c.Request
- bs, err := ioutil.ReadAll(req.Body)
- if err != nil {
- log.Error("ioutil.ReadAll() error(%v)", err)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- req.Body.Close()
- // params
- var ap = &archive.ArcParam{}
- if err = json.Unmarshal(bs, ap); err != nil {
- log.Error("http editByPGC() json.Unmarshal(%s) error(%v)", string(bs), err)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if ap.Aid == 0 || ap.Mid == 0 || ap.TypeID == 0 || ap.Copyright == 0 || ap.Title == "" || ap.Tag == "" || ap.Desc == "" {
- log.Error("editByPGC func param is empty (%v)", ap)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if ok := vdpSvc.AllowType(c, ap.TypeID); !ok {
- log.Error("typeId (%d) not exist", ap.TypeID)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if ok := archive.InCopyrights(ap.Copyright); !ok {
- log.Error("Copyright (%d) not in (1,2)", ap.Copyright)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- ap.UpFrom = archive.UpFromCoopera
- c.JSON(nil, vdpSvc.EditByPGC(c, ap))
- }
|