Create & Init Project...

This commit is contained in:
2019-04-22 18:49:16 +08:00
commit fc4fa37393
25440 changed files with 4054998 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"dataflow.go",
"display.go",
"favorite.go",
"history.go",
"http.go",
"local.go",
"relation.go",
"search.go",
"space.go",
],
importpath = "go-common/app/interface/main/app-interface/http",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/main/app-interface/conf:go_default_library",
"//app/interface/main/app-interface/model:go_default_library",
"//app/interface/main/app-interface/model/favorite:go_default_library",
"//app/interface/main/app-interface/model/history:go_default_library",
"//app/interface/main/app-interface/model/relation:go_default_library",
"//app/interface/main/app-interface/model/search:go_default_library",
"//app/interface/main/app-interface/model/space:go_default_library",
"//app/interface/main/app-interface/service/account:go_default_library",
"//app/interface/main/app-interface/service/dataflow:go_default_library",
"//app/interface/main/app-interface/service/display:go_default_library",
"//app/interface/main/app-interface/service/favorite:go_default_library",
"//app/interface/main/app-interface/service/history:go_default_library",
"//app/interface/main/app-interface/service/relation:go_default_library",
"//app/interface/main/app-interface/service/search:go_default_library",
"//app/interface/main/app-interface/service/space:go_default_library",
"//app/interface/main/history/model:go_default_library",
"//library/ecode:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//library/net/http/blademaster/middleware/auth:go_default_library",
"//library/net/http/blademaster/middleware/proxy:go_default_library",
"//library/net/http/blademaster/middleware/verify:go_default_library",
"//library/queue/databus:go_default_library",
"//library/xstr:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,32 @@
package http
import (
"strconv"
"time"
"go-common/library/ecode"
bm "go-common/library/net/http/blademaster"
)
// reportInfoc infoc
func reportInfoc(c *bm.Context) {
var (
params = c.Request.Form
err error
)
eventID := params.Get("event_id")
eventType := params.Get("event_type")
// header
buvid := params.Get("buvid")
fts := params.Get("fts")
if _, err = strconv.ParseInt(fts, 10, 64); err != nil {
c.JSON(nil, ecode.RequestErr)
return
}
messageInfo := params.Get("message_info")
if eventID == "" || eventType == "" || buvid == "" || messageInfo == "" {
c.JSON(nil, ecode.RequestErr)
return
}
c.JSON(nil, dataflowSvr.Report(c, eventID, eventType, buvid, fts, messageInfo, time.Now()))
}

View File

@@ -0,0 +1,25 @@
package http
import (
"time"
bm "go-common/library/net/http/blademaster"
)
func displayID(c *bm.Context) {
header := c.Request.Header
buvid := header.Get("Buvid")
var mid int64
if midInter, ok := c.Get("mid"); ok {
mid = midInter.(int64)
}
id := displaySvr.DisplayID(c, mid, buvid, time.Now())
c.JSON(struct {
ID string `json:"id"`
}{ID: id}, nil)
}
func zone(c *bm.Context) {
c.JSON(displaySvr.Zone(c, time.Now()), nil)
}

View File

