123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- package http
- import (
- "strconv"
- "go-common/app/interface/main/playlist/conf"
- "go-common/app/interface/main/playlist/model"
- favmdl "go-common/app/service/main/favorite/model"
- "go-common/library/ecode"
- bm "go-common/library/net/http/blademaster"
- "go-common/library/xstr"
- )
- func videoList(c *bm.Context) {
- var (
- pid int64
- pn, ps int
- err error
- list *model.ArcList
- )
- params := c.Request.Form
- pidStr := params.Get("pid")
- pnStr := params.Get("pn")
- psStr := params.Get("ps")
- if pid, err = strconv.ParseInt(pidStr, 10, 64); err != nil || pid <= 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if pn, err = strconv.Atoi(pnStr); err != nil || pn < 1 {
- pn = 1
- }
- if ps, err = strconv.Atoi(psStr); err != nil || ps < 1 || ps > conf.Conf.Rule.MaxPlArcsPs {
- ps = conf.Conf.Rule.MaxPlArcsPs
- }
- if list, err = plSvc.Videos(c, pid, pn, ps); err != nil {
- c.JSON(nil, switchCode(err, favmdl.TypePlayVideo))
- return
- }
- c.JSON(list, nil)
- }
- func toView(c *bm.Context) {
- var (
- pid, mid int64
- err error
- list *model.ToView
- )
- params := c.Request.Form
- if midStr, ok := c.Get("mid"); ok {
- mid = midStr.(int64)
- }
- pidStr := params.Get("pid")
- if pid, err = strconv.ParseInt(pidStr, 10, 64); err != nil || pid <= 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if list, err = plSvc.ToView(c, mid, pid); err != nil {
- c.JSON(nil, switchCode(err, favmdl.TypePlayVideo))
- return
- }
- c.JSON(list, nil)
- }
- func check(c *bm.Context) {
- var (
- err error
- mid, pid int64
- aids []int64
- videos model.Videos
- )
- params := c.Request.Form
- midStr, _ := c.Get("mid")
- mid = midStr.(int64)
- aidStr := params.Get("aids")
- if aidStr == "" {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if aids, err = xstr.SplitInts(aidStr); err != nil || len(aids) == 0 || len(aids) > conf.Conf.Rule.MaxArcChangeLimit {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- aidMap := make(map[int64]int64, len(aids))
- for _, aid := range aids {
- aidMap[aid] = aid
- }
- if len(aidMap) < len(aids) {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- pidStr := params.Get("pid")
- if pidStr != "" {
- if pid, err = strconv.ParseInt(pidStr, 10, 64); err != nil || pid < 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- }
- if videos, err = plSvc.CheckVideo(c, mid, pid, aids); err != nil {
- c.JSON(nil, switchCode(err, favmdl.TypePlayVideo))
- return
- }
- c.JSON(videos, nil)
- }
- func addVideo(c *bm.Context) {
- var (
- err error
- mid, pid int64
- aids []int64
- videos model.Videos
- )
- params := c.Request.Form
- midStr, _ := c.Get("mid")
- mid = midStr.(int64)
- aidStr := params.Get("aids")
- if aidStr == "" {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if aids, err = xstr.SplitInts(aidStr); err != nil || len(aids) == 0 || len(aids) > conf.Conf.Rule.MaxArcChangeLimit {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- aidMap := make(map[int64]int64, len(aids))
- for _, aid := range aids {
- aidMap[aid] = aid
- }
- if len(aidMap) < len(aids) {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- pidStr := params.Get("pid")
- if pidStr != "" {
- if pid, err = strconv.ParseInt(pidStr, 10, 64); err != nil || pid < 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- }
- if videos, err = plSvc.AddVideo(c, mid, pid, aids); err != nil {
- c.JSON(nil, switchCode(err, favmdl.TypePlayVideo))
- return
- }
- c.JSON(videos, nil)
- }
- func delVideo(c *bm.Context) {
- var (
- err error
- mid, pid int64
- aids []int64
- )
- params := c.Request.Form
- midStr, _ := c.Get("mid")
- mid = midStr.(int64)
- aidStr := params.Get("aids")
- if aidStr == "" {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if aids, err = xstr.SplitInts(aidStr); err != nil || len(aids) == 0 || len(aids) > conf.Conf.Rule.MaxArcChangeLimit {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- aidMap := make(map[int64]int64, len(aids))
- for _, aid := range aids {
- aidMap[aid] = aid
- }
- if len(aidMap) < len(aids) {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- pidStr := params.Get("pid")
- if pidStr != "" {
- if pid, err = strconv.ParseInt(pidStr, 10, 64); err != nil || pid < 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- }
- c.JSON(nil, switchCode(plSvc.DelVideo(c, mid, pid, aids), favmdl.TypePlayVideo))
- }
- func sortVideo(c *bm.Context) {
- var (
- mid, pid, aid, sort int64
- err error
- )
- params := c.Request.Form
- midStr, _ := c.Get("mid")
- mid = midStr.(int64)
- aidStr := params.Get("aid")
- if aid, err = strconv.ParseInt(aidStr, 10, 64); err != nil || aid <= 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- pidStr := params.Get("pid")
- if pid, err = strconv.ParseInt(pidStr, 10, 64); err != nil || pid <= 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- sortStr := params.Get("sort")
- if sort, err = strconv.ParseInt(sortStr, 10, 64); err != nil || sort <= 0 || sort > int64(conf.Conf.Rule.MaxVideoCnt) {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- c.JSON(nil, switchCode(plSvc.SortVideo(c, mid, pid, aid, sort), favmdl.TypePlayVideo))
- }
- func editVideoDesc(c *bm.Context) {
- var (
- err error
- mid, pid, aid int64
- )
- params := c.Request.Form
- midStr, _ := c.Get("mid")
- mid = midStr.(int64)
- pidStr := params.Get("pid")
- if pid, err = strconv.ParseInt(pidStr, 10, 64); err != nil || pid <= 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- aidStr := params.Get("aid")
- if aid, err = strconv.ParseInt(aidStr, 10, 64); err != nil || aid <= 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- desc := params.Get("desc")
- if len([]rune(desc)) > conf.Conf.Rule.MaxVideoDescLimit {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- c.JSON(nil, plSvc.EditVideoDesc(c, mid, pid, aid, desc))
- }
- func searchVideo(c *bm.Context) {
- var (
- err error
- pn, ps, count int
- list []*model.SearchArc
- )
- params := c.Request.Form
- pnStr := params.Get("pn")
- if pn, err = strconv.Atoi(pnStr); err != nil || pn < 1 {
- pn = 1
- }
- psStr := params.Get("ps")
- if ps, err = strconv.Atoi(psStr); err != nil || ps < 1 || ps > conf.Conf.Rule.MaxSearchArcPs {
- ps = conf.Conf.Rule.MaxSearchArcPs
- }
- query := params.Get("keyword")
- if query == "" || len([]rune(query)) > conf.Conf.Rule.MaxSearchLimit {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if list, count, err = plSvc.SearchVideos(c, pn, ps, query); err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- data := make(map[string]interface{}, 2)
- page := map[string]int{
- "num": pn,
- "size": ps,
- "count": count,
- }
- data["page"] = page
- data["list"] = list
- c.JSON(data, nil)
- }
|