Initial commit

This commit is contained in:
Donny
2019-04-22 20:46:32 +08:00
commit 49ab8aadd1
25441 changed files with 4055000 additions and 0 deletions

View File

@@ -0,0 +1,87 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
load(
"@io_bazel_rules_go//proto:def.bzl",
"go_proto_library",
)
go_test(
name = "go_default_test",
srcs = ["article_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = ["//vendor/github.com/smartystreets/goconvey/convey:go_default_library"],
)
go_library(
name = "go_default_library",
srcs = [
"activity.go",
"apply.go",
"article.go",
"author.go",
"cards.go",
"creation.go",
"hotspots.go",
"infoc.go",
"list.go",
"rank.go",
"rpc.go",
"setting.go",
"sort.go",
],
embed = [":model_go_proto"],
importpath = "go-common/app/interface/openplatform/article/model",
tags = ["automanaged"],
deps = [
"//app/interface/main/creative/model/data:go_default_library",
"//app/service/main/account/model:go_default_library",
"//library/time:go_default_library",
"@com_github_gogo_protobuf//gogoproto:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
],
)
proto_library(
name = "model_proto",
srcs = ["model.proto"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
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/interface/openplatform/article/model",
proto = ":model_proto",
tags = ["manual"],
visibility = ["//visibility:public"],
deps = [
"//library/time:go_default_library",
"@com_github_gogo_protobuf//gogoproto:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [
":package-srcs",
"//app/interface/openplatform/article/model/search:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,44 @@
package model
// ActInfo .
type ActInfo struct {
Activities []*Activity `json:"activities"`
Banners []*Banner `json:"banners"`
}
// AnniversaryInfo .
type AnniversaryInfo struct {
Mid int64 `json:"mid"`
Uname string `json:"uname"`
Face string `json:"face"`
ReaderInfo *AnniversaryReader `json:"reader_info"`
AuthorInfo *AnniversaryAuthor `json:"author_info"`
}
// AnniversaryAuthor .
type AnniversaryAuthor struct {
Articles int32 `json:"articles"`
Words int64 `json:"words"`
Views int64 `json:"views"`
Coins int64 `json:"coins"`
Title string `json:"title"`
Publish string `json:"publish"`
Rank string `json:"rank"`
ReaderMid int64 `json:"reader"`
ReaderUname string `json:"reader_name"`
ReaderFace string `json:"reader_face"`
}
// AnniversaryReader .
type AnniversaryReader struct {
Words int64 `json:"words"`
Views int64 `json:"views"`
Coins int64 `json:"coins"`
Comments int64 `json:"comments"`
Title string `json:"title"`
AuthorMid int64 `json:"author"`
AuthorUname string `json:"author_name"`
Rank string `json:"rank"`
FirstComment string `json:"first_comment"`
CommentDate string `json:"comment_date"`
}

View File

@@ -0,0 +1,14 @@
package model
//Apply apply model
type Apply struct {
Verify bool `json:"verify"`
Forbid bool `json:"forbid"`
Phone int `json:"phone"`
}
// Identify user verify info.
type Identify struct {
Identify int `json:"identify"`
Phone int `json:"phone"`
}

View File

@@ -0,0 +1,750 @@
package model
import (
"fmt"
"regexp"
"strconv"
"strings"
account "go-common/app/service/main/account/model"
xtime "go-common/library/time"
)
// Const .
const (
// State
StateAutoLock = -11
StateLock = -10
StateReject = -3
StatePending = -2
StateOpen = 0
StateOpenPending = 2
StateOpenReject = 3
StateAutoPass = 4
StateRePending = 5 // 重复编辑待审
StateReReject = 6 // 重复编辑未通过
StateRePass = 7 // 重复编辑通过
// groups for creation center.
GroupAll = 0 // except draft and deleted. 0 2 -2 3 -3 -10
GroupPending = 1 // -2 2
GroupPassed = 2 // 0
GroupUnpassed = 3 // -10 -3 3
NoLikeState = 0
LikeState = 1
DislikeState = 2
// Templates
TemplateText = 1
TemplateSingleImg = 2
TemplateMultiImg = 3
TemplateSingleBigImg = 4
// Attributes
//AttrBitNoDistribute 禁止分发(空间/分区/动态)
AttrBitNoDistribute = uint(1)
//AttrBitNoRegion 禁止在分区页显示
AttrBitNoRegion = uint(2)
//AttrBitNoRank 禁止排行
AttrBitNoRank = uint(3)
// Author
// AuthorStatePass 过审
AuthorStateReject = -1
AuthorStatePending = 0
AuthorStatePass = 1
AuthorStateClose = 2
// AuthorStateIgnore = 3
)
var cleanURLRegexp = regexp.MustCompile(`^.+hdslb.com`)
var bfsRegexp = regexp.MustCompile(`^https?://.{1,6}\.hdslb+\.com/.+(?:jpg|gif|png|webp|jpeg)$`)
// Categories for sorting category.
type Categories []*Category
func (as Categories) Len() int { return len(as) }
func (as Categories) Less(i, j int) bool {
return as[i].Position < as[j].Position
}
func (as Categories) Swap(i, j int) { as[i], as[j] = as[j], as[i] }
// StatMsg means article's stat message in databus.
type StatMsg struct {
View *int64 `json:"view"`
Like *int64 `json:"like"`
Dislike *int64 `json:"dislike"`
Favorite *int64 `json:"fav"`
Reply *int64 `json:"reply"`
Share *int64 `json:"share"`
Coin *int64 `json:"coin"`
Aid int64 `json:"aid"`
Mid int64 `json:"mid"`
IP string `json:"ip"`
CheatInfo *CheatInfo `json:"cheat_info"`
}
func (sm *StatMsg) String() (res string) {
if sm == nil {
res = "<nil>"
return
}
res = fmt.Sprintf("aid: %v, mid: %v, ip: %v, view(%s) likes(%s) dislike(%s) favorite(%s) reply(%s) share(%s) coin(%s)", sm.Aid, sm.Mid, sm.IP, formatPInt(sm.View), formatPInt(sm.Like), formatPInt(sm.Dislike), formatPInt(sm.Favorite), formatPInt(sm.Reply), formatPInt(sm.Share), formatPInt(sm.Coin))
return
}
// CheatInfo .
type CheatInfo struct {
Valid string `json:"valid"`
Client string `json:"client"`
Cvid string `json:"cvid"`
Mid string `json:"mid"`
Lv string `json:"lv"`
Ts string `json:"ts"`
IP string `json:"ip"`
UA string `json:"ua"`
Refer string `json:"refer"`
Sid string `json:"sid"`
Buvid string `json:"buvid"`
DeviceID string `json:"device_id"`
Build string `json:"build"`
Reason string `json:"reason"`
}
func formatPInt(s *int64) (res string) {
if s == nil {
return "<nil>"
}
return fmt.Sprintf("%d", *s)
}
// DraftMsg means article's draft message in databus.
type DraftMsg struct {
Aid int64 `json:"aid"`
Mid int64 `json:"mid"`
}
// Draft draft struct.
type Draft struct {
*Article
Tags []string `json:"tags"`
ListID int64 `json:"list_id"`
List *List `json:"list"`
}
// Metas Metas
type Metas []*Meta
func (as Metas) Len() int { return len(as) }
func (as Metas) Less(i, j int) bool {
var it, jt xtime.Time
if as[i] != nil {
it = as[i].PublishTime
}
if as[j] != nil {
jt = as[j].PublishTime
}
return it > jt
}
func (as Metas) Swap(i, j int) { as[i], as[j] = as[j], as[i] }
// CreationArtsType creation article-list type's count.
type CreationArtsType struct {
All int `json:"all"`
Audit int `json:"audit"`
Passed int `json:"passed"`
NotPassed int `json:"not_passed"`
}
// ArtPage article page.
type ArtPage struct {
Pn int `json:"pn"`
Ps int `json:"ps"`
Total int `json:"total"`
}
// CreationArts creation article list.
type CreationArts struct {
Articles []*Meta `json:"articles"`
Type *CreationArtsType `json:"type"`
Page *ArtPage `json:"page"`
}
// Drafts draft list.
type Drafts struct {
Drafts []*Draft `json:"drafts"`
Page *ArtPage `json:"page"`
}
// UpArtMetas article list.
type UpArtMetas struct {
Articles []*Meta `json:"articles"`
Pn int `json:"pn"`
Ps int `json:"ps"`
Count int `json:"count"`
}
// UpArtMetasLists .
type UpArtMetasLists struct {
*UpArtMetas
UpLists UpLists `json:"up_lists"`
}
// IsNormal judge whether article's state is normal.
func (a *Meta) IsNormal() bool {
return (a != nil) && (a.State >= StateOpen)
}
// IsNormal judge article state.
func (a *Article) IsNormal() bool {
if (a == nil) || (a.Meta == nil) {
return false
}
return a.Meta.IsNormal()
}
// AttrVal gets attr val by bit.
func (a *Meta) AttrVal(bit uint) bool {
return ((a.Attributes>>bit)&int32(1) == 1)
}
// AttrSet sets attr value by bit.
func (a *Meta) AttrSet(v int32, bit uint) {
a.Attributes = a.Attributes&(^(1 << bit)) | (v << bit)
}
// Strong fill blank images and tags
func (a *Meta) Strong() *Meta {
if a.ImageURLs == nil {
a.ImageURLs = []string{}
}
if a.OriginImageURLs == nil {
a.OriginImageURLs = []string{}
}
if a.Tags == nil {
a.Tags = []*Tag{}
}
return a
}
// AuthorPermission recode of article_authors table.
type AuthorPermission struct {
State int `json:"state"`
Rtime xtime.Time `json:"rtime"`
}
// Favorite user favorite list.
type Favorite struct {
*Meta
FavoriteTime int64 `json:"favorite_time"`
Valid bool `json:"valid"`
}
// Page model
type Page struct {
Pn int `json:"pn"`
Ps int `json:"ps"`
Total int `json:"total"`
}
// RecommendArt model
type RecommendArt struct {
Meta
Recommend
}
// RecommendArtWithLike model
type RecommendArtWithLike struct {
RecommendArt
LikeState int `json:"like_state"`
}
// MetaWithLike meta with like
type MetaWithLike struct {
Meta
LikeState int `json:"like_state"`
}
// Recommend model
type Recommend struct {
ArticleID int64 `json:"article_id,omitempty"`
Position int `json:"-"`
EndTime int64 `json:"-"`
Rec bool `json:"rec"`
RecFlag bool `json:"rec_flag"`
RecText string `json:"rec_text"`
RecImageURL string `json:"rec_image_url"`
RecImageStartTime int64 `json:"-"`
RecImageEndTime int64 `json:"-"`
}
// ViewInfo model
type ViewInfo struct {
Like int8 `json:"like"`
Attention bool `json:"attention"`
Favorite bool `json:"favorite"`
Coin int64 `json:"coin"`
Stats Stats `json:"stats"`
Title string `json:"title"`
BannerURL string `json:"banner_url"`
Mid int64 `json:"mid"`
AuthorName string `json:"author_name"`
IsAuthor bool `json:"is_author"`
ImageURLs []string `json:"image_urls"`
OriginImageURLs []string `json:"origin_image_urls"`
Shareable bool `json:"shareable"`
ShowLaterWatch bool `json:"show_later_watch"`
ShowSmallWindow bool `json:"show_small_window"`
InList bool `json:"in_list"`
Pre int64 `json:"pre"`
Next int64 `json:"next"`
}
// Group2State mapping creation group to
func Group2State(group int) (states []int64) {
switch group {
case GroupPassed:
states = []int64{StateOpen, StateAutoPass, StateRePass, StateReReject}
case GroupPending:
states = []int64{StatePending, StateOpenPending, StateRePending}
case GroupUnpassed:
states = []int64{StateReject, StateOpenReject, StateLock, StateAutoLock}
case GroupAll:
fallthrough
default:
states = []int64{StateOpen, StatePending, StateOpenPending, StateReject, StateOpenReject, StateLock, StateAutoPass, StateAutoLock, StateRePending, StateRePass, StateReReject}
}
return
}
// CompleteURL adds host on path.
func CompleteURL(path string) (url string) {
if path == "" {
// url = "http://static.hdslb.com/images/transparent.gif"
return
}
url = path
if strings.Index(path, "//") == 0 || strings.Index(path, "http://") == 0 || strings.Index(path, "https://") == 0 {
return
}
url = "https://i0.hdslb.com" + url
return
}
// CleanURL cuts host.
func CleanURL(url string) (path string) {
path = string(cleanURLRegexp.ReplaceAll([]byte(url), nil))
return
}
// CompleteURLs .
func CompleteURLs(paths []string) (urls []string) {
for _, v := range paths {
urls = append(urls, CompleteURL(v))
}
return
}
// CleanURLs .
func CleanURLs(urls []string) (paths []string) {
for _, v := range urls {
paths = append(paths, CleanURL(v))
}
return
}
// Recommends model
type Recommends [][]*Recommend
func (as Recommends) Len() int { return len(as) }
func (as Recommends) Less(i, j int) bool {
return as[i][0].Position > as[j][0].Position
}
func (as Recommends) Swap(i, j int) { as[i], as[j] = as[j], as[i] }
// RecommendHome .
type RecommendHome struct {
RecommendPlus
Categories []*Category `json:"categories"`
IP string `json:"ip"`
}
// RecommendPlus .
type RecommendPlus struct {
Banners []*Banner `json:"banners"`
Articles []*RecommendArtWithLike `json:"articles"`
Ranks []*RankMeta `json:"ranks"`
Hotspots []*Hotspot `json:"hotspots"`
}
// Banner struct
type Banner struct {
ID int `json:"id"`
Plat int8 `json:"-"`
Position int `json:"index"`
Title string `json:"title"`
Image string `json:"image"`
URL string `json:"url"`
Build int `json:"-"`
Condition string `json:"-"`
Rule string `json:"-"`
ResID int `json:"resource_id"`
ServerType int `json:"server_type"`
CmMark int `json:"cm_mark"`
IsAd bool `json:"is_ad"`
RequestID string `json:"request_id"`
}
// ConvertPlat convert plat from resource
func ConvertPlat(p int8) (plat int8) {
switch p {
case 0: // resource iphone
plat = PlatPC
case 1: // resource iphone
plat = PlatIPhone
case 2: // resource android
plat = PlatAndroid
case 3: // resource pad
plat = PlatIPad
case 4: // resource iphoneg
plat = PlatIPhoneI
case 5: // resource androidg
plat = PlatAndroidG
case 6: // resource padg
plat = PlatIPadI
case 7: // resource h5
plat = PlatH5
case 8: // resource androidi
plat = PlatAndroidI
}
return
}
// BannerRule .
type BannerRule struct {
Area string `json:"area"`
Hash string `json:"hash"`
Build int `json:"build"`
Condition string `json:"conditions"`
Channel string `json:"channel"`
}
// NoDistributeAttr check if no distribute
func NoDistributeAttr(attr int32) bool {
meta := Meta{Attributes: attr}
return meta.AttrVal(AttrBitNoDistribute)
}
// NoRegionAttr check if no region
func NoRegionAttr(attr int32) bool {
meta := Meta{Attributes: attr}
return meta.AttrVal(AttrBitNoRegion)
}
// AuthorLimit .
type AuthorLimit struct {
Limit int `json:"limit"`
State int `json:"state"`
Rtime xtime.Time `json:"rtime"`
}
// Forbid .
func (a *AuthorLimit) Forbid() bool {
// state -1 未通过 0待审 1通过 2关闭 3忽略
if a == nil {
return false
}
if a.State == AuthorStatePass {
return false
}
return true
}
// Pass .
func (a *AuthorLimit) Pass() bool {
return (a != nil) && (a.State == AuthorStatePass)
}
// Notice notice
type Notice struct {
ID int64 `json:"id"`
Title string `json:"title"`
Content string `json:"content"`
URL string `json:"url"`
Plat int `json:"-"`
Condition int `json:"-"`
Build int `json:"-"`
}
// MoreArts .
type MoreArts struct {
Articles []*Meta `json:"articles"`
Total int `json:"total"`
ReadCount int64 `json:"read_count"`
Author *AccountCard `json:"author"`
Attention bool `json:"attention"`
}
// AccountCard .
type AccountCard struct {
Mid string `json:"mid"`
Name string `json:"name"`
Approve bool `json:"approve"`
Sex string `json:"sex"`
Rank string `json:"rank"`
Face string `json:"face"`
DisplayRank string `json:"DisplayRank"`
Regtime int64 `json:"regtime"`
Spacesta int `json:"spacesta"`
Birthday string `json:"birthday"`
Place string `json:"place"`
Description string `json:"description"`
Article int `json:"article"`
Attentions []int64 `json:"attentions"`
Fans int `json:"fans"`
Friend int `json:"friend"`
Attention int `json:"attention"`
Sign string `json:"sign"`
LevelInfo struct {
Cur int `json:"current_level"`
Min int `json:"current_min"`
NowExp int `json:"current_exp"`
NextExp interface{} `json:"next_exp"`
} `json:"level_info"`
Pendant struct {
Pid int `json:"pid"`
Name string `json:"name"`
Image string `json:"image"`
Expire int `json:"expire"`
} `json:"pendant"`
Nameplate struct {
Nid int `json:"nid"`
Name string `json:"name"`
Image string `json:"image"`
ImageSmall string `json:"image_small"`
Level string `json:"level"`
Condition string `json:"condition"`
} `json:"nameplate"`
OfficialVerify struct {
Type int `json:"type"`
Desc string `json:"desc"`
} `json:"official_verify"`
Vip struct {
Type int `json:"vipType"`
DueDate int64 `json:"vipDueDate"`
DueRemark string `json:"dueRemark"`
AccessStatus int `json:"accessStatus"`
VipStatus int `json:"vipStatus"`
VipStatusWarn string `json:"vipStatusWarn"`
} `json:"vip"`
}
// FromCard from account card.
func (ac *AccountCard) FromCard(card *account.Card) {
ac.Mid = strconv.FormatInt(card.Mid, 10)
ac.Name = card.Name
// ac.Approve =
ac.Sex = card.Sex
ac.Rank = strconv.FormatInt(int64(card.Rank), 10)
ac.Face = card.Face
ac.DisplayRank = strconv.FormatInt(int64(card.Rank), 10)
// ac.Regtime =
// ac.Spacesta =
// ac.Birthday =
// ac.Place =
// ac.Description =
// ac.Article =
ac.Attentions = []int64{}
// ac.Fans =
// ac.Friend =
// ac.Attention =
ac.Sign = card.Sign
ac.LevelInfo.Cur = int(card.Level)
ac.Pendant.Pid = card.Pendant.Pid
ac.Pendant.Name = card.Pendant.Name
ac.Pendant.Image = card.Pendant.Image
ac.Pendant.Expire = card.Pendant.Expire
ac.Nameplate.Nid = card.Nameplate.Nid
ac.Nameplate.Name = card.Nameplate.Name
ac.Nameplate.Image = card.Nameplate.Image
ac.Nameplate.ImageSmall = card.Nameplate.ImageSmall
ac.Nameplate.Level = card.Nameplate.Level
ac.Nameplate.Condition = card.Nameplate.Condition
if card.Official.Role == 0 {
ac.OfficialVerify.Type = -1
} else {
if card.Official.Role <= 2 {
ac.OfficialVerify.Type = 0
} else {
ac.OfficialVerify.Type = 1
}
ac.OfficialVerify.Desc = card.Official.Title
}
ac.Vip.Type = int(card.Vip.Type)
ac.Vip.VipStatus = int(card.Vip.Status)
ac.Vip.DueDate = card.Vip.DueDate
}
// FromProfileStat .
func (ac *AccountCard) FromProfileStat(card *account.ProfileStat) {
ac.Mid = strconv.FormatInt(card.Mid, 10)
ac.Name = card.Name
// ac.Approve =
ac.Sex = card.Sex
ac.Rank = strconv.FormatInt(int64(card.Rank), 10)
ac.Face = card.Face
ac.DisplayRank = strconv.FormatInt(int64(card.Rank), 10)
// ac.Regtime =
// ac.Spacesta =
// ac.Birthday =
// ac.Place =
// ac.Description =
// ac.Article =
ac.Attentions = []int64{}
ac.Fans = int(card.Follower)
// ac.Friend =
// ac.Attention =
ac.Sign = card.Sign
ac.LevelInfo.Cur = int(card.Level)
ac.Pendant.Pid = card.Pendant.Pid
ac.Pendant.Name = card.Pendant.Name
ac.Pendant.Image = card.Pendant.Image
ac.Pendant.Expire = card.Pendant.Expire
ac.Nameplate.Nid = card.Nameplate.Nid
ac.Nameplate.Name = card.Nameplate.Name
ac.Nameplate.Image = card.Nameplate.Image
ac.Nameplate.ImageSmall = card.Nameplate.ImageSmall
ac.Nameplate.Level = card.Nameplate.Level
ac.Nameplate.Condition = card.Nameplate.Condition
if card.Official.Role == 0 {
ac.OfficialVerify.Type = -1
} else {
if card.Official.Role <= 2 {
ac.OfficialVerify.Type = 0
} else {
ac.OfficialVerify.Type = 1
}
ac.OfficialVerify.Desc = card.Official.Title
}
ac.Vip.Type = int(card.Vip.Type)
ac.Vip.VipStatus = int(card.Vip.Status)
ac.Vip.DueDate = card.Vip.DueDate
}
// NoticeState .
type NoticeState map[string]bool
// 数据库为tinyint 长度必须小于7 字段只能追加
var _noticeStates = []string{"lead", "new"}
// NewNoticeState .
func NewNoticeState(value int64) (res NoticeState) {
res = make(map[string]bool)
for i, name := range _noticeStates {
res[name] = ((value>>uint(i))&int64(1) == 1)
}
return
}
// ToInt64 .
func (n NoticeState) ToInt64() (res int64) {
for i, name := range _noticeStates {
if n[name] {
res = res | (1 << uint(i))
}
}
return
}
// Activity .
type Activity struct {
ActURL string `json:"act_url"`
Author string `json:"author"`
Cover string `json:"cover"`
Ctime string `json:"ctime"`
Dic string `json:"dic"`
Etime string `json:"etime"`
Flag string `json:"flag"`
H5Cover string `json:"h5_cover"`
ID int64 `json:"id"`
Letime string `json:"letime"`
Level string `json:"level"`
Lstime string `json:"lstime"`
Mtime string `json:"mtime"`
Name string `json:"name"`
Oid int64 `json:"oid"`
State int64 `json:"state"`
Stime string `json:"stime"`
Tags string `json:"tags"`
Type int64 `json:"type"`
Uetime string `json:"uetime"`
Ustime string `json:"ustime"`
}
// SkyHorseResp response
type SkyHorseResp struct {
Code int `json:"code"`
Data []struct {
ID int64 `json:"id"`
AvFeature string `json:"av_feature"`
} `json:"data"`
UserFeature string `json:"user_feature"`
}
// CheckBFSImage check bfs file
func CheckBFSImage(src string) bool {
return bfsRegexp.MatchString(src)
}
// FillDefaultImage .
func (l *List) FillDefaultImage(image string) {
if l != nil && l.ImageURL == "" {
l.ImageURL = image
}
}
// Articles .
type Articles struct {
*Article
Pre int64 `json:"pre"`
Next int64 `json:"next"`
}
// ArticleViewList .
type ArticleViewList struct {
Position int `json:"position"`
Aids []int64 `json:"articles_id"`
From string `json:"from"`
Mid int64 `json:"mid"`
Build int `json:"build"`
Buvid string `json:"buvid"`
Plat int8 `json:"plat"`
}
// TagArts .
type TagArts struct {
Tid int64 `json:"tid"`
Aids []int64 `json:"aids"`
}
// MediaResp .
type MediaResp struct {
Code int `json:"code"`
Message string `json:"message"`
Result *MediaResult `json:"result"`
}
// MediaResult .
type MediaResult struct {
Score int32 `json:"score"`
Media struct {
MediaID int64 `json:"media_id"`
Title string `json:"title"`
Cover string `json:"cover"`
Area string `json:"area"`
TypeID int32 `json:"type_id"`
TypeName string `json:"type_name"`
} `json:"media"`
}

View File

@@ -0,0 +1,58 @@
package model
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestCleanURL(t *testing.T) {
Convey("different urls", t, func() {
url := "/bfs/article/3b8b57821a94af4c171218a01d9cee44dc0dccf8.jpg"
So(CleanURL("http://i0.hdslb.com/bfs/article/3b8b57821a94af4c171218a01d9cee44dc0dccf8.jpg"), ShouldEqual, url)
So(CleanURL("https://i0.hdslb.com/bfs/article/3b8b57821a94af4c171218a01d9cee44dc0dccf8.jpg"), ShouldEqual, url)
So(CleanURL("//i0.hdslb.com/bfs/article/3b8b57821a94af4c171218a01d9cee44dc0dccf8.jpg"), ShouldEqual, url)
So(CleanURL("http://uat-i0.hdslb.com/bfs/article/3b8b57821a94af4c171218a01d9cee44dc0dccf8.jpg"), ShouldEqual, url)
So(CleanURL("https://uat-i0.hdslb.com/bfs/article/3b8b57821a94af4c171218a01d9cee44dc0dccf8.jpg"), ShouldEqual, url)
So(CleanURL("//uat-i0.hdslb.com/bfs/article/3b8b57821a94af4c171218a01d9cee44dc0dccf8.jpg"), ShouldEqual, url)
})
}
func TestCompleteURL(t *testing.T) {
Convey("prefix http", t, func() {
url := "http://i0.hdslb.com/bfs/article/3b8b57821a94af4c171218a01d9cee44dc0dccf8.jpg"
So(CompleteURL(url), ShouldEqual, url)
})
Convey("prefix https", t, func() {
url := "https://i0.hdslb.com/bfs/article/3b8b57821a94af4c171218a01d9cee44dc0dccf8.jpg"
So(CompleteURL(url), ShouldEqual, url)
})
Convey("prefix //", t, func() {
url := "//i0.hdslb.com/bfs/article/3b8b57821a94af4c171218a01d9cee44dc0dccf8.jpg"
So(CompleteURL(url), ShouldEqual, url)
})
Convey("prefix no prefix", t, func() {
url := "/bfs/article/3b8b57821a94af4c171218a01d9cee44dc0dccf8.jpg"
So(CompleteURL(url), ShouldEqual, "https://i0.hdslb.com"+url)
})
}
func TestNoticeState(t *testing.T) {
Convey("ToInt64", t, func() {
a := NoticeState{"lead": true, "new": true}
So(a.ToInt64(), ShouldEqual, 3)
})
Convey("ToInt64 2", t, func() {
a := NoticeState{"lead": true, "new": false}
So(a.ToInt64(), ShouldEqual, 1)
})
Convey("NewNoticeState", t, func() {
a := NoticeState{"lead": true, "new": true}
So(NewNoticeState(3), ShouldResemble, a)
})
Convey("NewNoticeState 2", t, func() {
a := NoticeState{"lead": true, "new": false}
So(NewNoticeState(1), ShouldResemble, a)
})
}

View File

@@ -0,0 +1,22 @@
package model
// RecommendAuthor .
type RecommendAuthor struct {
UpID int64 `json:"up_id"`
RecReason string `json:"rec_reason"`
RecType int `json:"rec_type"`
Tid int `json:"tid"`
Stid int `json:"second_tid"`
}
// RecommendAuthors .
type RecommendAuthors struct {
Count int `json:"count"`
Authors []*RecAuthor `json:"authors"`
}
// RecAuthor .
type RecAuthor struct {
*AccountCard
RecReason string `json:"rec_reason"`
}

View File

@@ -0,0 +1,104 @@
package model
import (
"fmt"
)
// Cards
const (
CardPrefixBangumi = "ss"
CardPrefixBangumiEp = "ep"
CardPrefixTicket = "pw"
CardPrefixMall = "sp"
CardPrefixAudio = "au"
CardPrefixArchive = "av"
CardPrefixArticle = "cv"
)
// TicketCard .
type TicketCard struct {
ID int64 `json:"id"`
Name string `json:"name"`
Image string `json:"performance_image"`
StartTime int64 `json:"start_time"`
EndTime int64 `json:"end_time"`
Province string `json:"province_name"`
City string `json:"city_name"`
District string `json:"district_name"`
Venue string `json:"venue_name"`
PriceLow float64 `json:"price_low"`
URL string `json:"url"`
}
// MallCard .
type MallCard struct {
ID int64 `json:"itemsId"`
Name string `json:"name"`
Brief string `json:"brief"`
Images []string `json:"img"`
Price int64 `json:"price"`
Type int `json:"type"`
}
// AudioCard .
type AudioCard struct {
ID int64 `json:"song_id"`
Title string `json:"title"`
UpMid int64 `json:"up_mid"`
UpName string `json:"up_name"`
Play int64 `json:"play_num"`
Reply int64 `json:"reply_num"`
CoverURL string `json:"cover_url"`
}
// BangumiCard .
type BangumiCard struct {
ID int64 `json:"season_id"`
Type int64 `json:"season_type"`
TypeName string `json:"season_type_name"`
Image string `json:"cover"`
Title string `json:"title"`
Rating struct {
Score float64 `json:"score"`
Count int64 `json:"count"`
} `json:"rating"`
Playable bool `json:"playable"`
FollowCount int64 `json:"follow_count"`
PlayCount int64 `json:"play_count"`
}
// Cards .
type Cards struct {
Type string `json:"type,omitempty"`
TicketCard *TicketCard `json:"ticket_card,omitempty"`
BangumiCard *BangumiCard `json:"bangumi_card,omitempty"`
MallCard *MallCard `json:"mall_card,omitempty"`
AudioCard *AudioCard `json:"audio_card,omitempty"`
}
// Key .
func (c *Cards) Key() string {
var id int64
if c.TicketCard != nil {
id = c.TicketCard.ID
} else if c.BangumiCard != nil {
id = c.BangumiCard.ID
} else if c.MallCard != nil {
id = c.MallCard.ID
} else if c.AudioCard != nil {
id = c.AudioCard.ID
}
return fmt.Sprintf("%s%d", c.Type, id)
}
// Item .
func (c *Cards) Item() interface{} {
if c.TicketCard != nil {
return c.TicketCard
} else if c.BangumiCard != nil {
return c.BangumiCard
} else if c.MallCard != nil {
return c.MallCard
}
return c.AudioCard.ID
}

View File

@@ -0,0 +1,157 @@
package model
import (
"go-common/app/interface/main/creative/model/data"
"go-common/library/time"
)
// const
const (
// ReprintForbid 禁止转载.
ReprintForbid = int8(0)
// ReprintAllow 允许规范转载.
ReprintAllow = int8(1)
// NoImage 无图.
///NoImage = int8(1)
// HeadImage 头图.
HeadImage = int8(4)
)
var (
_reprint = map[int8]int8{
ReprintForbid: ReprintForbid,
ReprintAllow: ReprintAllow,
}
_tid = map[int8]int8{
TemplateText: 0,
TemplateSingleImg: 1,
TemplateMultiImg: 3,
TemplateSingleBigImg: 1,
}
)
// InReprints check reprint in all reprints.
func InReprints(rp int8) (ok bool) {
_, ok = _reprint[rp]
return
}
// InTemplateID check tid in all tids.
func InTemplateID(tid int8) (ok bool) {
_, ok = _tid[tid]
return
}
// ValidTemplate checks template id & images count.
func ValidTemplate(tid int32, imgs []string) bool {
var images []string
for _, image := range imgs {
if image != "" {
images = append(images, image)
}
}
return len(images) == int(_tid[int8(tid)])
}
// UpStat for bigdata article up stat
type UpStat struct {
View int64 `json:"view"`
Reply int64 `json:"reply"`
Like int64 `json:"like"`
Coin int64 `json:"coin"`
Fav int64 `json:"fav"`
Share int64 `json:"share"`
PreView int64 `json:"-"`
PreReply int64 `json:"-"`
PreLike int64 `json:"-"`
PreCoin int64 `json:"-"`
PreFav int64 `json:"-"`
PreShare int64 `json:"-"`
IncrView int64 `json:"incr_view"`
IncrReply int64 `json:"incr_reply"`
IncrLike int64 `json:"incr_like"`
IncrCoin int64 `json:"incr_coin"`
IncrFav int64 `json:"incr_fav"`
IncrShare int64 `json:"incr_share"`
}
// ThirtyDayArticle for article 30 days data.
type ThirtyDayArticle struct {
Category string `json:"category"`
ThirtyDay []*data.ThirtyDay `json:"thirty_day"`
}
// ArtParam param for article info input.
type ArtParam struct {
AID int64 `json:"aid"`
MID int64 `json:"mid"`
Category int64 `json:"category"`
State int32 `json:"state"`
Reprint int32 `json:"reprint"`
TemplateID int32 `json:"tid"`
Title string `json:"title"`
BannerURL string `json:"banner_url"`
Content string `json:"content"`
Summary string `json:"summary"`
Tags string `json:"tags"`
ImageURLs []string `json:"image_urls"`
OriginImageURLs []string `json:"origin_image_urls"`
RealIP string `json:"-"`
Action int `json:"action"`
Words int64 `json:"words"`
DynamicIntro string `json:"dynamic_intro"`
ActivityID int64 `json:"activity_id"`
ListID int64 `json:"list_id"`
MediaID int64 `json:"media_id"`
Spoiler int32 `json:"spoiler"`
}
// CreativeMeta article detail.
type CreativeMeta struct {
ID int64 `json:"id"`
Title string `json:"title"`
Content string `json:"content"`
Summary string `json:"summary"`
BannerURL string `json:"banner_url"`
Reason string `json:"reason"`
TemplateID int32 `json:"template_id"`
State int32 `json:"state"`
Reprint int32 `json:"reprint"`
ImageURLs []string `json:"image_urls"`
OriginImageURLs []string `json:"origin_image_urls"`
Tags []string `json:"tags"`
Category *Category `json:"category"`
Author *Author `json:"author"`
Stats *Stats `json:"stats"`
PTime time.Time `json:"publish_time"`
CTime time.Time `json:"ctime"`
MTime time.Time `json:"mtime"`
ViewURL string `json:"view_url"`
EditURL string `json:"edit_url"`
IsPreview int `json:"is_preview"`
DynamicIntro string `json:"dynamic_intro"`
List *List `json:"list"`
MediaID int64 `json:"media_id"`
Spoiler int32 `json:"spoiler"`
EditTimes int `json:"edit_times"`
PreViewURL string `json:"pre_view_url"`
}
// CreativeArtList article for list.
type CreativeArtList struct {
Articles []*CreativeMeta `json:"articles"`
Type *CreationArtsType `json:"type"`
Page *ArtPage `json:"page"`
}
// CreativeDraftList draft list.
type CreativeDraftList struct {
Drafts []*CreativeMeta `json:"drafts"`
Page *ArtPage `json:"page"`
DraftURL string `json:"draft_url"`
}
// ExtMsg .
type ExtMsg struct {
Tags []*Tag `json:"tags"`
}

View File

@@ -0,0 +1,42 @@
package model
// hotspot type
const (
HotspotTypeView = 0
HotspotTypePtime = 1
)
// HotspotTypes types
var HotspotTypes = [...]int8{HotspotTypeView, HotspotTypePtime}
// Hotspot model
type Hotspot struct {
ID int64 `json:"id"`
Tag string `json:"tag"`
Title string `json:"title"`
TopArticles []int64 `json:"top_articles"`
Icon bool `json:"icon"`
Stats HotspotStats `json:"stats"`
}
// HotspotStats .
type HotspotStats struct {
Read int64 `json:"read"`
Reply int64 `json:"reply"`
Count int64 `json:"count"`
}
// SearchArt search article model
type SearchArt struct {
ID int64
PublishTime int64
Tags []string
StatsView int64
StatsReply int64
}
// HotspotResp model
type HotspotResp struct {
Hotspot *Hotspot `json:"hotspot"`
Articles []*MetaWithLike `json:"articles"`
}

View File

@@ -0,0 +1,98 @@
package model
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 Global.
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)
// PlatH5 is int8 for H5
PlatH5 = int8(9)
// PlatPC is int8 for PC
PlatPC = int8(10)
//PlatOther is int8 for unknow plat
PlatOther = int8(11)
)
// Plat return plat by platStr or mobiApp
func Plat(mobiApp, device string) int8 {
switch mobiApp {
case "iphone", "iphone_b":
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
case "h5":
return PlatH5
case "pc":
return PlatPC
}
return PlatOther
}
// Client 成转换AI部门的client
func Client(plat int8) string {
switch plat {
case PlatIPad, PlatIPadI:
return "ipad"
case PlatIPhone, PlatIPhoneI:
return "iphone"
case PlatAndroid, PlatAndroidG, PlatAndroidI, PlatAndroidTV:
return "android"
default:
return "web"
}
}
// HistoryClient .
func HistoryClient(plat int8) (client int8) {
switch plat {
case PlatAndroid, PlatAndroidG, PlatAndroidI:
client = 3
case PlatIPhone, PlatIPhoneI:
client = 1
case PlatPC, PlatH5:
client = 2
case PlatAndroidTV:
client = 33
case PlatIPad, PlatIPadI:
client = 4
case PlatWPhone:
client = 6
}
return
}

View File

@@ -0,0 +1,90 @@
package model
import xtime "go-common/library/time"
// sort type
const (
ListSortPtime = 0
ListSortView = 1
)
// CreativeList creative list
type CreativeList struct {
*List
Total int `json:"total"`
}
// ListArtMeta .
type ListArtMeta struct {
ID int64 `json:"id"`
Title string `json:"title"`
State int `json:"state"`
PublishTime xtime.Time `json:"publish_time"`
Position int `json:"-"`
Words int64 `json:"words"`
ImageURLs []string `json:"image_urls"`
Category *Category `json:"category"`
Categories []*Category `json:"categories"`
Summary string `json:"summary"`
}
// Strong fill
func (a *ListArtMeta) Strong() {
if a == nil {
return
}
if a.ImageURLs == nil {
a.ImageURLs = []string{}
}
if a.Category == nil {
a.Category = &Category{}
}
if a.Categories == nil {
a.Categories = []*Category{}
}
}
// FullListArtMeta .
type FullListArtMeta struct {
*ListArtMeta
Stats Stats `json:"stats"`
LikeState int8 `json:"like_state"`
}
// IsNormal judge whether article's state is normal.
func (a *ListArtMeta) IsNormal() bool {
return (a != nil) && (a.State >= StateOpen)
}
// ListArticles list articles
type ListArticles struct {
List *List `json:"list"`
Articles []*ListArtMeta `json:"articles"`
Author *Author `json:"author"`
Last ListArtMeta `json:"last"`
Attention bool `json:"attention"`
}
// WebListArticles .
type WebListArticles struct {
List *List `json:"list"`
Articles []*FullListArtMeta `json:"articles"`
Author *Author `json:"author"`
Last ListArtMeta `json:"last"`
Attention bool `json:"attention"`
}
// ListInfo list info
type ListInfo struct {
List *List `json:"list"`
Last *ListArtMeta `json:"last"`
Next *ListArtMeta `json:"next"`
Now int `json:"now"`
Total int `json:"total"`
}
// UpLists .
type UpLists struct {
Lists []*List `json:"lists"`
Total int `json:"total"`
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,134 @@
syntax = "proto3";
package article.service;
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
option (gogoproto.goproto_enum_prefix_all) = false;
option (gogoproto.goproto_getters_all) = false;
option (gogoproto.unmarshaler_all) = true;
option (gogoproto.marshaler_all) = true;
option (gogoproto.sizer_all) = true;
option go_package = "model";
message Category {
int64 id = 1 [(gogoproto.jsontag) = "id", (gogoproto.customname) = "ID"];
int64 parent_id = 2 [(gogoproto.jsontag) = "parent_id", (gogoproto.customname) = "ParentID"];
string name = 3 [(gogoproto.jsontag) = "name"];
int64 position = 4 [(gogoproto.jsontag) = "-"];
repeated Category children = 5 [(gogoproto.jsontag) = "children,omitempty"];
string banner_url = 6 [(gogoproto.jsontag) = "banner_url,omitempty", (gogoproto.customname) = "BannerURL"];
}
message Stats {
int64 view = 1 [(gogoproto.jsontag) = "view"];
int64 favorite = 2 [(gogoproto.jsontag) = "favorite"];
int64 like= 3 [(gogoproto.jsontag) = "like"];
int64 dislike= 4 [(gogoproto.jsontag) = "dislike"];
int64 reply= 5 [(gogoproto.jsontag) = "reply"];
int64 share= 6 [(gogoproto.jsontag) = "share"];
int64 coin= 7 [(gogoproto.jsontag) = "coin"];
int64 dynamic= 8 [(gogoproto.jsontag) = "dynamic"];
}
message Meta {
int64 id = 1 [(gogoproto.jsontag) = "id", (gogoproto.customname) = "ID"];
Category category = 2 [(gogoproto.jsontag) = "category"];
repeated Category categories = 3 [(gogoproto.jsontag) = "categories"];
string title = 4 [(gogoproto.jsontag) = "title"];
string summary = 5 [(gogoproto.jsontag) = "summary"];
string banner_url = 6 [(gogoproto.jsontag) = "banner_url", (gogoproto.customname) = "BannerURL"];
int32 template_id = 7 [(gogoproto.jsontag) = "template_id", (gogoproto.customname) = "TemplateID"];
int32 state = 8 [(gogoproto.jsontag) = "state"];
Author author = 9 [(gogoproto.jsontag) = "author"];
int32 reprint = 10 [(gogoproto.jsontag) = "reprint"];
repeated string image_urls = 11 [(gogoproto.jsontag) = "image_urls", (gogoproto.customname) = "ImageURLs"];
int64 publish_time = 12 [(gogoproto.jsontag) = "publish_time", (gogoproto.casttype) = "go-common/library/time.Time"];
int64 ctime = 13 [(gogoproto.jsontag) = "ctime", (gogoproto.casttype) = "go-common/library/time.Time"];
int64 mtime = 14 [(gogoproto.jsontag) = "mtime,omitempty", (gogoproto.casttype) = "go-common/library/time.Time"];
Stats stats = 15 [(gogoproto.jsontag) = "stats,omitempty"];
repeated Tag tags = 16 [(gogoproto.jsontag) = "tags,omitempty"];
int32 attributes = 17 [(gogoproto.jsontag) = "attributes,omitempty"];
string reason = 18 [(gogoproto.jsontag) = "reason,omitempty"];
int64 words = 19 [(gogoproto.jsontag) = "words"];
string dynamic = 20 [(gogoproto.jsontag) = "dynamic,omitempty"];
repeated string origin_image_urls = 21 [(gogoproto.jsontag) = "origin_image_urls", (gogoproto.customname) = "OriginImageURLs"];
List list = 22 [(gogoproto.jsontag) = "list"];
bool isLike = 23 [(gogoproto.jsontag) = "is_like", (gogoproto.customname) = "IsLike"];
Media media = 24 [(gogoproto.jsontag) = "media", (gogoproto.customname) = "Media"];
string apply_time = 25 [(gogoproto.jsontag) = "apply_time", (gogoproto.customname) = "ApplyTime"];
string check_time = 26 [(gogoproto.jsontag) = "check_time", (gogoproto.customname) = "CheckTime"];
}
message Media {
int32 score = 1 [(gogoproto.jsontag) = "score", (gogoproto.customname) = "Score"];
int64 media_id = 2 [(gogoproto.jsontag) = "media_id", (gogoproto.customname) = "MediaID"];
string title = 3 [(gogoproto.jsontag) = "title", (gogoproto.customname) = "Title"];
string cover = 4 [(gogoproto.jsontag) = "cover", (gogoproto.customname) = "Cover"];
string area = 5 [(gogoproto.jsontag) = "area", (gogoproto.customname) = "Area"];
int32 type_id = 6 [(gogoproto.jsontag) = "type_id", (gogoproto.customname) = "TypeID"];
string type_name = 7 [(gogoproto.jsontag) = "type_name", (gogoproto.customname) = "TypeName"];
int32 spoiler = 8 [(gogoproto.jsontag) = "spoiler", (gogoproto.customname) = "Spoiler"];
}
message OfficialVerify {
int64 type = 1 [(gogoproto.jsontag) = "type"];
string desc = 2 [(gogoproto.jsontag) = "desc"];
}
message Author {
int64 mid = 1 [(gogoproto.jsontag) = "mid"];
string name = 2 [(gogoproto.jsontag) = "name"];
string face = 3 [(gogoproto.jsontag) = "face"];
Pendant pendant = 4 [(gogoproto.jsontag) = "pendant", (gogoproto.nullable) = false];
OfficialVerify official_verify = 5 [(gogoproto.jsontag) = "official_verify", (gogoproto.nullable) = false];
Nameplate nameplate = 6 [(gogoproto.jsontag) = "nameplate", (gogoproto.nullable) = false];
VipInfo vip = 7 [(gogoproto.jsontag) = "vip", (gogoproto.nullable) = false];
}
message VipInfo {
int32 type = 1 [(gogoproto.jsontag) = "type"];
int32 status = 2 [(gogoproto.jsontag) = "status"];
int64 due_date = 3 [(gogoproto.jsontag) = "due_date"];
int32 vip_pay_type = 4 [(gogoproto.jsontag) = "vip_pay_type"];
}
message Nameplate {
int32 nid = 1 [(gogoproto.jsontag) = "nid",(gogoproto.casttype) = "int"];
string name = 2 [(gogoproto.jsontag) = "name"];
string image = 3 [(gogoproto.jsontag) = "image"];
string image_small = 4 [(gogoproto.jsontag) = "image_small"];
string level = 5 [(gogoproto.jsontag) = "level"];
string condition = 6 [(gogoproto.jsontag) = "condition"];
}
message Pendant {
int32 pid = 1 [(gogoproto.jsontag) = "pid"];
string name = 2 [(gogoproto.jsontag) = "name"];
string image = 3 [(gogoproto.jsontag) = "image"];
int32 expire = 4 [(gogoproto.jsontag) = "expire"];
}
message Tag {
int64 tid = 1 [(gogoproto.jsontag) = "tid"];
string name = 2 [(gogoproto.jsontag) = "name"];
}
message Article {
Meta meta = 1 [(gogoproto.jsontag) = "", (gogoproto.embed) = true];
string content = 2 [(gogoproto.jsontag) = "content,omitempty"];
string keywords = 3 [(gogoproto.jsontag) = "keywords", (gogoproto.customname) = "Keywords"];
}
message List {
int64 id = 1 [(gogoproto.jsontag) = "id", (gogoproto.customname) = "ID"];
int64 mid = 2[(gogoproto.jsontag) = "mid"];
string name = 3 [(gogoproto.jsontag) = "name"];
string image_url = 4 [(gogoproto.jsontag) = "image_url", (gogoproto.customname) = "ImageURL"];
int64 update_time = 5 [(gogoproto.jsontag) = "update_time", (gogoproto.casttype) = "go-common/library/time.Time"];
int64 ctime = 6 [(gogoproto.jsontag) = "ctime", (gogoproto.casttype) = "go-common/library/time.Time"];
int64 publish_time = 7 [(gogoproto.jsontag) = "publish_time", (gogoproto.casttype) = "go-common/library/time.Time"];
string summary = 8 [(gogoproto.jsontag) = "summary"];
int64 words = 9 [(gogoproto.jsontag) = "words"];
int64 read = 10 [(gogoproto.jsontag) = "read"];
int64 articles_count = 11 [(gogoproto.jsontag) = "articles_count"];
}

View File

@@ -0,0 +1,34 @@
package model
// rank
var (
RankMonth = int64(1)
RankWeek = int64(2)
RankYesterday = int64(3)
RankBeforeYesterday = int64(4)
)
// RankCategory .
type RankCategory struct {
ID int64 `json:"id"`
Name string `json:"name"`
}
// Rank .
type Rank struct {
Aid int64 `json:"aid"`
Score int64 `json:"score"`
}
// RankMeta .
type RankMeta struct {
*Meta
Attention bool `json:"attention"`
Score int64 `json:"score"`
}
// RankResp .
type RankResp struct {
Note string `json:"note"`
List []*Rank `json:"list"`
}

View File

@@ -0,0 +1,221 @@
package model
import (
xtime "go-common/library/time"
"time"
)
// ArgArticle .
type ArgArticle struct {
Action int
Aid int64
Category int64
Title string
Summary string
BannerURL string
TemplateID int32
State int32
Mid int64
Reprint int32
ImageURLs []string
OriginImageURLs []string
Tags []string
Content string
Words int64
DynamicIntro string
ActivityID int64
ListID int64
RealIP string
MediaID int64
Spoiler int32
}
// ArgAid .
type ArgAid struct {
Aid int64
RealIP string
}
// ArgPtime .
type ArgPtime struct {
Aid int64
PubTime int64
RealIP string
}
// ArgAidMid .
type ArgAidMid struct {
Aid int64
Mid int64
RealIP string
}
// ArgAids .
type ArgAids struct {
Aids []int64
RealIP string
}
// ArgMid .
type ArgMid struct {
Mid int64
RealIP string
}
// ArgMidAids .
type ArgMidAids struct {
Mid int64
Aids []int64
RealIP string
}
// ArgCreationArts .
type ArgCreationArts struct {
Mid int64
Sort int
Group int
Category int
Pn, Ps int
RealIP string
}
// ArgStats .
type ArgStats struct {
*Stats
Aid int64
}
// ArgIP .
type ArgIP struct {
RealIP string
}
// ArgUpsArts .
type ArgUpsArts struct {
Mids []int64
Pn, Ps int
RealIP string
}
// ArgUpArts .
type ArgUpArts struct {
Mid int64
Pn, Ps int
Sort int
RealIP string
}
// ArgRecommends .
type ArgRecommends struct {
Cid int64
Sort int
Aids []int64
Pn, Ps int
RealIP string
}
// ArgUpDraft .
type ArgUpDraft struct {
Mid int64
Pn, Ps int
RealIP string
}
// ArgAidCid .
type ArgAidCid struct {
Aid int64
Cid int64
RealIP string
}
// ArgAidContent .
type ArgAidContent struct {
Aid int64
Content string
RealIP string
}
// ArgFav .
type ArgFav struct {
Mid int64
Pn, Ps int
RealIP string
}
// ArgAuthor .
type ArgAuthor struct {
Mid int64
RealIP string
}
// ArgSort .
type ArgSort struct {
Aid int64
Changed [][2]int64
RealIP string
}
// ArgNewArt .
type ArgNewArt struct {
PubTime int64
RealIP string
}
// TransformArticle .
func TransformArticle(arg *ArgArticle) *Article {
a := &Article{
Meta: &Meta{
ID: arg.Aid,
Category: &Category{ID: arg.Category},
Title: arg.Title,
Summary: arg.Summary,
BannerURL: arg.BannerURL,
TemplateID: arg.TemplateID,
State: arg.State,
Author: &Author{Mid: arg.Mid},
Reprint: arg.Reprint,
ImageURLs: arg.ImageURLs,
OriginImageURLs: arg.OriginImageURLs,
Words: arg.Words,
Dynamic: arg.DynamicIntro,
Media: &Media{MediaID: arg.MediaID, Spoiler: arg.Spoiler},
},
Content: arg.Content,
}
for _, t := range arg.Tags {
a.Tags = append(a.Tags, &Tag{Name: t})
}
return a
}
// TransformDraft .
func TransformDraft(arg *ArgArticle) *Draft {
return &Draft{
Article: &Article{
Meta: &Meta{
ID: arg.Aid,
Author: &Author{Mid: arg.Mid},
Category: &Category{ID: arg.Category},
Title: arg.Title,
Summary: arg.Summary,
BannerURL: arg.BannerURL,
TemplateID: arg.TemplateID,
Reprint: arg.Reprint,
ImageURLs: arg.ImageURLs,
OriginImageURLs: arg.OriginImageURLs,
Mtime: xtime.Time(time.Now().Unix()),
Dynamic: arg.DynamicIntro,
Media: &Media{MediaID: arg.MediaID, Spoiler: arg.Spoiler},
},
Content: arg.Content,
},
Tags: arg.Tags,
ListID: arg.ListID,
}
}
// ArgForce force update
type ArgForce struct {
Force bool
RealIP string
}

View File

@@ -0,0 +1,53 @@
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 = "bili_search_rpc_tagbox_proto",
srcs = ["search.proto"],
tags = ["automanaged"],
)
go_proto_library(
name = "bili_search_rpc_tagbox_go_proto",
compilers = ["@io_bazel_rules_go//proto:go_grpc"],
importpath = "go-common/app/interface/openplatform/article/model/search",
proto = ":bili_search_rpc_tagbox_proto",
tags = ["automanaged"],
)
go_library(
name = "go_default_library",
srcs = [],
embed = [":bili_search_rpc_tagbox_go_proto"],
importpath = "go-common/app/interface/openplatform/article/model/search",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"@com_github_gogo_protobuf//proto:go_default_library",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_x_net//context: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"],
)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,26 @@
syntax="proto2";
option cc_generic_services = true;
package bili.search.rpc.tagbox;
message SourceTypeConst {
optional string SOURCE_ARTICLE = 1 [default = "article"]; // 文章
}
message TagboxRequest {
required int32 id = 1;
required string source_type = 2;
required string content = 3;
required int32 trackid = 4;
optional string remarks = 5;
}
message TagboxResponse {
required int32 exec_code = 1;
required int32 id = 2;
repeated string keywords = 3;
}
service TagboxService {
rpc segment(TagboxRequest) returns (TagboxResponse);
}

View File

@@ -0,0 +1,23 @@
package model
// Setting .
type Setting struct {
// 是否开启申请
ApplyOpen bool `json:"apply_info"`
// 申请限制
ApplyLimit int64 `json:"apply_limit"`
// 申请被拒绝后的冷冻期
ApplyFrozenDuration int64 `json:"frozen_duration"`
// 是否在推荐页面展示最新投稿
ShowRecommendNewArticles bool `json:"show_rec_new_arts"`
// 是否展示web端排行榜的说明
ShowRankNote bool `json:"show_rank_note"`
// 是否展示app专栏主要的排行榜
ShowAppHomeRank bool `json:"show_app_home_rank"`
// 详情页展示稍后在看
ShowLaterWatch bool `json:"show_later_watch"`
// 详情页展示小窗播放
ShowSmallWindow bool `json:"show_small_window"`
// 热点标签
ShowHotspot bool `json:"show_hotspot"`
}

View File

@@ -0,0 +1,19 @@
package model
const (
// FieldDefault with recommends
FieldDefault = iota
// FieldNew new list
FieldNew
// FieldLike like stat
FieldLike
// FieldReply reply stat
FieldReply
// FieldFav favorite stat
FieldFav
// FieldView view stat
FieldView
)
// SortFields all field
var SortFields = []int{FieldNew, FieldLike, FieldReply, FieldFav, FieldView}