@@ -0,0 +1,228 @@
package http
import (
"strconv"
"go-common/app/interface/main/app-interface/model/favorite"
"go-common/library/ecode"
bm "go-common/library/net/http/blademaster"
)
// folder get folder.
func folder(c *bm.Context) {
var (
aid, vmid, mid int64
build int
err error
)
params := c.Request.Form
accessKey := params.Get("access_key")
actionKey := params.Get("actionKey")
device := params.Get("device")
mobiApp := params.Get("mobi_app")
platform := params.Get("platform")
if build, err = strconv.Atoi(params.Get("build")); err != nil {
c.JSON(nil, ecode.RequestErr)
return
}
aid, _ = strconv.ParseInt(params.Get("aid"), 10, 64)
vmid, _ = strconv.ParseInt(params.Get("vmid"), 10, 64)
if midInter, ok := c.Get("mid"); ok {
mid = midInter.(int64)
}
c.JSON(favSvr.Folder(c, accessKey, actionKey, device, mobiApp, platform, build, aid, vmid, mid))
}
func favoriteVideo(c *bm.Context) {
var (
mid, vmid, fid int64
build, tid int
pn, ps int
err error
)
params := c.Request.Form
accessKey := params.Get("access_key")
actionKey := params.Get("actionKey")
device := params.Get("device")
mobiApp := params.Get("mobi_app")
platform := params.Get("platform")
keyword := params.Get("keyword")
order := params.Get("order")
if build, _ = strconv.Atoi(params.Get("build")); err != nil {
c.JSON(nil, ecode.RequestErr)
return
}
if pn, _ = strconv.Atoi(params.Get("pn")); pn < 1 {
pn = 1
}
if ps, _ = strconv.Atoi(params.Get("ps")); ps < 1 || ps > 20 {
ps = 20
}
tid, _ = strconv.Atoi(params.Get("tid"))
fid, _ = strconv.ParseInt(params.Get("fid"), 10, 64)
vmid, _ = strconv.ParseInt(params.Get("vmid"), 10, 64)
if midInter, ok := c.Get("mid"); ok {
mid = midInter.(int64)
}
c.JSON(favSvr.FolderVideo(c, accessKey, actionKey, device, mobiApp, platform, keyword, order, build, tid, pn, ps, mid, fid, vmid), nil)
}
func topic(c *bm.Context) {
var (
mid int64
build int
pn, ps int
err error
)
params := c.Request.Form
accessKey := params.Get("access_key")
actionKey := params.Get("actionKey")
device := params.Get("device")
mobiApp := params.Get("mobi_app")
platform := params.Get("platform")
if build, err = strconv.Atoi(params.Get("build")); err != nil {
c.JSON(nil, ecode.RequestErr)
return
}
if pn, _ = strconv.Atoi(params.Get("pn")); pn < 1 {
pn = 1
}
if ps, _ = strconv.Atoi(params.Get("ps")); ps < 1 || ps > 20 {
ps = 20
}
if midInter, ok := c.Get("mid"); ok {
mid = midInter.(int64)
}
c.JSON(favSvr.Topic(c, accessKey, actionKey, device, mobiApp, platform, build, ps, pn, mid), nil)
}
func article(c *bm.Context) {
var (
mid int64
pn, ps int
)
params := c.Request.Form
if pn, _ = strconv.Atoi(params.Get("pn")); pn < 1 {
pn = 1
}
if ps, _ = strconv.Atoi(params.Get("ps")); ps < 1 || ps > 20 {
ps = 20
}
if midInter, ok := c.Get("mid"); ok {
mid = midInter.(int64)
}
c.JSON(favSvr.Article(c, mid, pn, ps), nil)
}
func favClips(c *bm.Context) {
var (
mid int64
build int
pn, ps int
err error
)
params := c.Request.Form
accessKey := params.Get("access_key")
actionKey := params.Get("actionKey")
device := params.Get("device")
mobiApp := params.Get("mobi_app")
platform := params.Get("platform")
if build, err = strconv.Atoi(params.Get("build")); err != nil {
c.JSON(nil, ecode.RequestErr)
return
}
if pn, _ = strconv.Atoi(params.Get("pn")); pn < 1 {
pn = 1
}
if ps, _ = strconv.Atoi(params.Get("ps")); ps < 1 || ps > 20 {
ps = 20
}
if midInter, ok := c.Get("mid"); ok {
mid = midInter.(int64)
}
c.JSON(favSvr.Clips(c, mid, accessKey, actionKey, device, mobiApp, platform, build, pn, ps), nil)
}
func favAlbums(c *bm.Context) {
var (
mid int64
build int
pn, ps int
err error
)
params := c.Request.Form
accessKey := params.Get("access_key")
actionKey := params.Get("actionKey")
device := params.Get("device")
mobiApp := params.Get("mobi_app")
platform := params.Get("platform")
if build, err = strconv.Atoi(params.Get("build")); err != nil {
c.JSON(nil, ecode.RequestErr)
return
}
if pn, _ = strconv.Atoi(params.Get("pn")); pn < 1 {
pn = 1
}
if ps, _ = strconv.Atoi(params.Get("ps")); ps < 1 || ps > 20 {
ps = 20
}
if midInter, ok := c.Get("mid"); ok {
mid = midInter.(int64)
}
c.JSON(favSvr.Albums(c, mid, accessKey, actionKey, device, mobiApp, platform, build, pn, ps), nil)
}
func specil(c *bm.Context) {
var (
build int
pn, ps int
err error
)
params := c.Request.Form
accessKey := params.Get("access_key")
actionKey := params.Get("actionKey")
device := params.Get("device")
mobiApp := params.Get("mobi_app")
platform := params.Get("platform")
if build, err = strconv.Atoi(params.Get("build")); err != nil {
c.JSON(nil, ecode.RequestErr)
return
}
if pn, _ = strconv.Atoi(params.Get("pn")); pn < 1 {
pn = 1
}
if ps, _ = strconv.Atoi(params.Get("ps")); ps < 1 || ps > 20 {
ps = 20
}
c.JSON(favSvr.Specil(c, accessKey, actionKey, device, mobiApp, platform, build, pn, ps), nil)
}
func audio(c *bm.Context) {
var (
mid int64
pn, ps int
)
params := c.Request.Form
accessKey := params.Get("access_key")
if pn, _ = strconv.Atoi(params.Get("pn")); pn < 1 {
pn = 1
}
if ps, _ = strconv.Atoi(params.Get("ps")); ps < 1 || ps > 20 {
ps = 20
}
if midInter, ok := c.Get("mid"); ok {
mid = midInter.(int64)
}
c.JSON(favSvr.Audio(c, accessKey, mid, pn, ps), nil)
}
func tab(c *bm.Context) {
param := &favorite.TabParam{}
if err := c.Bind(param); err != nil {
return
}
if midInter, ok := c.Get("mid"); ok {
param.Mid = midInter.(int64)
}
c.JSON(favSvr.Tab(c, param.AccessKey, param.ActionKey, param.Device, param.MobiApp, param.Platform, param.Filtered, param.Build, param.Mid))
}

View File

@@ -0,0 +1,147 @@
package http
import (
"strconv"
"strings"
"go-common/app/interface/main/app-interface/model"
"go-common/app/interface/main/app-interface/model/history"
hismodle "go-common/app/interface/main/history/model"
"go-common/library/ecode"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
"go-common/library/xstr"
)
var (
busMap = map[string][]string{
"": {},
"all": {},
"archive": {"archive", "pgc"},
"article": {"article", "article-list"},
"live": {"live"},
}
)
//history list
func historyList(c *bm.Context) {
param := &history.HisParam{}
if err := c.Bind(param); err != nil {
return
}
if param.Pn < 1 {
param.Pn = 1
}
if param.Ps > 20 || param.Ps <= 0 {
param.Ps = 20
}
if midInter, ok := c.Get("mid"); ok {
param.Mid = midInter.(int64)
}
plat := model.Plat(param.MobiApp, param.Device)
c.JSON(historySvr.List(c, param.Mid, param.Build, param.Pn, param.Ps, param.Platform, plat))
}
// shortAll get shorturl list
func live(c *bm.Context) {
param := &history.LiveParam{}
if err := c.Bind(param); err != nil {
return
}
roomIDs, err := xstr.SplitInts(param.RoomIDs)
if err != nil {
c.JSON(nil, ecode.RequestErr)
return
}
c.JSON(historySvr.Live(c, roomIDs))
}
//history list
func liveList(c *bm.Context) {
param := &history.HisParam{}
if err := c.Bind(param); err != nil {
return
}
if param.Pn < 1 {
param.Pn = 1
}
if param.Ps > 20 || param.Ps <= 0 {
param.Ps = 20
}
if midInter, ok := c.Get("mid"); ok {
param.Mid = midInter.(int64)
}
plat := model.Plat(param.MobiApp, param.Device)
c.JSON(historySvr.LiveList(c, param.Mid, param.Build, param.Pn, param.Ps, param.Platform, plat))
}
//history cursor
func historyCursor(c *bm.Context) {
param := &history.HisParam{}
if err := c.Bind(param); err != nil {
return
}
if param.Ps > 20 || param.Ps <= 0 {
param.Ps = 20
}
if midInter, ok := c.Get("mid"); ok {
param.Mid = midInter.(int64)
}
businesses, ok := busMap[param.Business]
if !ok {
log.Error("historyCursor invalid business(%s)", param.Business)
c.JSON(nil, ecode.RequestErr)
return
}
plat := model.Plat(param.MobiApp, param.Device)
c.JSON(historySvr.Cursor(c, param.Mid, param.Build, param.Max, param.Ps, param.Platform, param.MaxTP, plat, businesses))
}
//history del
func historyDel(c *bm.Context) {
param := &history.DelParam{}
if err := c.Bind(param); err != nil {
return
}
if midInter, ok := c.Get("mid"); ok {
param.Mid = midInter.(int64)
}
var hisRes []*hismodle.Resource
for _, boid := range param.Boids {
bo := strings.Split(boid, "_")
if len(bo) != 2 {
log.Error("historyDel invalid param(%+v)", param)
c.JSON(nil, ecode.RequestErr)
return
}
oid, _ := strconv.ParseInt(bo[1], 10, 0)
if oid == 0 {
log.Error("historyDel invalid param(%+v)", param)
c.JSON(nil, ecode.RequestErr)
return
}
hisRes = append(hisRes, &hismodle.Resource{
Oid: oid,
Business: bo[0],
})
}
c.JSON(nil, historySvr.Del(c, param.Mid, hisRes))
}
//history clear
func historyClear(c *bm.Context) {
param := &history.HisParam{}
if err := c.Bind(param); err != nil {
return
}
if midInter, ok := c.Get("mid"); ok {
param.Mid = midInter.(int64)
}
businesses, ok := busMap[param.Business]
if !ok {
log.Error("historyCursor invalid business(%s)", param.Business)
c.JSON(nil, ecode.RequestErr)
return
}
c.JSON(nil, historySvr.Clear(c, param.Mid, businesses))
}

