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,55 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = ["resource_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
)
go_library(
name = "go_default_library",
srcs = [
"abtest.go",
"ads.go",
"archive.go",
"banner.go",
"const.go",
"cpm.go",
"databus.go",
"relate.go",
"resource.go",
"rpc.go",
"show.go",
],
importpath = "go-common/app/service/main/resource/model",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/main/app-view/model:go_default_library",
"//app/service/main/archive/api:go_default_library",
"//library/log:go_default_library",
"//library/time: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,21 @@
package model
import "hash/crc32"
// AbTest struct
type AbTest struct {
ID int64 `json:"groupId"`
Name string `json:"groupName"`
Threshold int64 `json:"flowPercent"`
ParamValues string `json:"-"`
UTime int64 `json:"-"`
}
// AbTestIn check build in test
func (ab *AbTest) AbTestIn(buvid string) (ok bool) {
ration := crc32.ChecksumIEEE([]byte(buvid)) % 100
if ration < uint32(ab.Threshold) {
ok = true
}
return
}

View File

@@ -0,0 +1,79 @@
package model
import (
xtime "go-common/library/time"
avmdl "go-common/app/interface/main/app-view/model"
)
// ads const
const (
// ads plat
VdoAdsPC = int8(0)
VdoAdsIPhone = int8(1)
VdoAdsAndroid = int8(2)
VdoAdsIPad = int8(3)
// ads type
VdoAdsTypeBangumi = int8(0)
VdoAdsTypeNologin = int8(1)
VdoAdsTypeNothing = int8(2)
VdoAdsTypeOther = int8(3)
// ads target
VdoAdsTargetArchive = int8(1)
VdoAdsTargetBangumi = int8(2)
VdoAdsTargetType = int8(3)
)
// VideoAD is Ads of videos.
type VideoAD struct {
Name string `json:"name"`
ContractID string `json:"contract_id"`
Aid int64 `json:"aid"`
SeasonID int `json:"season_id"`
TypeID int16 `json:"type _id"`
AdCid int64 `json:"ad_cid"`
AdStrategy int `json:"ad_strategy"`
AdURL string `json:"ad_url"`
AdOrder int `json:"ad_order"`
Skipable int8 `json:"skipable"`
Note string `json:"note"`
AgencyName string `json:"agency_name"`
AgencyCountry int `json:"agency_country"`
AgencyArea int `json:"agency_area"`
Price float32 `json:"price"`
Verified int `json:"verified"`
State int `json:"state"`
FrontAid int64 `json:"front_aid"`
Target int8 `json:"target"`
Platform int8 `json:"platform"`
Type int8 `json:"type"`
UserSet int8 `json:"user_set"`
PlayCount int64 `json:"play_count"`
MTime xtime.Time `json:"mtime"`
Aids string `json:"-"`
}
// Paster struct
type Paster struct {
AID int64 `json:"aid"`
CID int64 `json:"cid"`
Duration int64 `json:"duration"`
Type int8 `json:"type"`
AllowJump int8 `json:"allow_jump"`
URL string `json:"url"`
}
// PasterPlat exchange plat to video_ads
func PasterPlat(plat int8) int8 {
switch plat {
case PlatWEB:
return VdoAdsPC
case avmdl.PlatIPad, avmdl.PlatIpadHD, avmdl.PlatIPadI: // 2、9、6 -> 3
return VdoAdsIPad
case avmdl.PlatIPhone, avmdl.PlatIPhoneI: // 1、5 -> 1
return VdoAdsIPhone
case avmdl.PlatAndroid, avmdl.PlatAndroidG, avmdl.PlatAndroidI, avmdl.PlatAndroidTV, avmdl.PlatWPhone: // 0、4、8、7、3 -> 2
return VdoAdsAndroid
}
return VdoAdsIPhone // 1
}

View File

@@ -0,0 +1,82 @@
package model
// resource archive const
const (
// StateOpen 开放浏览
StateOpen = int8(0)
// StateOrange 橙色通过
StateOrange = int8(1)
// StateForbidWait 待审
StateForbidWait = int8(-1)
// StateForbidRecycle 被打回
StateForbidRecycle = int8(-2)
// StateForbidPolice 网警锁定
StateForbidPolice = int8(-3)
// StateForbidLock 被锁定
StateForbidLock = int8(-4)
// StateForbidFackLock 管理员锁定(可浏览)
StateForbidFackLock = int8(-5)
// StateForbidFixed 修复待审
StateForbidFixed = int8(-6)
// StateForbidLater 暂缓审核
StateForbidLater = int8(-7)
// StateForbidPatched 补档待审
StateForbidPatched = int8(-8)
// StateForbidWaitXcode 等待转码
StateForbidWaitXcode = int8(-9)
// StateForbidAdminDelay 延迟审核
StateForbidAdminDelay = int8(-10)
// StateForbidFixing 视频源待修
StateForbidFixing = int8(-11)
// StateForbidStorageFail 转储失败
StateForbidStorageFail = int8(-12)
// StateForbidOnlyComment 允许评论待审
StateForbidOnlyComment = int8(-13)
// StateForbidTmpRecicle 临时回收站
StateForbidTmpRecicle = int8(-14)
// StateForbidDispatch 分发中
StateForbidDispatch = int8(-15)
// StateForbidXcodeFail 转码失败
StateForbidXcodeFail = int8(-16)
// StateForbitUpLoad 创建未提交
StateForbitUpLoad = int8(-20) // NOTE:spell body can judge to change state
// StateForbidSubmit 创建已提交
StateForbidSubmit = int8(-30)
// StateForbidUserDelay 定时发布
StateForbidUserDelay = int8(-40)
// StateForbidUpDelete 用户删除
StateForbidUpDelete = int8(-100)
// resource apply
ApplyFirstAudit = 0 // 待一审
ApplySecondAudit = 1 // 待二审
ApplyNoAssignment = 2 // 未投放
ApplyAssignment = 3 // 已投放
ApplyReject = -1 // 已驳回
ApplyRecall = -2 // 已撤回
)
// Archive archive struct
type Archive struct {
ID int64 `json:"id"`
Mid int64 `json:"mid"`
TypeID int16 `json:"typeid"`
HumanRank int `json:"humanrank"`
Duration int `json:"duration"`
Title string `json:"title"`
Cover string `json:"cover"`
Content string `json:"content"`
Tag string `json:"tag"`
Attribute int32 `json:"attribute"`
Copyright int8 `json:"copyright"`
AreaLimit int8 `json:"arealimit"`
State int8 `json:"state"`
Author string `json:"author"`
Access int `json:"access"`
Forward int `json:"forward"`
PubTime string `json:"pubtime"`
Reason string `json:"reject_reason"`
Round int8 `json:"round"`
CTime string `json:"ctime"`
MTime string `json:"mtime"`
}

View File

@@ -0,0 +1,162 @@
package model
import (
"encoding/json"
"strconv"
xtime "go-common/library/time"
)
// Banners struct
type Banners struct {
Banner map[int][]*Banner
Version string
}
// Banner struct
type Banner struct {
ID int `json:"id"`
ParentID int `json:"-"`
Plat int8 `json:"-"`
Module string `json:"-"`
Position string `json:"-"`
Title string `json:"title"`
Image string `json:"image"`
Hash string `json:"hash"`
URI string `json:"uri"`
Goto string `json:"-"`
Value string `json:"-"`
Param string `json:"-"`
Channel string `json:"-"`
Build int `json:"-"`
Condition string `json:"-"`
Area string `json:"-"`
Rank int `json:"-"`
Rule string `json:"-"`
Type int8 `json:"-"`
Start xtime.Time `json:"stime"`
End xtime.Time `json:"-"`
MTime xtime.Time `json:"-"`
ResourceID int `json:"resource_id"`
RequestId string `json:"request_id,omitempty"`
CreativeId int `json:"creative_id,omitempty"`
SrcId int `json:"src_id,omitempty"`
IsAd bool `json:"is_ad"`
IsAdReplace bool `json:"-"`
IsAdLoc bool `json:"is_ad_loc,omitempty"`
CmMark int `json:"cm_mark"`
AdCb string `json:"ad_cb,omitempty"`
ShowUrl string `json:"show_url,omitempty"`
ClickUrl string `json:"click_url,omitempty"`
ClientIp string `json:"client_ip,omitempty"`
Index int `json:"index"`
ServerType int `json:"server_type"`
Extra json.RawMessage `json:"extra"`
CreativeType int `json:"creative_type"`
}
// JSONBanner bilibili_assignment rule
type JSONBanner struct {
Area string `json:"area"`
Hash string `json:"hash"`
Build int `json:"build"`
Condition string `json:"cond"`
Channel string `json:"channel"`
CreativeType int `json:"creative_type"`
}
// Limit limit
type Limit struct {
Rule string `json:"-"`
}
// JSONLimit limit
type JSONLimit struct {
Limit int `json:"limit"`
Resrc []string `json:"resrc"`
}
// BannerChange change banner
func (b *Banner) BannerChange() {
var tmp *JSONBanner
if err := json.Unmarshal([]byte(b.Rule), &tmp); err == nil {
b.Area = tmp.Area
b.Build = tmp.Build
b.Condition = tmp.Condition
if tmp.Channel == "" {
b.Channel = "*"
} else {
b.Channel = tmp.Channel
}
b.Hash = tmp.Hash
b.CreativeType = tmp.CreativeType
}
switch b.Plat {
case 1: // resource iphone
b.Plat = PlatIPhone
case 2: // resource android
b.Plat = PlatAndroid
case 3: // resource pad
b.Plat = PlatIPad
case 4: // resource iphoneg
b.Plat = PlatIPhoneI
case 5: // resource androidg
b.Plat = PlatAndroidG
case 6: // resource padg
b.Plat = PlatIPadI
case 8: // resource androidi
b.Plat = PlatAndroidI
}
if b.Value == "" {
return
}
switch b.Type {
case 7:
if b.Plat == PlatIPhone || b.Plat == PlatAndroid || b.Plat == PlatIPad || b.Plat == PlatIPhoneI || b.Plat == PlatAndroidG || b.Plat == PlatIPadI || b.Plat == PlatAndroidI {
b.URI = "bilibili://pegasus/channel/" + b.Value + "/"
} else {
b.URI = "http://www.bilibili.com/tag/" + b.Value
}
case 6:
//GotoAv
b.URI = "bilibili://video/" + b.Value
case 4:
//GotoLive
if b.Plat == PlatIPad {
b.URI = "bilibili://player/live/" + b.Value
} else {
b.URI = "bilibili://live/" + b.Value
}
case 3:
//GotoBangumi
b.URI = "bilibili://bangumi/season/" + b.Value
case 5:
//GotoGame
b.URI = "bilibili://game/" + b.Value
case 2:
//GotoWeb
b.URI = b.Value
}
}
// LimitChange change limit
func (l *Limit) LimitChange() (data map[int]int) {
data = map[int]int{}
var (
tmp = &JSONLimit{}
err error
resid int
)
if err = json.Unmarshal([]byte(l.Rule), tmp); err != nil {
return
}
l.Rule = ""
for _, residstr := range tmp.Resrc {
resid, err = strconv.Atoi(residstr)
if err != nil {
return
}
data[resid] = tmp.Limit
}
return
}

View File

@@ -0,0 +1,146 @@
package model
// resource const
const (
// PlatAndroid is int8 for android.
PlatAndroid = int8(0)
// PlatIPhone is int8 for iphone.
PlatIPhone = int8(1)
// PlatIPad is int8 for ipad.
PlatIPad = int8(2)
// PlatWPhone is int8 for wphone.
PlatWPhone = int8(3)
// PlatAndroidG is int8 for Android Googleplay.
PlatAndroidG = int8(4)
// PlatIPhoneI is int8 for Iphone Global.
PlatIPhoneI = int8(5)
// PlatIPadI is int8 for IPAD Global.
PlatIPadI = int8(6)
// PlatAndroidTV is int8 for AndroidTV Global.
PlatAndroidTV = int8(7)
// PlatAndroidI is int8 for Android Global.
PlatAndroidI = int8(8)
// PlatAndroidB is int8 for Android Bule.
PlatAndroidB = int8(9)
// PlatWEB is int8 for web.
PlatWEB = int8(99)
// goto
GotoAv = "av"
GotoWeb = "web"
GotoBangumi = "bangumi"
GotoBangumiWeb = "bangumi_web"
GotoSp = "sp"
GotoLive = "live"
GotoGame = "game"
GotoArticle = "article"
GotoActivity = "activity_new"
GotoTopic = "topic_new"
GotoDaily = "daily"
GotoRank = "rank"
GotoCard = "card"
GotoVeidoCard = "video_card"
GotoSpecialCard = "special_card"
GotoTagCard = "tag_card"
GotoColumn = "column"
GotoColumnStage = "column_stage"
GotoTagID = "tag_id"
CardGotoAv = int8(1)
CardGotoTopic = int8(2)
CardGotoActivity = int8(3)
)
// InvalidBuild check source build is not allow by config build and condition.
// eg: when condition is gt, means srcBuild must gt cfgBuild, otherwise is invalid srcBuild.
func InvalidBuild(srcBuild, cfgBuild int, cfgCond string) bool {
if cfgBuild != 0 && cfgCond != "" {
switch cfgCond {
case "gt":
if cfgBuild >= srcBuild {
return true
}
case "lt":
if cfgBuild <= srcBuild {
return true
}
case "eq":
if cfgBuild != srcBuild {
return true
}
case "ne":
if cfgBuild == srcBuild {
return true
}
}
}
return false
}
// InvalidChannel check source channel is not allow by config channel.
func InvalidChannel(plat int8, srcCh, cfgCh string) bool {
return plat == PlatAndroid && cfgCh != "*" && cfgCh != srcCh
}
// Plat return plat by platStr or mobiApp
func Plat(mobiApp, device string) int8 {
switch mobiApp {
case "iphone":
if device == "pad" {
return PlatIPad
}
return PlatIPhone
case "white":
return PlatIPhone
case "ipad":
return PlatIPad
case "android":
return PlatAndroid
case "win":
return PlatWPhone
case "android_G":
return PlatAndroidG
case "android_I":
return PlatAndroidI
case "iphone_I":
if device == "pad" {
return PlatIPadI
}
return PlatIPhoneI
case "ipad_I":
return PlatIPadI
case "android_tv":
return PlatAndroidTV
}
return PlatIPhone
}
// FillURI deal app schema.
func FillURI(gt, param string) (uri string) {
if param == "" {
return
}
switch gt {
case GotoAv, "":
uri = "bilibili://video/" + param
case GotoLive:
uri = "bilibili://live/" + param
case GotoBangumi:
uri = "bilibili://bangumi/season/" + param
case GotoBangumiWeb:
uri = "http://bangumi.bilibili.com/anime/" + param
case GotoGame:
uri = "bilibili://game/" + param
case GotoSp:
uri = "bilibili://splist/" + param
case GotoWeb:
uri = param
case GotoDaily:
uri = "bilibili://daily/" + param
case GotoColumn:
uri = "bilibili://pegasus/list/column/" + param
case GotoArticle:
uri = "bilibili://article/" + param
}
return
}

View File

@@ -0,0 +1,91 @@
package model
import (
"encoding/json"
"strconv"
"go-common/library/log"
)
// ADRequest cpm type
type ADRequest struct {
RequestID string `json:"request_id"`
ADIndexs map[string]map[string]*ADIndex `json:"ads_info"`
}
// ADIndex cpm type
type ADIndex struct {
Index int `json:"index"`
Info *ADInfo `json:"ad_info"`
IsAd bool `json:"is_ad"`
CmMark int `json:"cm_mark"`
}
// ADInfo cpm type
type ADInfo struct {
CreativeID int `json:"creative_id"`
CreativeType int `json:"creative_type"`
CreativeContent struct {
Title string `json:"title"`
Desc string `json:"description"`
VideoID int64 `json:"video_id"`
UserName string `json:"username"`
ImageURL string `json:"image_url"`
ImageMD5 string `json:"image_md5"`
LogURL string `json:"log_url"`
LogMD5 string `json:"log_md5"`
URL string `json:"url"`
ClickURL string `json:"click_url"`
ShowURL string `json:"show_url"`
} `json:"creative_content"`
AdCb string `json:"ad_cb"`
Extra json.RawMessage `json:"extra"`
}
// ConvertBanner expair cpm type
func (adr *ADRequest) ConvertBanner(ip, mobiApp string, build int) (banners map[int]map[int]*Banner) {
banners = map[int]map[int]*Banner{}
for resIDStr, sAdis := range adr.ADIndexs {
resID, _ := strconv.Atoi(resIDStr)
if len(sAdis) == 0 {
log.Info("mobi_app:%v-build:%v-resource:%v-is_ad_loc:%v", mobiApp, build, resID, false)
continue
}
for sidStr, adi := range sAdis {
sid, _ := strconv.Atoi(sidStr)
var bnnr = &Banner{
IsAdLoc: true,
IsAd: adi.IsAd,
IsAdReplace: false,
CmMark: adi.CmMark,
Rank: adi.Index,
SrcId: sid,
RequestId: adr.RequestID,
ClientIp: ip,
}
if adInfo := adi.Info; adInfo != nil {
bnnr.IsAdReplace = true
bnnr.CreativeId = adInfo.CreativeID
bnnr.AdCb = adInfo.AdCb
bnnr.ShowUrl = adInfo.CreativeContent.ShowURL
bnnr.ClickUrl = adInfo.CreativeContent.ClickURL
bnnr.Title = adInfo.CreativeContent.Title
bnnr.Image = adInfo.CreativeContent.ImageURL
bnnr.Hash = adInfo.CreativeContent.ImageMD5
bnnr.URI = adInfo.CreativeContent.URL
bnnr.Channel = "*"
bnnr.Extra = adInfo.Extra
bnnr.ServerType = 1
}
if _, ok := banners[resID]; ok {
banners[resID][bnnr.Rank] = bnnr
} else {
banners[resID] = map[int]*Banner{
bnnr.Rank: bnnr,
}
}
log.Info("mobi_app:%v-build:%v-source:%v-resource:%v-is_ad_loc:%v", mobiApp, build, sid, resID, true)
}
}
return
}

View File

@@ -0,0 +1,28 @@
package model
import "encoding/json"
// Message databus
type Message struct {
Action string `json:"action"`
Table string `json:"table"`
New json.RawMessage `json:"new"`
Old json.RawMessage `json:"old"`
}
// databus const
const (
RouteFirstRoundForbid = "first_round_forbid"
RouteSecondRound = "second_round"
RouteAutoOpen = "auto_open"
RouteDelayOpen = "delay_open"
RouteDeleteArchive = "delete_archive"
RouteForceSync = "force_sync"
)
// Videoup message for videoup2BVC
type Videoup struct {
Route string `json:"route"`
Timestamp int64 `json:"timestamp"`
Aid int64 `json:"aid"`
}

View File

@@ -0,0 +1,27 @@
package model
import xtime "go-common/library/time"
//Version app version
type Version struct {
Plat int8 `json:"plat,omitempty"`
Build int `json:"build,omitempty"`
Condition string `json:"conditions,omitempty"`
}
//Relate relate card
type Relate struct {
ID int64 `json:"id,omitempty"`
Param int64 `json:"param,omitempty"`
Goto string `json:"goto,omitempty"`
Title string `json:"title,omitempty"`
ResourceIDs string `json:"resource_ids,omitempty"`
TagIDs string `json:"tag_ids,omitempty"`
ArchiveIDs string `json:"archive_ids,omitempty"`
RecReason string `json:"rec_reason,omitempty"`
Position int32 `json:"position,omitempty"`
STime xtime.Time `json:"stime,omitempty"`
ETime xtime.Time `json:"etime,omitempty"`
Versions map[int8][]*Version `json:"versions,omitempty"`
PgcIDs string
}

View File

@@ -0,0 +1,144 @@
package model
import (
xtime "go-common/library/time"
)
// resource const
const (
IconTypeFix = 1
IconTypeRandom = 2
IconTypeBangumi = 3
NoCategory = 0
IsCategory = 1
AsgTypePic = int8(0)
AsgTypeVideo = int8(1)
// pgc mobile
AsgTypeURL = int8(2)
AsgTypeBangumi = int8(3)
AsgTypeLive = int8(4)
AsgTypeGame = int8(5)
AsgTypeAv = int8(6)
)
// IconTypes icon_type
var IconTypes = map[int]string{
IconTypeFix: "fix",
IconTypeRandom: "random",
IconTypeBangumi: "bangumi",
}
// Rule resource_assignmen rule
type Rule struct {
Cover int32 `json:"is_cover"`
Style int32 `json:"style"`
Label string `json:"label"`
Intro string `json:"intro"`
}
// Resource struct
type Resource struct {
ID int `json:"id"`
Platform int `json:"platform"`
Name string `json:"name"`
Parent int `json:"parent"`
State int `json:"-"`
Counter int `json:"counter"`
Position int `json:"position"`
Rule string `json:"rule"`
Size string `json:"size"`
Previce string `json:"preview"`
Desc string `json:"description"`
Mark string `json:"mark"`
Assignments []*Assignment `json:"assignments"`
CTime xtime.Time `json:"ctime"`
MTime xtime.Time `json:"mtime"`
Level int64 `json:"level"`
Type int `json:"type"`
IsAd int `json:"is_ad"`
}
// Assignment struct
type Assignment struct {
ID int `json:"id"`
AsgID int `json:"-"`
Name string `json:"name"`
ContractID string `json:"contract_id"`
ResID int `json:"resource_id"`
Pic string `json:"pic"`
LitPic string `json:"litpic"`
URL string `json:"url"`
Rule string `json:"rule"`
Weight int `json:"weight"`
Agency string `json:"agency"`
Price float32 `json:"price"`
State int `json:"state"`
Atype int8 `json:"atype"`
Username string `json:"username"`
PlayerCategory int8 `json:"player_category"`
ApplyGroupID int `json:"-"`
STime xtime.Time `json:"stime"`
ETime xtime.Time `json:"etime"`
CTime xtime.Time `json:"ctime"`
MTime xtime.Time `json:"mtime"`
}
// IndexIcon struct
type IndexIcon struct {
ID int64 `json:"id"`
Type int `json:"type"`
Title string `json:"title"`
State int `json:"state"`
Links []string `json:"links"`
Icon string `json:"icon"`
Weight int `json:"weight"`
UserName string `json:"-"`
StTime xtime.Time `json:"sttime"`
EndTime xtime.Time `json:"endtime"`
DelTime xtime.Time `json:"deltime"`
CTime xtime.Time `json:"ctime"`
MTime xtime.Time `json:"mtime"`
}
// PlayerIcon struct
type PlayerIcon struct {
URL1 string `json:"url1"`
Hash1 string `json:"hash1"`
URL2 string `json:"url2"`
Hash2 string `json:"hash2"`
CTime xtime.Time `json:"ctime"`
}
// ResWarnInfo for email
type ResWarnInfo struct {
AID int64
URL string
AssignmentID int
AssignmentName string
ResourceName string
ResourceID int
MaterialID int
UserName string
STime xtime.Time `json:"stime"`
ETime xtime.Time `json:"etime"`
ApplyGroupID int
}
// Cmtbox live danmaku box
type Cmtbox struct {
ID int64 `json:"id"`
LoadCID int64 `json:"load_cid"`
Server string `json:"server"`
Port string `json:"port"`
SizeFactor string `json:"size_factor"`
SpeedFactor string `json:"speed_factor"`
MaxOnscreen string `json:"max_onscreen"`
Style string `json:"style"`
StyleParam string `json:"style_param"`
TopMargin string `json:"top_margin"`
State string `json:"state"`
CTime xtime.Time `json:"ctime"`
MTime xtime.Time `json:"mtime"`
}

View File

@@ -0,0 +1,8 @@
package model
import (
"testing"
)
func TestCPM(t *testing.T) {
}

View File

@@ -0,0 +1,51 @@
package model
// ArgBanner for banner func
type ArgBanner struct {
Plat int8
Build int
AID int64
MID int64
ResIDs string
Channel string
IP string
Buvid string
Network string
MobiApp string
Device string
IsAd bool
OpenEvent string
AdExtra string
Version string
}
// ArgRes for resource func
type ArgRes struct {
ResID int
}
// ArgRess for resources func
type ArgRess struct {
ResIDs []int
}
// ArgPaster for paster func
type ArgPaster struct {
Platform int8
AdType int8
Aid string
TypeId string
TypeID string
Buvid string
}
// ArgCmtbox for ctmbox
type ArgCmtbox struct {
ID int64
}
// ArgAbTest for abTest
type ArgAbTest struct {
Groups string
IP string
}

View File

@@ -0,0 +1,216 @@
package model
import (
"encoding/json"
"strconv"
"go-common/app/service/main/archive/api"
xtime "go-common/library/time"
)
// Card audio card struct
type Card struct {
ID int `json:"-"`
Tab int `json:"-"`
RegionID int `json:"-"`
Type int `json:"-"`
Title string `json:"-"`
Cover string `json:"-"`
Rtype int `json:"-"`
Rvalue string `json:"-"`
PlatVer string `json:"-"`
Plat int8 `json:"-"`
Build int `json:"-"`
Condition string `json:"-"`
TypeStr string `json:"-"`
Goto string `json:"-"`
Param string `json:"-"`
URI string `json:"-"`
Desc string `json:"-"`
TagID int `json:"-"`
}
// Content audio content struct
type Content struct {
ID int `json:"-"`
Module int `json:"-"`
RecID int `json:"-"`
Type int8 `json:"-"`
Value string `json:"-"`
Title string `json:"-"`
TagID int `json:"-"`
}
// PlatLimit audio plat limit struct
type PlatLimit struct {
Plat int8 `json:"plat"`
Build int `json:"build"`
Condition string `json:"conditions"`
}
// ShowItem audio show item struct
type ShowItem struct {
Title string `json:"title"`
Cover string `json:"cover"`
URI string `json:"uri"`
NewURI string `json:"-"`
Param string `json:"param"`
Goto string `json:"goto"`
// up
Mid int64 `json:"mid,omitempty"`
Name string `json:"name,omitempty"`
Face string `json:"face,omitempty"`
Follower int `json:"follower,omitempty"`
Attribute int `json:"attribute,omitempty"`
OfficialVerify *OfficialVerify `json:"official_verify,omitempty"`
// stat
Play int `json:"play,omitempty"`
Danmaku int `json:"danmaku,omitempty"`
Reply int `json:"reply,omitempty"`
Fav int `json:"favourite,omitempty"`
// movie and bangumi badge
Status int8 `json:"status,omitempty"`
CoverMark string `json:"cover_mark,omitempty"`
// ranking
Pts int64 `json:"pts,omitempty"`
Children []*ShowItem `json:"children,omitempty"`
// av
PubDate xtime.Time `json:"pubdate"`
// av stat
Duration int64 `json:"duration,omitempty"`
// region
Rid int `json:"rid,omitempty"`
Rname string `json:"rname,omitempty"`
Reid int `json:"reid,omitempty"`
//new manager
Desc string `json:"desc,omitempty"`
Stime string `json:"stime,omitempty"`
Etime string `json:"etime,omitempty"`
Like int `json:"like,omitempty"`
}
// OfficialVerify audio verify struct
type OfficialVerify struct {
Type int `json:"type"`
Desc string `json:"desc"`
}
// Head audio struct
type Head struct {
CardID int `json:"card_id,omitempty"`
Title string `json:"title,omitempty"`
Cover string `json:"cover,omitempty"`
Type string `json:"type,omitempty"`
Date int64 `json:"date,omitempty"`
Plat int8 `json:"-"`
Build int `json:"-"`
Condition string `json:"-"`
URI string `json:"uri,omitempty"`
Goto string `json:"goto,omitempty"`
Param string `json:"param,omitempty"`
Body []*ShowItem `json:"body,omitempty"`
}
// CardPlatChange audio card change plat
func (c *Card) CardPlatChange() (platlinits []*PlatLimit) {
platlinits = platJSONChange(c.PlatVer)
return
}
// platJSONChange json change plat build condition
func platJSONChange(jsonStr string) (platlinits []*PlatLimit) {
var tmp []struct {
Plat string `json:"plat"`
Build string `json:"build"`
Condition string `json:"conditions"`
}
if err := json.Unmarshal([]byte(jsonStr), &tmp); err == nil {
for _, limit := range tmp {
platlinit := &PlatLimit{}
switch limit.Plat {
case "0": // resource android
platlinit.Plat = PlatAndroid
case "1": // resource iphone
platlinit.Plat = PlatIPhone
case "2": // resource pad
platlinit.Plat = PlatIPad
case "5": // resource iphone_i
platlinit.Plat = PlatIPhoneI
case "8": // resource android_i
platlinit.Plat = PlatAndroidI
}
platlinit.Build, _ = strconv.Atoi(limit.Build)
platlinit.Condition = limit.Condition
platlinits = append(platlinits, platlinit)
}
}
return
}
// FromArchivePB from archive archive.
func (i *ShowItem) FromArchivePB(a *api.Arc) {
i.Title = a.Title
i.Cover = a.Pic
i.Param = strconv.FormatInt(a.Aid, 10)
i.URI = FillURI(GotoAv, i.Param)
i.Goto = GotoAv
i.Play = int(a.Stat.View)
i.Danmaku = int(a.Stat.Danmaku)
i.Name = a.Author.Name
i.Reply = int(a.Stat.Reply)
i.Fav = int(a.Stat.Fav)
i.PubDate = a.PubDate
i.Rid = int(a.TypeID)
i.Rname = a.TypeName
i.Duration = a.Duration
i.Like = int(a.Stat.Like)
if a.Access > 0 {
i.Play = 0
}
}
// FillBuildURI fill url by plat build
func (h *Head) FillBuildURI(plat int8, build int) {
switch h.Goto {
case GotoDaily:
if (plat == PlatIPhone && build > 6670) || (plat == PlatAndroid && build > 5250000) {
h.URI = "bilibili://pegasus/list/daily/" + h.Param
}
}
}
// SideBars for side bars
type SideBars struct {
SideBar []*SideBar `json:"sidebar,omitempty"`
Limit map[int64][]*SideBarLimit `json:"limit,omitempty"`
}
// SideBar for side bar
type SideBar struct {
ID int64 `json:"id,omitempty"`
Tip int `json:"tip,omitempty"`
Rank int `json:"rank,omitempty"`
Logo string `json:"logo,omitempty"`
LogoWhite string `json:"logo_white,omitempty"`
Name string `json:"name,omitempty"`
Param string `json:"param,omitempty"`
Module int `json:"module,omitempty"`
Plat int8 `json:"-"`
Build int `json:"-"`
Conditions string `json:"-"`
OnlineTime xtime.Time `json:"online_time"`
NeedLogin int8 `json:"need_login,omitempty"`
WhiteURL string `json:"white_url,omitempty"`
Menu int8 `json:"menu,omitempty"`
LogoSelected string `json:"logo_selected,omitempty"`
TabID string `json:"tab_id,omitempty"`
Red string `json:"red_dot_url,omitempty"`
Language string `json:"language,omitempty"`
}
// SideBarLimit side bar limit
type SideBarLimit struct {
ID int64 `json:"-"`
Build int `json:"-"`
Condition string `json:"-"`
}