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,62 @@
load(
"@io_bazel_rules_go//proto:def.bzl",
"go_proto_library",
)
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
proto_library(
name = "model_proto",
srcs = ["dm.proto"],
tags = ["automanaged"],
deps = ["@gogo_special_proto//github.com/gogo/protobuf/gogoproto"],
)
go_proto_library(
name = "model_go_proto",
compilers = ["@io_bazel_rules_go//proto:gogofast_proto"],
importpath = "go-common/app/job/main/dm/model",
proto = ":model_proto",
tags = ["manual"],
deps = [
"//library/time:go_default_library",
"@com_github_gogo_protobuf//gogoproto:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = [
"dm.go",
"job.go",
"subject.go",
],
embed = [":model_go_proto"],
importpath = "go-common/app/job/main/dm/model",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//library/time:go_default_library",
"@com_github_gogo_protobuf//gogoproto:go_default_library",
"@com_github_golang_protobuf//proto: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"],
)

116
app/job/main/dm/model/dm.go Normal file
View File

@@ -0,0 +1,116 @@
package model
import (
"database/sql/driver"
"strconv"
"time"
)
// all const variable used in job
const (
AttrNo = int32(0)
AttrYes = int32(1)
// platform
PlatUnknow = int32(0)
PlatWeb = int32(1)
PlatAndroid = int32(2)
PlatIPhone = int32(3)
PlatWpM = int32(4) // wp mobile
PlatIPad = int32(5)
PlatPadHd = int32(6) // ipad hd
PlatWpPc = int32(7) // win10
// dm state
StateNormal = int32(0) // 普通状态
StateDelete = int32(1) // 删除状态
StateHide = int32(2) // 隐藏状态
StateBlock = int32(3) // 屏蔽状态
StateFilter = int32(4) // 过滤状态
StateMonitorBefore = int32(5) // 先审后发
StateMonitorAfter = int32(6) // 先发后审
// dm attribute
AttrProtect = uint(0) // 保护弹幕
// dm pool
PoolNormal = int32(0) // 普通弹幕池
PoolSubtitle = int32(1) // 字幕弹幕池
PoolSpecial = int32(2) // 特殊弹幕池
// dm mode
ModeNormal = int32(1) // 正常滚动弹幕
ModeBottom = int32(4) // 底部弹幕
ModeTop = int32(5) // 顶部弹幕
ModeReverse = int32(6) // 逆向滚动弹幕
ModeAdvance = int32(7) // 高级弹幕
ModeCode = int32(8) // 代码弹幕
NotFound = int64(-1)
)
// AttrVal return val of index'attr
func (d *DM) AttrVal(bit uint) int32 {
return (d.Attr >> bit) & int32(1)
}
// AttrSet set val of index'attr
func (d *DM) AttrSet(v int32, bit uint) {
d.Attr = d.Attr&(^(1 << bit)) | (v << bit)
}
// NeedDisplay 判断该条弹幕是否需要展示
func (d *DM) NeedDisplay() bool {
return d.State == StateNormal || d.State == StateMonitorAfter
}
// NeedStateNormal 判断是否更新状态
// pool0 变为 pool1 状态正常
// 变为保护弹幕 状态正常
func (d *DM) NeedStateNormal(old *DM) bool {
if (d.Pool != old.Pool) && d.Pool == PoolSubtitle {
return !(d.State == StateNormal)
}
if d.AttrVal(AttrProtect) == AttrYes && old.AttrVal(AttrProtect) == AttrNo {
return !(d.State == StateNormal)
}
return false
}
// Trim dmid and it's progress time will be trimed.
type Trim struct {
ID int64 `json:"id"`
Attr int32 `json:"-"`
}
type stime int64
// Scan scan time.
func (st *stime) Scan(src interface{}) (err error) {
switch sc := src.(type) {
case time.Time:
*st = stime(sc.Unix())
case string:
var i int64
i, err = strconv.ParseInt(sc, 10, 64)
*st = stime(i)
}
return
}
// Value get time value.
func (st stime) Value() (driver.Value, error) {
return time.Unix(int64(st), 0), nil
}
// UnmarshalJSON implements the json.Unmarshaler interface.
func (st *stime) UnmarshalJSON(data []byte) error {
timestamp, err := strconv.ParseInt(string(data), 10, 64)
if err == nil {
*st = stime(timestamp)
return nil
}
t, err := time.ParseInLocation(`"2006-01-02 15:04:05"`, string(data), time.Local)
*st = stime(t.Unix())
return err
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,37 @@
syntax = "proto3";
package model;
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
message DM {
int64 ID = 1 [(gogoproto.jsontag) = "id"];
int32 Type = 2 [(gogoproto.jsontag) = "type"];
int64 Oid = 3 [(gogoproto.jsontag) = "oid"];
int64 Mid = 4 [(gogoproto.jsontag) = "mid"];
int32 Progress = 5 [(gogoproto.jsontag) = "progress"];
int32 Pool = 6 [(gogoproto.jsontag) = "pool"];
int32 Attr = 7 [(gogoproto.jsontag) = "attr"];
int32 State = 8 [(gogoproto.jsontag) = "state"];
int64 Ctime = 9 [(gogoproto.jsontag) = "ctime", (gogoproto.casttype) = "stime"];
int64 Mtime = 10 [(gogoproto.jsontag) = "mtime", (gogoproto.casttype) = "stime"];
Content Content = 11 [(gogoproto.jsontag) = "content,omitempty"];
ContentSpecial ContentSpe = 12 [(gogoproto.jsontag) = "content_special,omitempty"];
}
message Content {
int64 ID = 1 [(gogoproto.jsontag) = "id"];
int32 FontSize = 2 [(gogoproto.jsontag) = "fontsize"];
int64 Color = 3 [(gogoproto.jsontag) = "color"];
int32 Mode = 4 [(gogoproto.jsontag) = "mode"];
int64 IP = 5 [(gogoproto.jsontag) = "ip"];
int32 Plat = 6 [(gogoproto.jsontag) = "plat"];
string Msg = 7 [(gogoproto.jsontag) = "msg"];
int64 Ctime = 8 [(gogoproto.jsontag) = "ctime", (gogoproto.casttype) = "go-common/library/time.Time"];
int64 Mtime = 9 [(gogoproto.jsontag) = "mtime", (gogoproto.casttype) = "go-common/library/time.Time"];
}
message ContentSpecial {
int64 ID = 1 [(gogoproto.jsontag) = "id"];
string Msg = 2 [(gogoproto.jsontag) = "msg"];
int64 Ctime = 3 [(gogoproto.jsontag) = "ctime", (gogoproto.casttype) = "go-common/library/time.Time"];
int64 Mtime = 4 [(gogoproto.jsontag) = "mtime", (gogoproto.casttype) = "go-common/library/time.Time"];
}

View File

@@ -0,0 +1,21 @@
package model
import (
"encoding/json"
)
// All const variable used in job
const (
// binlog type
SyncInsert = "insert"
SyncUpdate = "update"
SyncDelete = "delete"
)
// BinlogMsg dm binlog msg
type BinlogMsg struct {
Action string `json:"action"`
Table string `json:"table"`
New json.RawMessage `json:"new"`
Old json.RawMessage `json:"old"`
}

View File

@@ -0,0 +1,128 @@
package model
import (
"go-common/library/time"
)
var (
_defaultSeg = &Segment{Start: 0, End: DefaultVideoEnd, Cnt: 1, Num: 1, Duration: 0}
)
const (
// segmentLength 分段长度,根据视频时长做分段,单位:毫秒
segmentLength = int64(6 * 60 * 1000)
// DefaultVideoEnd 当视频时长不存在或者为0时的默认视频结尾时间点
DefaultVideoEnd = int64(10 * 60 * 60 * 1000)
// SubTypeVideo 主题类型
SubTypeVideo = int32(1)
// SubStateOpen 主题打开
SubStateOpen = int32(0)
// SubStateClosed 主题关闭
SubStateClosed = int32(1)
// AttrSubGuest 允许游客弹幕
AttrSubGuest = uint(0)
// AttrSubSpolier 允许剧透弹幕
AttrSubSpolier = uint(1)
// AttrSubMission 允许活动弹幕
AttrSubMission = uint(2)
// AttrSubAdvance 允许高级弹幕
AttrSubAdvance = uint(3)
// AttrSubMonitorBefore 弹幕先审后发
AttrSubMonitorBefore = uint(4)
// AttrSubMonitorAfter 弹幕先发后审
AttrSubMonitorAfter = uint(5)
)
// Subject dm_subject.
type Subject struct {
ID int64 `json:"id"`
Type int32 `json:"type"`
Oid int64 `json:"oid"`
Pid int64 `json:"pid"`
Mid int64 `json:"mid"`
State int32 `json:"state"`
Attr int32 `json:"attr"`
ACount int64 `json:"acount"`
Count int64 `json:"count"`
MCount int64 `json:"mcount"`
MoveCnt int64 `json:"move_count"`
Maxlimit int64 `json:"maxlimit"`
Childpool int32 `json:"childpool"`
CTime time.Time `json:"ctime"`
MTime time.Time `json:"mtime"`
}
// AttrVal return val of subject'attr.
func (s *Subject) AttrVal(bit uint) int32 {
return (s.Attr >> bit) & int32(1)
}
// AttrSet set val of subject'attr.
func (s *Subject) AttrSet(v int32, bit uint) {
s.Attr = s.Attr&(^(1 << bit)) | (v << bit)
}
// Segment dm segment struct
type Segment struct {
Start int64 `json:"ps"` // 分段起始时间
End int64 `json:"pe"` // 分段结束时间
Cnt int64 `json:"cnt"` // 总分段数
Num int64 `json:"num"` // 当前第几段
Duration int64 `json:"duration"` // 视频总时长
}
// SegmentInfo get segment info by start time and video duration.
func SegmentInfo(ps, duration int64) (s *Segment) {
var cnt, num, pe int64
if duration == 0 {
s = _defaultSeg
return
}
cnt = duration / segmentLength
if duration%segmentLength > 0 {
cnt++
}
for i := int64(0); i < cnt; i++ {
if ps >= i*segmentLength && ps < (i+1)*segmentLength {
ps = i * segmentLength
pe = (i + 1) * segmentLength
num = i + 1
}
}
if pe > duration {
pe = duration
}
if ps > duration {
ps = duration
pe = duration
num = cnt
}
s = &Segment{
Start: ps,
End: pe,
Cnt: cnt,
Num: num,
Duration: duration,
}
return
}
// SegmentPoint 根据当前段数和视频总时长计算分段的起始时间点
func SegmentPoint(num, duration int64) (ps, pe int64) {
if duration == 0 {
ps = 0
pe = DefaultVideoEnd
return
}
pe = num * segmentLength
ps = pe - segmentLength
if pe > duration {
pe = duration
}
if ps < 0 {
ps = 0
}
return
}