View File

@@ -0,0 +1,133 @@
package http
import (
"go-common/app/interface/main/app-interface/conf"
acc "go-common/app/interface/main/app-interface/service/account"
"go-common/app/interface/main/app-interface/service/dataflow"
"go-common/app/interface/main/app-interface/service/display"
"go-common/app/interface/main/app-interface/service/favorite"
"go-common/app/interface/main/app-interface/service/history"
"go-common/app/interface/main/app-interface/service/relation"
"go-common/app/interface/main/app-interface/service/search"
"go-common/app/interface/main/app-interface/service/space"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
"go-common/library/net/http/blademaster/middleware/auth"
"go-common/library/net/http/blademaster/middleware/proxy"
"go-common/library/net/http/blademaster/middleware/verify"
"go-common/library/queue/databus"
)
var (
verifySvc *verify.Verify
authSvc *auth.Auth
spaceSvr *space.Service
srcSvr *search.Service
displaySvr *display.Service
favSvr *favorite.Service
accSvr *acc.Service
relSvr *relation.Service
historySvr *history.Service
dataflowSvr *dataflow.Service
// databus
userActPub *databus.Databus
config *conf.Config
)
// Init init http
func Init(c *conf.Config) {
initService(c)
// init external router
engineOut := bm.DefaultServer(c.BM.Outer)
// init outer router
outerRouter(engineOut)
if err := engineOut.Start(); err != nil {
log.Error("engineOut.Start() error(%v) | config(%v)", err, c)
panic(err)
}
}
func initService(c *conf.Config) {
verifySvc = verify.New(nil)
authSvc = auth.New(nil)
spaceSvr = space.New(c)
srcSvr = search.New(c)
displaySvr = display.New(c)
favSvr = favorite.New(c)
accSvr = acc.New(c)
relSvr = relation.New(c)
historySvr = history.New(c)
dataflowSvr = dataflow.New(c)
userActPub = databus.New(c.UseractPub)
config = c
}
func outerRouter(e *bm.Engine) {
e.Ping(ping)
proxyHandler := proxy.NewZoneProxy("sh004", "http://sh001-app.bilibili.com")
account := e.Group("/x/v2/account", verifySvc.Verify)
account.GET("/myinfo", myinfo)
account.GET("/mine", authSvc.GuestMobile, mine)
account.GET("/mine/ipad", authSvc.GuestMobile, mineIpad)
space := e.Group("/x/v2/space")
space.GET("", authSvc.GuestMobile, spaceAll)
space.GET("/archive", authSvc.GuestMobile, upArchive)
space.GET("/article", authSvc.GuestMobile, upArticle)
space.GET("/bangumi", authSvc.GuestMobile, bangumi)
space.GET("/coinarc", authSvc.GuestMobile, coinArc)
space.GET("/likearc", authSvc.GuestMobile, likeArc)
space.GET("/community", authSvc.GuestMobile, community)
space.GET("/contribute", proxyHandler, authSvc.GuestMobile, contribute)
space.GET("/contribute/cursor", proxyHandler, authSvc.GuestMobile, contribution)
space.GET("/clips", authSvc.GuestMobile, clips)
space.GET("/albums", authSvc.GuestMobile, albums)
space.POST("/report", verifySvc.Verify, report)
space.POST("/upContribute", proxyHandler, verifySvc.Verify, upContribute)
search := e.Group("/x/v2/search")
search.GET("", authSvc.GuestMobile, searchAll)
search.GET("/type", authSvc.GuestMobile, searchByType)
search.GET("/episodes", authSvc.GuestMobile, searchEpisodes)
search.GET("/live", authSvc.GuestMobile, searchLive)
search.GET("/hot", authSvc.GuestMobile, hotSearch)
search.GET("/suggest", authSvc.GuestMobile, suggest)
search.GET("/suggest2", authSvc.GuestMobile, suggest2)
search.GET("/suggest3", authSvc.GuestMobile, suggest3)
search.GET("/defaultwords", authSvc.GuestMobile, defaultWords)
search.GET("/user", authSvc.GuestMobile, searchUser)
search.GET("/recommend", authSvc.GuestMobile, recommend)
search.GET("/recommend/noresult", authSvc.GuestMobile, recommendNoResult)
search.GET("/recommend/pre", authSvc.GuestMobile, recommendPre)
search.GET("/resource", authSvc.GuestMobile, resource)
display := e.Group("/x/v2/display", verifySvc.Verify)
display.GET("/zone", zone)
display.GET("/id", authSvc.GuestMobile, displayID)
favorite := e.Group("/x/v2/favorite", verifySvc.Verify)
favorite.GET("", authSvc.GuestMobile, folder)
favorite.GET("/video", authSvc.GuestMobile, favoriteVideo)
favorite.GET("/topic", authSvc.GuestMobile, topic)
favorite.GET("/article", authSvc.GuestMobile, article)
favorite.GET("/clips", authSvc.GuestMobile, favClips)
favorite.GET("/albums", authSvc.GuestMobile, favAlbums)
favorite.GET("/sp", specil)
favorite.GET("/audio", authSvc.GuestMobile, audio)
favorite.GET("/tab", authSvc.UserMobile, tab)
relation := e.Group("/x/v2/relation")
relation.GET("/followings", authSvc.GuestMobile, followings)
relation.GET("/tag", authSvc.UserMobile, tag)
history := e.Group("/x/v2/history", verifySvc.Verify)
history.GET("", authSvc.UserMobile, historyList)
history.GET("/live", live)
history.GET("/liveList", authSvc.UserMobile, liveList)
history.GET("/cursor", authSvc.UserMobile, historyCursor)
history.POST("/del", authSvc.UserMobile, historyDel)
history.POST("/clear", authSvc.UserMobile, historyClear)
dataflow := e.Group("/x/v2/dataflow")
dataflow.POST("/report", reportInfoc)
}

