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,38 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"archive.go",
"databus.go",
"media_cache.go",
"sync.go",
"upper.go",
],
importpath = "go-common/app/job/main/tv/model/ugc",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/archive/api: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,138 @@
package ugc
import (
v1 "go-common/app/service/main/archive/api"
"go-common/library/time"
)
// Archive archive def. corresponding to our table structure
type Archive struct {
ID int
AID int64
MID int64
TypeID int32
Videos int64
Title string
Cover string
Content string
Duration int64
Copyright int32
Pubtime time.Time
Ctime time.Time
Mtime time.Time
State int32
Manual int
Valid int
Submit int
Retry int
Result int
Deleted int
}
// FromArcReply def
func (a *Archive) FromArcReply(arc *v1.Arc) {
a.AID = arc.Aid
a.MID = arc.Author.Mid
a.Videos = arc.Videos
a.TypeID = arc.TypeID
a.Title = arc.Title
a.Cover = arc.Pic
a.Content = arc.Desc
a.Duration = arc.Duration
a.Copyright = arc.Copyright
a.Pubtime = arc.PubDate
a.State = arc.State
}
// ArcAllow is the struct used to check whether the arc is allowed to enter TV database
type ArcAllow struct {
Aid int64
State int32
Ugcpay int32
Typeid int32
Copyright int32
}
// FromArcReply takes info from grpc result
func (a *ArcAllow) FromArcReply(reply *v1.Arc) {
a.Aid = reply.Aid
a.State = reply.State
a.Ugcpay = reply.Rights.UGCPay
a.Typeid = reply.TypeID
a.Copyright = reply.Copyright
}
// FromArcmdl takes info from gorpc result
func (a *ArcAllow) FromArcmdl(mdl *v1.Arc) {
a.Aid = mdl.Aid
a.State = mdl.State
a.Ugcpay = mdl.Rights.UGCPay
a.Typeid = mdl.TypeID
a.Copyright = mdl.Copyright
}
// FromDatabus takes info from databus result ( archive-notify T )
func (a *ArcAllow) FromDatabus(db *ArchDatabus) {
a.Aid = db.Aid
a.State = db.State
a.Typeid = db.TypeID
a.Copyright = db.Copyright
}
// FromArcFull takes info from arcFull structure ( db )
func (a *ArcAllow) FromArcFull(full *ArcFull) {
a.Aid = full.AID
a.State = full.State
a.Copyright = full.Copyright
a.Typeid = full.TypeID
}
// FromArchive takes info from DB
func (a *ArcAllow) FromArchive(arc *Archive) {
a.Aid = arc.AID
a.State = arc.State
a.Copyright = arc.Copyright
a.Typeid = arc.TypeID
}
// CanPlay distinguishes whether an archive can play or not
func (a *ArcAllow) CanPlay() bool {
return a.State >= 0 || a.State == -6
}
// IsOrigin distinguishes whether an archive is original or not
func (a *ArcAllow) IsOrigin() bool {
return a.Copyright == 1
}
// ArcMedia is the archive media struct in MC
type ArcMedia struct {
Title string
AID int64
Cover string
TypeID int32
Pubtime time.Time
Videos int64
Deleted int
}
// DelVideos is used to delete videos of an archive
type DelVideos struct {
AID int64
CIDs []int64
}
// ToSimple def.
func (a *Archive) ToSimple() *SimpleArc {
return &SimpleArc{
AID: a.AID,
MID: a.MID,
TypeID: a.TypeID,
Videos: a.Videos,
Title: a.Title,
Cover: a.Cover,
Content: a.Content,
Duration: a.Duration,
Pubtime: a.Pubtime.Time().Format("2006-01-02"),
}
}

View File

