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,36 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"history.go",
"rpc.go",
"toview.go",
],
importpath = "go-common/app/interface/main/history/model",
tags = ["automanaged"],
deps = [
"//app/service/main/archive/model/archive:go_default_library",
"//app/service/main/history/model:go_default_library",
"//library/ecode: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,187 @@
package model
import (
"go-common/app/service/main/archive/model/archive"
"go-common/library/ecode"
)
// const .
const (
// TypeUnknown unkown
TypeUnknown = int8(-1)
// TypeOffline offline
TypeOffline = int8(0)
// TypeBangumi bangumi
TypeBangumi = int8(1)
// TypeMovie movie
TypeMovie = int8(2)
// TypeUGC UGC
TypeUGC = int8(3)
// TypePGC PGC
TypePGC = int8(4)
// TypeArticle Article
TypeArticle = int8(5)
// TypeLive Live
TypeLive = int8(6)
// TypeCorpus corpus
TypeCorpus = int8(7)
// TypeComic comic
TypeComic = int8(8)
// SubTypeOffline archive subtype
SubTypeOffline = int8(1)
// SubTypeBangumi bangumi
SubTypeBangumi = int8(1)
// SubTypeFilm film
SubTypeFilm = int8(2)
// SubTypeDoc documentary
SubTypeDoc = int8(3)
// SubTypeNation nation
SubTypeNation = int8(4)
// SubTypeTV TV
SubTypeTV = int8(5)
// DeviceUnknown unknown
DeviceUnknown = int8(0)
// DeviceIphone iphoneTV
DeviceIphone = int8(1)
// DevicePC PC
DevicePC = int8(2)
// DeviceAndroid android
DeviceAndroid = int8(3)
// DeviceAndroidTV android TV
DeviceAndroidTV = int8(33)
// DeviceIpad ipad
DeviceIpad = int8(4)
// DeviceWP8 WP8
DeviceWP8 = int8(5)
// DeviceUWP UWP
DeviceUWP = int8(6)
// ShadowUnknown unknown
ShadowUnknown = int64(-1)
// ShadowOff off
ShadowOff = int64(0)
// ShadowOn on
ShadowOn = int64(1)
// ProComplete progress complete
ProComplete = int64(-1)
// PlatformAndroid platform android.
PlatformAndroid string = "android"
// PlatformIOS platform ios.
PlatformIOS string = "ios"
// DevicePad device pad.
DevicePad string = "pad"
// MobileAppAndroidTV mobile app android tv.
MobileAppAndroidTV string = "android_tv_yst"
HistoryLog = 171
HistoryClear = "history_clear"
HistoryClearTyp = "history_clear_%s"
ToviewClear = "toview_clear"
)
var businesses = map[string]int8{
"pgc": TypePGC,
"article": TypeArticle,
"archive": TypeUGC,
"live": TypeLive,
"article-list": TypeCorpus,
"comic": TypeComic,
}
var businessIDs = map[int8]string{
TypeOffline: "archive",
TypeMovie: "pgc",
TypeBangumi: "pgc",
TypePGC: "pgc",
TypeArticle: "article",
TypeUGC: "archive",
TypeLive: "live",
TypeCorpus: "article-list",
TypeComic: "comic",
}
// BusinessByTP .
func BusinessByTP(b int8) string {
return businessIDs[b]
}
// CheckBusiness .
func CheckBusiness(bs string) (tp int8, err error) {
if bs == "" {
return
}
tp, ok := businesses[bs]
if !ok {
err = ecode.AppDenied
}
return
}
// MustCheckBusiness .
func MustCheckBusiness(bs string) (tp int8, err error) {
if bs == "" {
err = ecode.RequestErr
return
}
tp, ok := businesses[bs]
if !ok {
err = ecode.AppDenied
}
return
}
// Merge report merge in history.
type Merge struct {
Mid int64 `json:"mid"`
Now int64 `json:"now"`
}
// Video video history.
type Video struct {
*archive.Archive3
Favorite bool `json:"favorite"` // video favorite
TP int8 `json:"type"` // video type
STP int8 `json:"sub_type"` // video type
DT int8 `json:"device"` // device type
Page *archive.Page3 `json:"page,omitempty"`
Count int `json:"count,omitempty"`
BangumiInfo *Bangumi `json:"bangumi,omitempty"`
Progress int64 `json:"progress"`
ViewAt int64 `json:"view_at"`
}
// Season season.
type Season struct {
ID int64 `json:"season_id"`
Title string `json:"title"`
SeasonStatus int `json:"season_status"`
IsFinish int `json:"is_finish"`
TotalCount int32 `json:"total_count"`
NewestEpid int64 `json:"newest_ep_id"`
NewestEpIndex string `json:"newest_ep_index"`
SeasonType int `json:"season_type,omitempty"`
Mode int `json:"mode,omitempty"`
}
// Bangumi bangumi.
type Bangumi struct {
Epid int64 `json:"ep_id"`
Title string `json:"title"`
LongTitle string `json:"long_title"`
EpisodeStatus int `json:"episode_status"`
Follow int `json:"follow"`
Cover string `json:"cover"`
Season *Season `json:"season"`
}
// BangumiSeason season.
type BangumiSeason struct {
ID int64 `json:"season_id"`
Epid int64 `json:"episode_id"`
EpidType int64 `json:"season_type"`
}

View File

@@ -0,0 +1,173 @@
package model
import hismdl "go-common/app/service/main/history/model"
// History video hisotry info.
type History struct {
Mid int64 `json:"mid,omitempty"`
Aid int64 `json:"aid"`
Sid int64 `json:"sid,omitempty"`
Epid int64 `json:"epid,omitempty"`
TP int8 `json:"tp,omitempty"`
Business string `json:"business"`
STP int8 `json:"stp,omitempty"` // sub_type
Cid int64 `json:"cid,omitempty"`
DT int8 `json:"dt,omitempty"`
Pro int64 `json:"pro,omitempty"`
Unix int64 `json:"view_at"`
}
// Histories history sorted.
type Histories []*History
func (h Histories) Len() int { return len(h) }
func (h Histories) Less(i, j int) bool {
if h[i].Unix == h[j].Unix {
return h[i].Aid < h[j].Aid
}
return h[i].Unix > h[j].Unix
}
func (h Histories) Swap(i, j int) { h[i], h[j] = h[j], h[i] }
// FillBusiness add history
func (h *History) FillBusiness() {
if h == nil {
return
}
h.Business = businessIDs[h.TP]
}
// ConvertType convert old type
func (h *History) ConvertType() {
if h == nil {
return
}
switch h.TP {
case TypeBangumi:
h.TP = TypePGC
h.STP = SubTypeBangumi
case TypeMovie:
h.TP = TypePGC
h.STP = SubTypeFilm
case TypePGC:
if h.Epid == 0 || h.Sid == 0 {
h.TP = TypeUGC
}
}
}
// ConvertServiceType .
func (h History) ConvertServiceType() (r *hismdl.History) {
switch h.TP {
case TypeOffline:
h.TP = TypeUGC
h.STP = SubTypeOffline
case TypeUnknown:
h.TP = TypeUGC
case TypeBangumi:
h.TP = TypePGC
h.STP = SubTypeBangumi
case TypeMovie:
h.TP = TypePGC
h.STP = SubTypeFilm
}
if h.TP == TypePGC && (h.Epid == 0 || h.Sid == 0) {
h.TP = TypeUGC
}
h.FillBusiness()
r = &hismdl.History{
Mid: h.Mid,
BusinessID: int64(h.TP),
Business: h.Business,
Kid: h.Aid,
Aid: h.Aid,
Sid: h.Sid,
Epid: h.Epid,
Cid: h.Cid,
SubType: int32(h.STP),
Device: int32(h.DT),
Progress: int32(h.Pro),
ViewAt: h.Unix,
}
if h.TP == TypePGC {
r.Kid = r.Sid
}
return
}
// ArgPro arg.
type ArgPro struct {
Mid int64
RealIP string
Aids []int64
}
// ArgPos arg.
type ArgPos struct {
Mid int64
Aid int64
Business string
TP int8
RealIP string
}
// ArgDelete arg.
type ArgDelete struct {
Mid int64
RealIP string
Resources []*Resource
}
// ArgHistory arg.
type ArgHistory struct {
Mid int64
Realtime int64
RealIP string
History *History
}
// ArgHistories arg.
type ArgHistories struct {
Mid int64
TP int8
Business string
Pn int
Ps int
RealIP string
}
// ArgCursor arg.
type ArgCursor struct {
Mid int64
Max int64
TP int8
// history business
Business string
ViewAt int64
// filter business, blank means all business
Businesses []string
Ps int
RealIP string
}
// Resource video hisotry info .
type Resource struct {
Mid int64 `json:"mid,omitempty"`
Oid int64 `json:"oid"`
Sid int64 `json:"sid,omitempty"`
Epid int64 `json:"epid,omitempty"`
TP int8 `json:"tp,omitempty"`
STP int8 `json:"stp,omitempty"` // sub_type
Cid int64 `json:"cid,omitempty"`
Business string `json:"business"`
DT int8 `json:"dt,omitempty"`
Pro int64 `json:"pro,omitempty"`
Unix int64 `json:"view_at"`
}
// ArgClear .
type ArgClear struct {
Mid int64
RealIP string
Businesses []string
}

View File

@@ -0,0 +1,37 @@
package model
import (
"go-common/app/service/main/archive/model/archive"
)
// ArcToView toview video.
type ArcToView struct {
*archive.Archive3
Page *archive.Page3 `json:"page,omitempty"`
Count int `json:"count"`
Cid int64 `json:"cid"`
Progress int64 `json:"progress"`
AddTime int64 `json:"add_at"`
}
// WebArcToView toview video.
type WebArcToView struct {
*archive.View3
BangumiInfo *Bangumi `json:"bangumi,omitempty"`
Cid int64 `json:"cid"`
Progress int64 `json:"progress"`
AddTime int64 `json:"add_at"`
}
// ToView toview.
type ToView struct {
Aid int64 `json:"aid,omitempty"`
Unix int64 `json:"now,omitempty"`
}
// ToViews toview sorted.
type ToViews []*ToView
func (h ToViews) Len() int { return len(h) }
func (h ToViews) Less(i, j int) bool { return h[i].Unix > h[j].Unix }
func (h ToViews) Swap(i, j int) { h[i], h[j] = h[j], h[i] }