View File

@@ -0,0 +1,16 @@
package http
import (
"net/http"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
)
// ping check server ok.
func ping(c *bm.Context) {
if err := spaceSvr.Ping(c); err != nil {
log.Error("app-interface service ping error(%+v)", err)
c.AbortWithStatus(http.StatusServiceUnavailable)
}
}

View File

@@ -0,0 +1,79 @@
package http
import (
"strconv"
model "go-common/app/interface/main/app-interface/model/relation"
"go-common/library/ecode"
bm "go-common/library/net/http/blademaster"
)
// followings get user's following list.
func followings(c *bm.Context) {
var (
mid, vmid int64
pn, ps int
version uint64
self bool
err error
)
params := c.Request.Form
midInter, ok := c.Get("mid")
if ok {
mid = midInter.(int64)
}
versionStr := params.Get("re_version")
order := params.Get("order")
if vmid, err = strconv.ParseInt(params.Get("vmid"), 10, 64); err != nil || vmid < 1 {
c.JSON(nil, ecode.RequestErr)
return
}
self = mid == vmid
if pn, _ = strconv.Atoi(params.Get("pn")); pn < 1 {
pn = 1
}
if !self && pn > 5 {
c.JSON(nil, ecode.RelFollowingGuestLimit)
return
}
if ps, _ = strconv.Atoi(params.Get("ps")); ps < 1 || ps > 50 {
ps = 50
}
if versionStr != "" {
if version, err = strconv.ParseUint(versionStr, 10, 64); err != nil {
c.JSON(nil, ecode.RequestErr)
return
}
}
if order != "asc" {
order = "desc"
}
followings, crc32v, total, err := relSvr.Followings(c, vmid, mid, pn, ps, version, order)
c.JSON(struct {
List []*model.Following `json:"list"`
ReVersion uint32 `json:"re_version"`
Total int `json:"total"`
}{followings, crc32v, total}, err)
}
func tag(c *bm.Context) {
var (
mid, tid int64
pn, ps int
err error
)
params := c.Request.Form
midInter, _ := c.Get("mid")
mid = midInter.(int64)
if tid, err = strconv.ParseInt(params.Get("tagid"), 10, 64); err != nil {
c.JSON(nil, ecode.RequestErr)
return
}
if pn, _ = strconv.Atoi(params.Get("pn")); pn < 1 {
pn = 1
}
if ps, _ = strconv.Atoi(params.Get("ps")); ps < 1 || ps > 50 {
ps = 50
}
c.JSON(relSvr.Tag(c, mid, tid, pn, ps))
}

View File

