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,33 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"fav.go",
"job.go",
"music.go",
"video.go",
],
importpath = "go-common/app/job/main/favorite/model",
tags = ["automanaged"],
deps = ["//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,194 @@
package model
import (
"database/sql/driver"
"encoding/json"
"errors"
"strconv"
"time"
)
var (
// ErrFavResourceExist error this has been favoured.
ErrFavResourceExist = errors.New("error this has been favoured")
// ErrFavResourceAlreadyDel error this has been unfavoured.
ErrFavResourceAlreadyDel = errors.New("error this has been unfavoured")
)
const (
// CacheNotFound .
CacheNotFound = -1
// SyncInsert binlog action.
SyncInsert = "insert"
// SyncUpdate binlog action.
SyncUpdate = "update"
// SyncDelete binlog action.
SyncDelete = "delete"
)
// CanelMessage binlog message.
type CanelMessage struct {
Action string `json:"action"`
Table string `json:"table"`
New json.RawMessage `json:"new"`
Old json.RawMessage `json:"old"`
}
// OldCount .
type OldCount struct {
ID int64 `json:"id"`
Aid int64 `json:"aid"`
Count int64 `json:"count"`
CTime Stime `json:"ctime"`
MTime Stime `json:"mtime"`
}
// NewCount .
type NewCount struct {
ID int64 `json:"id"`
Type int8 `json:"type"`
Oid int64 `json:"oid"`
Count int64 `json:"count"`
CTime Stime `json:"ctime"`
MTime Stime `json:"mtime"`
}
// OldFolder .
type OldFolder struct {
ID int64 `json:"id"`
Mid int64 `json:"mid"`
Name string `json:"name"`
CurCount int `json:"cur_count"`
State int8 `json:"state"`
CTime Stime `json:"ctime"`
MTime Stime `json:"mtime"`
}
// NewFolder .
type NewFolder struct {
ID int64 `json:"id"`
Type int8 `json:"type"`
Mid int64 `json:"mid"`
Name string `json:"name"`
Count int `json:"count"`
Attr int8 `json:"attr"`
State int8 `json:"state"`
CTime Stime `json:"ctime"`
MTime Stime `json:"mtime"`
}
// VideoFolder .
type VideoFolder struct {
ID int64 `json:"id"`
Mid int64 `json:"mid"`
Fid int64 `json:"fid"`
VideoFid int64 `json:"video_fid"`
CTime Stime `json:"ctime"`
MTime Stime `json:"mtime"`
}
// OldVideo .
type OldVideo struct {
ID int64 `json:"id"`
Mid int64 `json:"mid"`
Fid int64 `json:"fid"`
Aid int64 `json:"aid"`
CTime Stime `json:"ctime"`
MTime Stime `json:"mtime"`
}
// NewRelation .
type NewRelation struct {
ID int64 `json:"id"`
Type int8 `json:"type"`
Mid int64 `json:"mid"`
Fid int64 `json:"fid"`
Oid int64 `json:"oid"`
State int8 `json:"state"`
CTime Stime `json:"ctime"`
MTime Stime `json:"mtime"`
}
// OldFolderSort .
type OldFolderSort struct {
ID int64 `json:"id"`
Mid int64 `json:"mid"`
Sort string `json:"sort"`
CTime Stime `json:"ctime"`
MTime Stime `json:"mtime"`
}
// NewFolderSort .
type NewFolderSort struct {
ID int64 `json:"id"`
Type int8 `json:"type"`
Mid int64 `json:"mid"`
Sort []byte `json:"sort"`
CTime Stime `json:"ctime"`
MTime Stime `json:"mtime"`
}
// Stime .
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)
if err == nil {
*st = Stime(t.Unix())
}
return nil
}
// StatMsg .
type StatMsg struct {
Play *int64 `json:"play"`
Fav *int64 `json:"fav"`
Share *int64 `json:"share"`
Oid int64 `json:"oid"`
}
// StatCount .
type StatCount struct {
Type string `json:"type"`
ID int64 `json:"id"`
Count int64 `json:"count"`
DisLike int64 `json:"dislike_count"`
TimeStamp int64 `json:"timestamp"`
}
// PlayReport .
type PlayReport struct {
ID int64 `json:"id"`
Mid int64 `json:"mid"`
LV string `json:"lv"`
IP string `json:"ip"`
Buvid string `json:"buvid"`
DeviceID string `json:"device_id"`
UA string `json:"ua"`
Refer string `json:"refer"`
TS int64 `json:"ts"`
}