@@ -0,0 +1,138 @@
package ugc
import (
"time"
arcmdl "go-common/app/service/main/archive/api"
)
// ArcMsg reprensents the archive Notify-T message structure
type ArcMsg struct {
Action string `json:"action"`
Table string `json:"table"`
Old *ArchDatabus `json:"old"`
New *ArchDatabus `json:"new"`
}
// ArchDatabus model ( we pick the fields that we need )
type ArchDatabus struct {
Aid int64 `json:"aid"`
Mid int64 `json:"mid"`
TypeID int32 `json:"typeid"`
Videos int64 `json:"videos"`
Duration int `json:"duration"`
Title string `json:"title"`
Cover string `json:"cover"`
Content string `json:"content"`
Attribute int32 `json:"attribute"`
Copyright int32 `json:"copyright"`
State int32 `json:"state"`
Access int `json:"access"`
PubTime string `json:"pubtime"`
}
// VideoDiff reprensents the result of videos comparison
type VideoDiff struct {
Aid int64
Equal []int64 // totally equal
New []int64 // new added videos
Updated []*arcmdl.Page
Removed []int64
}
// DatabusVideo is the struct of message for the modification of ugc_Video
type DatabusVideo struct {
New *MarkVideo `json:"new"`
Old *MarkVideo `json:"old"`
}
// DatabusArc is the struct of message for the modification of ugc_archive
type DatabusArc struct {
Old *MarkArc `json:"old"`
New *MarkArc `json:"new"`
}
// MarkVideo contains the main fields that we want to pick up from databus message
type MarkVideo struct {
Mark int `json:"mark"`
Deleted int `json:"deleted"`
CID int64 `json:"cid"`
AID int64 `json:"aid"`
EPTitle string `json:"eptitle"`
IndexOrder int `json:"index_order"`
Valid int `json:"valid"`
Result int `json:"result"`
Submit int `json:"submit"`
Transcoded int `json:"transcoded"`
Retry int64 `json:"retry"`
}
// MarkArc contains the main fields that we want to pick up from databus message
type MarkArc struct {
ID int `json:"id"`
AID int64 `json:"aid"`
MID int `json:"mid"`
TypeID int32 `json:"typeid"`
Videos int `json:"videos"`
Title string `json:"title"`
Cover string `json:"cover"`
Content string `json:"content"`
Duration int `json:"duration"`
Copyright int `json:"copyright"`
Pubtime string `json:"pubtime"`
Ctime string `json:"ctime"`
Mtime string `json:"mtime"`
State int `json:"state"`
Manual int `json:"manual"`
Valid int `json:"valid"`
Submit int `json:"submit"`
Retry int `json:"retry"`
Result int `json:"result"`
Deleted int `json:"deleted"`
InjectTime string `json:"inject_time"`
Reason string `json:"reason"`
}
// IsPass returns whether the arc is able to play
func (a MarkArc) IsPass() bool {
return a.Deleted == 0 && a.Valid == 1 && a.Result == 1
}
// CidReq reprensents the structure for reporting cid
type CidReq struct {
CID int64 `json:"cid"`
}
// CidResp represents the structure of cid reporting API's response
type CidResp struct {
Code int `json:"code"`
Message string `json:"message"`
}
// ToReport distinguishes whether the CID need to be reported to video cloud
func (vm *MarkVideo) ToReport(criCID int64) bool {
return vm.Deleted == 0 && vm.Mark == 0 && vm.CID > criCID
}
// ToAudit distinguishes whether the CID need to be reported to the license owner
func (vm *MarkVideo) ToAudit(criCID int64) bool {
return vm.Submit == 1 && (vm.Transcoded == 1 || vm.CID <= criCID) && vm.Retry < time.Now().Unix() && vm.Deleted == 0
}
// CanPlay tells whether a video can play or not
func (vm *MarkVideo) CanPlay() bool {
return vm.Result == 1 && vm.Deleted == 0 && vm.Valid == 1
}
// ToCMS transforms a databus video to CMS info
func (vm *MarkVideo) ToCMS() *VideoCMS {
return &VideoCMS{
CID: int(vm.CID),
Title: vm.EPTitle,
AID: int(vm.AID),
IndexOrder: vm.IndexOrder,
Valid: vm.Valid,
Deleted: vm.Deleted,
Result: vm.Result,
}
}

View File

@@ -0,0 +1,56 @@
package ugc
import "go-common/library/time"
// ArcCMS represents the archive data structure in MC
type ArcCMS struct {
// Media Info
Title string
AID int64
Content string
Cover string
TypeID int32
Pubtime time.Time
Videos int
// Auth Info
Valid int
Deleted int
Result int
}
// ArcFull is the plus version of ArcCMS
type ArcFull struct {
ArcCMS
Copyright int32
State int32
MID int64
Duration int64
}
// VideoCMS represents the video data structure in MC
type VideoCMS struct {
// Media Info
CID int
Title string
AID int
IndexOrder int
// Auth Info
Valid int
Deleted int
Result int
}
// ToSimple transforms an arcFull to SimpleArc
func (arc *ArcFull) ToSimple() *SimpleArc {
return &SimpleArc{
AID: arc.AID,
MID: arc.MID,
TypeID: arc.TypeID,
Videos: int64(arc.Videos),
Title: arc.Title,
Cover: arc.Cover,
Content: arc.Content,
Duration: arc.Duration,
Pubtime: arc.Pubtime.Time().Format("2006-01-02"),
}
}

View File

@@ -0,0 +1,30 @@
package ugc
// SimpleArc provides the fields for license owner sync
type SimpleArc struct {
AID int64
MID int64
TypeID int32
Videos int64
Title string
Cover string
Content string
Duration int64
Pubtime string
}
// SimpleVideo provides the fields for license owner sync
type SimpleVideo struct {
ID int
CID int64
IndexOrder int64
Eptitle string
Duration int64
Description string
}
// LicSke represents the skeleton of a license audit message
type LicSke struct {
Arc *SimpleArc
Videos []*SimpleVideo
}

View File

@@ -0,0 +1,71 @@
package ugc
import "strings"
// Upper reprensents the uppers
type Upper struct {
MID int64
Toinit int
Submit int // 1=need report
OriName string // original name
CMSName string // cms intervened name
OriFace string // original face
CMSFace string // cms intervened face
Valid int // auth info: 1=online,0=hidden
Deleted int
}
// EasyUp is the simple version of upper
type EasyUp struct {
MID int64
Name string
Face string
}
// ToUpper transform an EasyUp to Upper
func (u *EasyUp) ToUpper(ori *Upper) *Upper {
if ori == nil { // if no original data is given
ori = &Upper{
Valid: 1,
}
}
return &Upper{
MID: u.MID,
OriFace: u.Face,
CMSFace: u.Face,
OriName: u.Name,
CMSName: u.Name,
Toinit: ori.Toinit,
Submit: ori.Submit,
Valid: ori.Valid,
Deleted: ori.Deleted,
}
}
// IsSame returns whether the upper is the same
func (u *Upper) IsSame(name, face string) (f bool, n bool) {
n = u.OriName == name
if strings.Contains(u.OriFace, "bfs") &&
strings.Contains(face, "bfs") {
f = bfsFName(u.OriFace) == bfsFName(face)
} else {
f = u.OriFace == face
}
return
}
// bfsFName picks the file name from bfs url
func bfsFName(bfsurl string) (fileName string) {
var index = strings.LastIndex(bfsurl, "/")
if index >= 0 && index+1 < len(bfsurl) {
fileName = bfsurl[index+1:]
}
return
}
// ReqSetUp is the structure of request to function in Dao, set upper value
type ReqSetUp struct {
Value string
MID int64
UpType int
}