@@ -0,0 +1,526 @@
package http
import (
"strconv"
"time"
"go-common/app/interface/main/app-interface/model"
"go-common/app/interface/main/app-interface/model/search"
"go-common/library/ecode"
bm "go-common/library/net/http/blademaster"
)
const (
_headerBuvid = "Buvid"
_keyWordLen = 50
)
func searchAll(c *bm.Context) {
var (
build int
mid int64
pn, ps int
err error
)
params := c.Request.Form
header := c.Request.Header
// params
mobiApp := params.Get("mobi_app")
device := params.Get("device")
ridStr := params.Get("rid")
keyword := params.Get("keyword")
highlightStr := params.Get("highlight")
lang := params.Get("lang")
duration := params.Get("duration")
order := params.Get("order")
filtered := params.Get("filtered")
platform := params.Get("platform")
zoneidStr := params.Get("zoneid")
fromSource := params.Get("from_source")
recommend := params.Get("recommend")
parent := params.Get("parent_mode")
// header
buvid := header.Get("Buvid")
// check params
if keyword == "" || len([]rune(keyword)) > _keyWordLen {
c.JSON(nil, ecode.RequestErr)
return
}
if build, err = strconv.Atoi(params.Get("build")); err != nil {
c.JSON(nil, ecode.RequestErr)
return
}
zoneid, _ := strconv.ParseInt(zoneidStr, 10, 64)
rid, _ := strconv.Atoi(ridStr)
highlight, _ := strconv.Atoi(highlightStr)
// page and size
if pn, _ = strconv.Atoi(params.Get("pn")); pn < 1 {
pn = 1
}
if ps, _ = strconv.Atoi(params.Get("ps")); ps < 1 || ps > 20 {
ps = 20
}
if midInter, ok := c.Get("mid"); ok {
mid = midInter.(int64)
}
switch order {
case "default", "":
order = "totalrank"
case "view":
order = "click"
case "danmaku":
order = "dm"
}
if duration == "" {
duration = "0"
}
if recommend == "" || recommend != "1" {
recommend = "0"
}
isQuery, _ := strconv.Atoi(params.Get("is_org_query"))
plat := model.Plat(mobiApp, device)
c.JSON(srcSvr.Search(c, mid, zoneid, mobiApp, device, platform, buvid, keyword, duration, order, filtered, lang, fromSource, recommend, parent, plat, rid, highlight, build, pn, ps, isQuery, checkOld(plat, build), time.Now()))
}
func searchByType(c *bm.Context) {
var (
build int
mid int64
pn, ps int
typeV string
err error
)
params := c.Request.Form
header := c.Request.Header
// params
mobiApp := params.Get("mobi_app")
device := params.Get("device")
sType := params.Get("type")
keyword := params.Get("keyword")
filtered := params.Get("filtered")
zoneidStr := params.Get("zoneid")
order := params.Get("order")
platform := params.Get("platform")
highlightStr := params.Get("highlight")
categoryIDStr := params.Get("category_id")
userTypeStr := params.Get("user_type")
orderSortStr := params.Get("order_sort")
// header
buvid := header.Get("Buvid")
if keyword == "" || len([]rune(keyword)) > _keyWordLen {
c.JSON(nil, ecode.RequestErr)
return
}
if build, err = strconv.Atoi(params.Get("build")); err != nil {
c.JSON(nil, ecode.RequestErr)
return
}
userType, _ := strconv.Atoi(userTypeStr)
orderSort, _ := strconv.Atoi(orderSortStr)
zoneid, _ := strconv.ParseInt(zoneidStr, 10, 64)
categoryID, _ := strconv.Atoi(categoryIDStr)
highlight, _ := strconv.Atoi(highlightStr)
// page and size
if pn, _ = strconv.Atoi(params.Get("pn")); pn < 1 {
pn = 1
}
if ps, _ = strconv.Atoi(params.Get("ps")); ps < 1 || ps > 20 {
ps = 20
}
if midInter, ok := c.Get("mid"); ok {
mid = midInter.(int64)
}
switch sType {
case "1":
typeV = "season"
case "2":
typeV = "upper"
case "3":
typeV = "movie"
case "4":
typeV = "live_room"
case "5":
typeV = "live_user"
case "6":
typeV = "article"
case "7":
typeV = "season2"
case "8":
typeV = "movie2"
case "9":
typeV = "tag"
case "10":
typeV = "video"
}
plat := model.Plat(mobiApp, device)
c.JSON(srcSvr.SearchByType(c, mid, zoneid, mobiApp, device, platform, buvid, typeV, keyword, filtered, order, plat, build, highlight, categoryID, userType, orderSort, pn, ps, checkOld(plat, build), time.Now()))
}
func searchLive(c *bm.Context) {
var (
build int
mid int64
pn, ps int
typeV string
err error
)
params := c.Request.Form
header := c.Request.Header
// params
mobiApp := params.Get("mobi_app")
device := params.Get("device")
sType := params.Get("type")
keyword := params.Get("keyword")
order := params.Get("order")
platform := params.Get("platform")
// header
buvid := header.Get("Buvid")
if keyword == "" || len([]rune(keyword)) > _keyWordLen {
c.JSON(nil, ecode.RequestErr)
return
}
if build, err = strconv.Atoi(params.Get("build")); err != nil {
c.JSON(nil, ecode.RequestErr)
return
}
// page and size
if pn, _ = strconv.Atoi(params.Get("pn")); pn < 1 {
pn = 1
}
if ps, _ = strconv.Atoi(params.Get("ps")); ps < 1 || ps > 20 {
ps = 20
}
if midInter, ok := c.Get("mid"); ok {
mid = midInter.(int64)
}
plat := model.Plat(mobiApp, device)
switch sType {
case "4":
if (model.IsAndroid(plat) && build > search.SearchLiveAllAndroid) || (model.IsIPhone(plat) && build > search.SearchLiveAllIOS) || model.IsIPad(plat) || model.IsIPhoneB(plat) {
typeV = "live_all"
} else {
typeV = "live_room"
}
case "5":
typeV = "live_user"
}
if typeV == "live_all" {
c.JSON(srcSvr.SearchLiveAll(c, mid, mobiApp, platform, buvid, device, typeV, keyword, order, build, pn, ps))
} else {
c.JSON(srcSvr.SearchLive(c, mid, mobiApp, platform, buvid, device, typeV, keyword, order, build, pn, ps))
}
}
// ip string, limit int
func hotSearch(c *bm.Context) {
var (
mid int64
build int
limit int
err error
)
params := c.Request.Form
header := c.Request.Header
if midInter, ok := c.Get("mid"); ok {
mid = midInter.(int64)
}
mobiApp := params.Get("mobi_app")
device := params.Get("device")
platform := params.Get("platform")
buvid := header.Get("Buvid")
if build, err = strconv.Atoi(params.Get("build")); err != nil {
c.JSON(nil, ecode.RequestErr)
return
}
if limit, err = strconv.Atoi(params.Get("limit")); err != nil {
c.JSON(nil, ecode.RequestErr)
return
}
c.JSON(srcSvr.HotSearch(c, buvid, mid, build, limit, mobiApp, device, platform, time.Now()), nil)
}
// suggest search suggest data.
func suggest(c *bm.Context) {
var (
build int
mid int64
err error
)
params := c.Request.Form
header := c.Request.Header
mobiApp := params.Get("mobi_app")
device := params.Get("device")
term := params.Get("keyword")
if midInter, ok := c.Get("mid"); ok {
mid = midInter.(int64)
}
if build, err = strconv.Atoi(params.Get("build")); err != nil {
c.JSON(nil, ecode.RequestErr)
return
}
buvid := header.Get(_headerBuvid)
c.JSON(srcSvr.Suggest(c, mid, buvid, term, build, mobiApp, device, time.Now()), nil)
}
// suggest2 search suggest data from new api.
func suggest2(c *bm.Context) {
var (
build int
mid int64
err error
)
params := c.Request.Form
header := c.Request.Header
mobiApp := params.Get("mobi_app")
term := params.Get("keyword")
if midInter, ok := c.Get("mid"); ok {
mid = midInter.(int64)
}
if build, err = strconv.Atoi(params.Get("build")); err != nil {
c.JSON(nil, ecode.RequestErr)
return
}
buvid := header.Get(_headerBuvid)
platform := params.Get("platform")
c.JSON(srcSvr.Suggest2(c, mid, platform, buvid, term, build, mobiApp, time.Now()), nil)
}
// suggest3 search suggest data from newest api.
func suggest3(c *bm.Context) {
var (
build int
mid int64
err error
)
params := c.Request.Form
header := c.Request.Header
mobiApp := params.Get("mobi_app")
term := params.Get("keyword")
device := params.Get("device")
highlight, _ := strconv.Atoi(params.Get("highlight"))
if midInter, ok := c.Get("mid"); ok {
mid = midInter.(int64)
}
if build, err = strconv.Atoi(params.Get("build")); err != nil {
c.JSON(nil, ecode.RequestErr)
return
}
buvid := header.Get(_headerBuvid)
platform := params.Get("platform")
c.JSON(srcSvr.Suggest3(c, mid, platform, buvid, term, device, build, highlight, mobiApp, time.Now()), nil)
}
func checkOld(plat int8, build int) bool {
const (
_oldAndroid = 513000
_oldIphone = 6060
)
return (model.IsIPhone(plat) && build <= _oldIphone) || (model.IsAndroid(plat) && build <= _oldAndroid)
}
func searchUser(c *bm.Context) {
var (
build int
mid int64
err error
)
params := c.Request.Form
header := c.Request.Header
mobiApp := params.Get("mobi_app")
device := params.Get("device")
platform := params.Get("platform")
keyword := params.Get("keyword")
filtered := params.Get("filtered")
order := params.Get("order")
fromSource := params.Get("from_source")
if midInter, ok := c.Get("mid"); ok {
mid = midInter.(int64)
}
if build, err = strconv.Atoi(params.Get("build")); err != nil {
c.JSON(nil, ecode.RequestErr)
return
}
userType, _ := strconv.Atoi(params.Get("user_type"))
highlight, _ := strconv.Atoi(params.Get("highlight"))
if order == "" {
order = "totalrank"
}
if order != "totalrank" && order != "fans" && order != "level" {
c.JSON(nil, ecode.RequestErr)
return
}
orderSort, _ := strconv.Atoi(params.Get("order_sort"))
if orderSort != 1 {
orderSort = 0
}
if fromSource == "" {
fromSource = "dynamic_uname"
}
if fromSource != "dynamic_uname" {
c.JSON(nil, ecode.RequestErr)
return
}
pn, _ := strconv.Atoi(params.Get("pn"))
if pn < 1 {
pn = 1
}
ps, _ := strconv.Atoi(params.Get("ps"))
if ps < 1 || ps > 20 {
ps = 20
}
buvid := header.Get(_headerBuvid)
c.JSON(srcSvr.User(c, mid, buvid, mobiApp, device, platform, keyword, filtered, order, fromSource, highlight, build, userType, orderSort, pn, ps, time.Now()), nil)
}
func recommend(c *bm.Context) {
var (
build int
mid int64
err error
)
params := c.Request.Form
header := c.Request.Header
if midInter, ok := c.Get("mid"); ok {
mid = midInter.(int64)
}
platform := params.Get("platform")
mobiApp := params.Get("mobi_app")
device := params.Get("device")
if build, err = strconv.Atoi(params.Get("build")); err != nil {
c.JSON(nil, ecode.RequestErr)
return
}
from, _ := strconv.Atoi(params.Get("from"))
show, _ := strconv.Atoi(params.Get("show"))
buvid := header.Get("Buvid")
c.JSON(srcSvr.Recommend(c, mid, build, from, show, buvid, platform, mobiApp, device))
}
func defaultWords(c *bm.Context) {
var (
build int
mid int64
err error
)
params := c.Request.Form
header := c.Request.Header
if midInter, ok := c.Get("mid"); ok {
mid = midInter.(int64)
}
platform := params.Get("platform")
mobiApp := params.Get("mobi_app")
device := params.Get("device")
if build, err = strconv.Atoi(params.Get("build")); err != nil {
c.JSON(nil, ecode.RequestErr)
return
}
from, _ := strconv.Atoi(params.Get("from"))
buvid := header.Get("Buvid")
c.JSON(srcSvr.DefaultWords(c, mid, build, from, buvid, platform, mobiApp, device))
}
func recommendNoResult(c *bm.Context) {
var (
params = c.Request.Form
header = c.Request.Header
build int
mid int64
err error
)
platform := params.Get("platform")
mobiApp := params.Get("mobi_app")
device := params.Get("device")
if build, err = strconv.Atoi(params.Get("build")); err != nil {
c.JSON(nil, ecode.RequestErr)
return
}
if midInter, ok := c.Get("mid"); ok {
mid = midInter.(int64)
}
buvid := header.Get("Buvid")
keyword := params.Get("keyword")
if keyword == "" {
c.JSON(nil, ecode.RequestErr)
return
}
pn, _ := strconv.Atoi(params.Get("pn"))
if pn < 1 {
pn = 1
}
ps, _ := strconv.Atoi(params.Get("ps"))
if ps < 1 || ps > 20 {
ps = 20
}
c.JSON(srcSvr.RecommendNoResult(c, platform, mobiApp, device, buvid, keyword, build, pn, ps, mid))
}
func resource(c *bm.Context) {
var (
params = c.Request.Form
header = c.Request.Header
build int
mid int64
err error
)
mobiApp := params.Get("mobi_app")
device := params.Get("device")
network := params.Get("network")
buvid := header.Get("Buvid")
adExtra := params.Get("ad_extra")
if build, err = strconv.Atoi(params.Get("build")); err != nil {
c.JSON(nil, ecode.RequestErr)
return
}
plat := model.Plat(mobiApp, device)
if midInter, ok := c.Get("mid"); ok {
mid = midInter.(int64)
}
c.JSON(srcSvr.Resource(c, mobiApp, device, network, buvid, adExtra, build, plat, mid))
}
func recommendPre(c *bm.Context) {
var (
params = c.Request.Form
header = c.Request.Header
build int
mid int64
err error
)
platform := params.Get("platform")
mobiApp := params.Get("mobi_app")
device := params.Get("device")
if build, err = strconv.Atoi(params.Get("build")); err != nil {
c.JSON(nil, ecode.RequestErr)
return
}
if midInter, ok := c.Get("mid"); ok {
mid = midInter.(int64)
}
buvid := header.Get("Buvid")
ps, _ := strconv.Atoi(params.Get("ps"))
if ps < 1 || ps > 20 {
ps = 20
}
c.JSON(srcSvr.RecommendPre(c, platform, mobiApp, device, buvid, build, ps, mid))
}
func searchEpisodes(c *bm.Context) {
var (
params = c.Request.Form
mid, ssID int64
err error
)
if ssID, err = strconv.ParseInt(params.Get("season_id"), 10, 64); err != nil {
c.JSON(nil, ecode.RequestErr)
return
}
if midInter, ok := c.Get("mid"); ok {
mid = midInter.(int64)
}
if ssID == 0 {
c.JSON(nil, ecode.RequestErr)
return
}
c.JSON(srcSvr.SearchEpisodes(c, mid, ssID))
}