View File

@@ -0,0 +1,19 @@
package model
const (
// type
FieldFav = "folder"
FieldArc = "video"
FieldResource = "resource"
// action
ActionAdd = "add"
ActionDel = "del"
ActionMove = "move"
ActionCopy = "copy"
ActionMdel = "mdel"
ActionIndef = "indef"
ActionIncol = "incol"
ActionClean = "clean"
ActionInitRelationFids = "initRelationFids"
ActionInitFolderRelations = "initFolderRelations"
)

View File

@@ -0,0 +1,12 @@
package model
type MusicResult struct {
Code int `json:"code"`
Data map[int64]*Music `json:"data"`
}
type Music struct {
ID int64 `json:"song_id"`
Cover string `json:"cover_url"`
Title string `json:"title"`
}

View File

@@ -0,0 +1,110 @@
package model
import (
"errors"
"go-common/library/time"
)
var (
// ErrFavVideoExist error video has been favoured.
ErrFavVideoExist = errors.New("error video has been favoured")
// ErrFavVideoAlreadyDel error video has been unfavoured.
ErrFavVideoAlreadyDel = errors.New("error video has been unfavoured")
)
const (
bit1 = int8(1)
bit2 = int8(1) << 1
// StateDefaultPublic default public folder.
StateDefaultPublic = int8(0) // binary 00 / int 0
// StateDefaultNoPublic default private folder.
StateDefaultNoPublic = int8(0) | bit1 // binary 01 / int 1
// StateNormalPublic nomal public folder.
StateNormalPublic = bit2 | int8(0) // binary 10 / int 2
// StateNormalNoPublic nomal private folder.
StateNormalNoPublic = bit2 | bit1 // binary 11 / int 3
// DefaultFolderName name of favorite folder.
DefaultFolderName = "默认收藏夹"
)
// Favorite .
type Favorite struct {
Fid int64 `json:"fid"`
Mid int64 `json:"mid"`
Name string `json:"name"`
MaxCount int `json:"max_count"`
CurCount int `json:"cur_count"`
AttenCount int `json:"atten_count"`
State int8 `json:"state"`
CTime time.Time `json:"ctime"`
MTime time.Time `json:"-"`
Cover []*Cover `json:"cover,omitempty"`
}
// Archive .
type Archive struct {
ID int64 `json:"id"`
Mid int64 `json:"mid"`
Fid int64 `json:"fid"`
Aid int64 `json:"aid"`
CTime time.Time `json:"-"`
MTime time.Time `json:"-"`
}
// IsPublic return true if folder is public.
func (f *Favorite) IsPublic() bool {
return f.State&bit1 == int8(0)
}
// IsDefault return true if folder is default.
func (f *Favorite) IsDefault() bool {
return f.State&bit2 == int8(0)
}
// StatePub return folder's public state.
func (f *Favorite) StatePub() int8 {
return f.State & bit1
}
// StateDef return folder's default state.
func (f *Favorite) StateDef() int8 {
return f.State & bit2
}
// IsDefault return true if state is default state.
func IsDefault(state int8) bool {
return (state&(int8(1)<<1) == int8(0))
}
// CheckPublic check user update public value in [0, 1].
func CheckPublic(state int8) bool {
return state == int8(0) || state == bit1
}
// Favorites .
type Favorites []*Favorite
func (f Favorites) Len() int { return len(f) }
func (f Favorites) Less(i, j int) bool {
if f[i].State < f[j].State {
return true
}
if f[i].State == f[j].State && f[i].MaxCount > f[j].MaxCount {
return true
}
if f[i].State == f[j].State && f[i].MaxCount <= f[j].MaxCount && f[i].CTime < f[j].CTime {
return true
}
return false
}
func (f Favorites) Swap(i, j int) { f[i], f[j] = f[j], f[i] }
// Cover image
type Cover struct {
Aid int64 `json:"aid"`
Pic string `json:"pic"`
}