View File

@@ -0,0 +1,452 @@
package http
import (
"context"
"encoding/json"
"strconv"
"time"
"go-common/app/interface/main/app-interface/model"
"go-common/app/interface/main/app-interface/model/space"
"go-common/library/ecode"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
)
const (
_crop = "@750w_250h_1c"
)
type userAct struct {
Client string `json:"client"`
Buvid string `json:"buvid"`
Mid int64 `json:"mid"`
Time int64 `json:"time"`
From string `json:"from"`
Build string `json:"build"`
ItemID string `json:"item_id"`
ItemType string `json:"item_type"`
Action string `json:"action"`
ActionID string `json:"action_id"`
Extra string `json:"extra"`
}
func spaceAll(c *bm.Context) {
var (
mid int64
vmid int64
build int
pn, ps int
err error
)
params := c.Request.Form
mobiApp := params.Get("mobi_app")
platform := params.Get("platform")
device := params.Get("device")
buildStr := params.Get("build")
name := params.Get("name")
// check params
if vmid, _ = strconv.ParseInt(params.Get("vmid"), 10, 64); vmid < 1 && name == "" {
c.JSON(nil, ecode.RequestErr)
return
}
if midInt, ok := c.Get("mid"); ok {
mid = midInt.(int64)
}
if build, err = strconv.Atoi(buildStr); err != nil {
c.JSON(nil, ecode.RequestErr)
return
}
if pn, _ = strconv.Atoi(params.Get("pn")); pn < 1 {
pn = 1
}
if ps, _ = strconv.Atoi(params.Get("ps")); ps < 1 || ps > 20 {
ps = 20
}
plat := model.Plat(mobiApp, device)
space, err := spaceSvr.Space(c, mid, vmid, plat, build, pn, ps, platform, device, mobiApp, name, time.Now())
if err != nil {
c.JSON(nil, err)
return
}
if model.IsIPhone(plat) && space.Space != nil && space.Space.ImgURL != "" {
space.Space.ImgURL = space.Space.ImgURL + _crop
}
space.Relation = compRealtion(space.Relation, mobiApp, build, device)
c.JSON(space, nil)
// for ai big data
userActPub.Send(context.TODO(), strconv.FormatInt(mid, 10), &userAct{
Client: mobiApp,
Buvid: c.Request.Header.Get("Buvid"),
Mid: mid,
Time: time.Now().Unix(),
From: params.Get("from"),
Build: buildStr,
ItemID: space.Card.Mid,
ItemType: "mid",
Action: "space",
})
}
func upArchive(c *bm.Context) {
var (
pn, ps int
)
params := c.Request.Form
// check params
vmid, _ := strconv.ParseInt(params.Get("vmid"), 10, 64)
if vmid < 1 {
c.JSON(nil, ecode.RequestErr)
return
}
if pn, _ = strconv.Atoi(params.Get("pn")); pn < 1 {
pn = 1
}
if ps, _ = strconv.Atoi(params.Get("ps")); ps < 1 || ps > 20 {
ps = 20
}
c.JSON(spaceSvr.UpArcs(c, vmid, pn, ps, time.Now()), nil)
}
func myinfo(c *bm.Context) {
mid, err := authSvc.AuthToken(c)
if err != nil {
shouldChangeError := false
params := c.Request.Form
mobiApp := params.Get("mobi_app")
device := params.Get("device")
build, _ := strconv.Atoi(params.Get("build"))
plat := model.Plat(mobiApp, device)
if model.IsIPhone(plat) && build > config.LoginBuild.Iphone {
shouldChangeError = true
}
if shouldChangeError && ecode.Cause(err).Equal(ecode.NoLogin) {
c.JSON(nil, ecode.UserLoginInvalid)
return
}
c.JSON(nil, err)
return
}
c.JSON(accSvr.Myinfo(c, mid))
}
func mine(c *bm.Context) {
params := &space.MineParam{}
if err := c.Bind(params); err != nil {
return
}
if midInter, ok := c.Get("mid"); ok {
params.Mid = midInter.(int64)
}
plat := model.Plat(params.MobiApp, params.Device)
c.JSON(accSvr.Mine(c, params.Mid, params.Platform, params.Filtered, params.Build, plat))
}
func mineIpad(c *bm.Context) {
params := &space.MineParam{}
if err := c.Bind(params); err != nil {
return
}
if midInter, ok := c.Get("mid"); ok {
params.Mid = midInter.(int64)
}
plat := model.Plat(params.MobiApp, params.Device)
if model.IsIPad(plat) {
plat = model.PlatIPad
}
c.JSON(accSvr.MineIpad(c, params.Mid, params.Platform, params.Filtered, params.Build, plat))
}
func upArticle(c *bm.Context) {
var (
pn, ps int
)
params := c.Request.Form
// check params
vmid, _ := strconv.ParseInt(params.Get("vmid"), 10, 64)
if vmid < 1 {
c.JSON(nil, ecode.RequestErr)
return
}
if pn, _ = strconv.Atoi(params.Get("pn")); pn < 1 {
pn = 1
}
if ps, _ = strconv.Atoi(params.Get("ps")); ps < 1 || ps > 20 {
ps = 20
}
c.JSON(spaceSvr.UpArticles(c, vmid, pn, ps), nil)
}
func contribute(c *bm.Context) {
var (
vmid int64
build int
pn, ps int
err error
)
params := c.Request.Form
mobiApp := params.Get("mobi_app")
device := params.Get("device")
// check params
if build, err = strconv.Atoi(params.Get("build")); err != nil {
c.JSON(nil, ecode.RequestErr)
return
}
if vmid, _ = strconv.ParseInt(params.Get("vmid"), 10, 64); vmid < 1 {
c.JSON(nil, ecode.RequestErr)
return
}
if pn, _ = strconv.Atoi(params.Get("pn")); pn < 1 {
pn = 1
}
if ps, _ = strconv.Atoi(params.Get("ps")); ps < 1 || ps > 20 {
ps = 20
}
plat := model.Plat(mobiApp, device)
c.JSON(spaceSvr.Contribute(c, plat, build, vmid, pn, ps, time.Now()))
}
func contribution(c *bm.Context) {
var (
vmid int64
build int
maxID, minID int64
size int
err error
)
params := c.Request.Form
mobiApp := params.Get("mobi_app")
device := params.Get("device")
maxIDStr := params.Get("max_id")
minIDStr := params.Get("min_id")
// check params
if build, err = strconv.Atoi(params.Get("build")); err != nil {
c.JSON(nil, ecode.RequestErr)
return
}
if vmid, _ = strconv.ParseInt(params.Get("vmid"), 10, 64); vmid < 1 {
c.JSON(nil, ecode.RequestErr)
return
}
if maxIDStr != "" {
if maxID, err = strconv.ParseInt(maxIDStr, 10, 64); err != nil {
c.JSON(nil, ecode.RequestErr)
return
}
}
if minIDStr != "" {
if minID, err = strconv.ParseInt(minIDStr, 10, 64); err != nil {
c.JSON(nil, ecode.RequestErr)
return
}
}
if size, _ = strconv.Atoi(params.Get("size")); size < 1 || size > 20 {
size = 20
}
cursor, err := model.NewCursor(maxID, minID, size)
if err != nil {
c.JSON(nil, ecode.RequestErr)
log.Error("%+v", err)
return
}
plat := model.Plat(mobiApp, device)
c.JSON(spaceSvr.Contribution(c, plat, build, vmid, cursor, time.Now()))
}
func upContribute(c *bm.Context) {
var (
vmid int64
attrs *space.Attrs
items []*space.Item
err error
)
params := c.Request.Form
vmidStr := params.Get("vmid")
attrsStr := params.Get("attrs")
itemsStr := params.Get("items")
// check params
if vmid, _ = strconv.ParseInt(vmidStr, 10, 64); vmid < 1 {
c.JSON(nil, ecode.RequestErr)
return
}
if err = json.Unmarshal([]byte(attrsStr), &attrs); err != nil {
c.JSON(nil, ecode.RequestErr)
log.Error("json.Unmarshal(%s) error(%v)", attrsStr, err)
return
}
if err = json.Unmarshal([]byte(itemsStr), &items); err != nil {
c.JSON(nil, ecode.RequestErr)
log.Error("json.Unmarshal(%s) error(%v)", itemsStr, err)
return
}
c.JSON(spaceSvr.AddContribute(c, vmid, attrs, items), nil)
}
func bangumi(c *bm.Context) {
var (
mid int64
pn, ps int
)
params := c.Request.Form
if midInt, ok := c.Get("mid"); ok {
mid = midInt.(int64)
}
// check params
vmid, _ := strconv.ParseInt(params.Get("vmid"), 10, 64)
if vmid < 1 {
c.JSON(nil, ecode.RequestErr)
return
}
if pn, _ = strconv.Atoi(params.Get("pn")); pn < 1 {
pn = 1
}
if ps, _ = strconv.Atoi(params.Get("ps")); ps < 1 || ps > 20 {
ps = 20
}
c.JSON(spaceSvr.Bangumi(c, mid, vmid, nil, pn, ps), nil)
}
func community(c *bm.Context) {
var (
pn, ps int
)
params := c.Request.Form
ak := params.Get("access_key")
platform := params.Get("platform")
// check params
vmid, _ := strconv.ParseInt(params.Get("vmid"), 10, 64)
if vmid < 1 {
c.JSON(nil, ecode.RequestErr)
return
}
if pn, _ = strconv.Atoi(params.Get("pn")); pn < 1 {
pn = 1
}
if ps, _ = strconv.Atoi(params.Get("ps")); ps < 1 || ps > 20 {
ps = 20
}
c.JSON(spaceSvr.Community(c, vmid, pn, ps, ak, platform), nil)
}
func coinArc(c *bm.Context) {
var (
mid int64
pn, ps int
)
params := c.Request.Form
if midInt, ok := c.Get("mid"); ok {
mid = midInt.(int64)
}
// check params
vmid, _ := strconv.ParseInt(params.Get("vmid"), 10, 64)
if vmid < 1 {
c.JSON(nil, ecode.RequestErr)
return
}
if pn, _ = strconv.Atoi(params.Get("pn")); pn < 1 {
pn = 1
}
if ps, _ = strconv.Atoi(params.Get("ps")); ps < 1 || ps > 20 {
ps = 20
}
c.JSON(spaceSvr.CoinArcs(c, mid, vmid, nil, pn, ps), nil)
}
func likeArc(c *bm.Context) {
var (
mid int64
pn, ps int
)
params := c.Request.Form
if midInt, ok := c.Get("mid"); ok {
mid = midInt.(int64)
}
// check params
vmid, _ := strconv.ParseInt(params.Get("vmid"), 10, 64)
if vmid < 1 {
c.JSON(nil, ecode.RequestErr)
return
}
if pn, _ = strconv.Atoi(params.Get("pn")); pn < 1 {
pn = 1
}
if ps, _ = strconv.Atoi(params.Get("ps")); ps < 1 || ps > 20 {
ps = 20
}
c.JSON(spaceSvr.LikeArcs(c, mid, vmid, nil, pn, ps), nil)
}
func report(c *bm.Context) {
params := c.Request.Form
ak := params.Get("access_key")
reason := params.Get("reason")
mid, _ := strconv.ParseInt(params.Get("mid"), 10, 64)
if mid < 1 {
c.JSON(nil, ecode.RequestErr)
return
}
c.JSON(nil, spaceSvr.Report(c, mid, reason, ak))
}
func clips(c *bm.Context) {
var (
pos, ps int
)
params := c.Request.Form
// check params
vmid, _ := strconv.ParseInt(params.Get("vmid"), 10, 64)
if vmid < 1 {
c.JSON(nil, ecode.RequestErr)
return
}
if pos, _ = strconv.Atoi(params.Get("offset")); pos < 0 {
pos = 0
}
if ps, _ = strconv.Atoi(params.Get("ps")); ps < 1 || ps > 20 {
ps = 20
}
c.JSON(spaceSvr.Clip(c, vmid, pos, ps), nil)
}
func albums(c *bm.Context) {
var (
pos, ps int
)
params := c.Request.Form
// check params
vmid, _ := strconv.ParseInt(params.Get("vmid"), 10, 64)
if vmid < 1 {
c.JSON(nil, ecode.RequestErr)
return
}
if pos, _ = strconv.Atoi(params.Get("offset")); pos < 0 {
pos = 0
}
if ps, _ = strconv.Atoi(params.Get("ps")); ps < 1 || ps > 20 {
ps = 20
}
c.JSON(spaceSvr.Album(c, vmid, pos, ps), nil)
}
// checkPay pay movie or bangumi
func compRealtion(rel int, mobiApp string, build int, device string) (r int) {
const (
_upAndroid = 505000
_banIphone = 5550
_banIPad = 10450
)
switch mobiApp {
case "android", "android_G":
if build < _upAndroid && rel == -1 {
return -999
}
case "iphone", "iphone_G":
if build < _banIphone && rel == -1 {
return -999
}
case "ipad", "ipad_G":
if build <= _banIPad && rel == -1 {
return -999
}
}
return rel
}