@ -17,6 +17,7 @@ import (
"github.com/rocboss/paopao-ce/internal/conf"
"github.com/rocboss/paopao-ce/internal/conf"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/internal/core/cs"
"github.com/rocboss/paopao-ce/internal/core/cs"
"github.com/rocboss/paopao-ce/internal/core/ms"
"github.com/rocboss/paopao-ce/internal/model/web"
"github.com/rocboss/paopao-ce/internal/model/web"
"github.com/rocboss/paopao-ce/internal/servants/base"
"github.com/rocboss/paopao-ce/internal/servants/base"
"github.com/rocboss/paopao-ce/internal/servants/chain"
"github.com/rocboss/paopao-ce/internal/servants/chain"
@ -28,7 +29,13 @@ import (
var (
var (
_ api . Priv = ( * privSrv ) ( nil )
_ api . Priv = ( * privSrv ) ( nil )
_uploadAttachmentTypeMap = map [ string ] cs . AttachmentType {
_uploadAttachmentTypeMap = map [ string ] ms . AttachmentType {
"public/image" : ms . AttachmentTypeImage ,
"public/avatar" : ms . AttachmentTypeImage ,
"public/video" : ms . AttachmentTypeVideo ,
"attachment" : ms . AttachmentTypeOther ,
}
_uploadAttachmentTypes = map [ string ] cs . AttachmentType {
"public/image" : cs . AttachmentTypeImage ,
"public/image" : cs . AttachmentTypeImage ,
"public/avatar" : cs . AttachmentTypeImage ,
"public/avatar" : cs . AttachmentTypeImage ,
"public/video" : cs . AttachmentTypeVideo ,
"public/video" : cs . AttachmentTypeVideo ,
@ -119,20 +126,20 @@ func (s *privSrv) UploadAttachment(req *web.UploadAttachmentReq) (*web.UploadAtt
}
}
// 构造附件Model
// 构造附件Model
attachment := & c s. Attachment {
attachment := & m s. Attachment {
UserID : req . Uid ,
UserID : req . Uid ,
FileSize : req . FileSize ,
FileSize : req . FileSize ,
Content : objectUrl ,
Content : objectUrl ,
Type : _uploadAttachmentTypeMap [ req . UploadType ] ,
Type : _uploadAttachmentTypeMap [ req . UploadType ] ,
}
}
if attachment . Type == c s. AttachmentTypeImage {
if attachment . Type == m s. AttachmentTypeImage {
var src image . Image
var src image . Image
src , err = imaging . Decode ( req . File )
src , err = imaging . Decode ( req . File )
if err == nil {
if err == nil {
attachment . ImgWidth , attachment . ImgHeight = getImageSize ( src . Bounds ( ) )
attachment . ImgWidth , attachment . ImgHeight = getImageSize ( src . Bounds ( ) )
}
}
}
}
attachment . ID , err = s . Ds a . CreateAttachment ( attachment )
attachment . ID , err = s . Ds . CreateAttachment ( attachment )
if err != nil {
if err != nil {
logrus . Errorf ( "Ds.CreateAttachment err: %s" , err )
logrus . Errorf ( "Ds.CreateAttachment err: %s" , err )
return nil , web . ErrFileUploadFailed
return nil , web . ErrFileUploadFailed
@ -155,7 +162,7 @@ func (s *privSrv) DownloadAttachmentPrecheck(req *web.DownloadAttachmentPrecheck
return nil , web . ErrInvalidDownloadReq
return nil , web . ErrInvalidDownloadReq
}
}
resp := & web . DownloadAttachmentPrecheckResp { Paid : true }
resp := & web . DownloadAttachmentPrecheckResp { Paid : true }
if content . Type == core . ContentTypeChargeAttachment {
if content . Type == ms . ContentTypeChargeAttachment {
tweet , err := s . GetTweetBy ( content . PostID )
tweet , err := s . GetTweetBy ( content . PostID )
if err != nil {
if err != nil {
logrus . Errorf ( "get tweet err: %v" , err )
logrus . Errorf ( "get tweet err: %v" , err )
@ -178,7 +185,7 @@ func (s *privSrv) DownloadAttachment(req *web.DownloadAttachmentReq) (*web.Downl
return nil , web . ErrInvalidDownloadReq
return nil , web . ErrInvalidDownloadReq
}
}
// 收费附件
// 收费附件
if content . Type == core . ContentTypeChargeAttachment {
if content . Type == ms . ContentTypeChargeAttachment {
post , err := s . GetTweetBy ( content . PostID )
post , err := s . GetTweetBy ( content . PostID )
if err != nil {
if err != nil {
logrus . Errorf ( "s.GetTweetBy err: %v" , err )
logrus . Errorf ( "s.GetTweetBy err: %v" , err )
@ -191,8 +198,8 @@ func (s *privSrv) DownloadAttachment(req *web.DownloadAttachmentReq) (*web.Downl
}
}
// 未购买,则尝试购买
// 未购买,则尝试购买
if ! paidFlag {
if ! paidFlag {
err := s . buyPostAttachment ( & core . Post {
err := s . buyPostAttachment ( & ms . Post {
Model : & core . Model {
Model : & ms . Model {
ID : post . ID ,
ID : post . ID ,
} ,
} ,
UserID : post . UserID ,
UserID : post . UserID ,
@ -229,7 +236,7 @@ func (s *privSrv) CreateTweet(req *web.CreateTweetReq) (_ *web.CreateTweetResp,
}
}
mediaContents = contents
mediaContents = contents
tags := tagsFrom ( req . Tags )
tags := tagsFrom ( req . Tags )
post := & core . Post {
post := & ms . Post {
UserID : req . User . ID ,
UserID : req . User . ID ,
Tags : strings . Join ( tags , "," ) ,
Tags : strings . Join ( tags , "," ) ,
IP : req . ClientIP ,
IP : req . ClientIP ,
@ -250,10 +257,10 @@ func (s *privSrv) CreateTweet(req *web.CreateTweetReq) (_ *web.CreateTweetResp,
logrus . Infof ( "contents check err: %s" , err )
logrus . Infof ( "contents check err: %s" , err )
continue
continue
}
}
if item . Type == core . ContentTypeAttachment && req . AttachmentPrice > 0 {
if item . Type == ms . ContentTypeAttachment && req . AttachmentPrice > 0 {
item . Type = core . ContentTypeChargeAttachment
item . Type = ms . ContentTypeChargeAttachment
}
}
postContent := & core . PostContent {
postContent := & ms . PostContent {
PostID : post . ID ,
PostID : post . ID ,
UserID : req . User . ID ,
UserID : req . User . ID ,
Content : item . Content ,
Content : item . Content ,
@ -280,10 +287,10 @@ func (s *privSrv) CreateTweet(req *web.CreateTweetReq) (_ *web.CreateTweetResp,
// 创建消息提醒
// 创建消息提醒
// TODO: 优化消息提醒处理机制
// TODO: 优化消息提醒处理机制
go s . Ds . CreateMessage ( & core . Message {
go s . Ds . CreateMessage ( & ms . Message {
SenderUserID : req . User . ID ,
SenderUserID : req . User . ID ,
ReceiverUserID : user . ID ,
ReceiverUserID : user . ID ,
Type : core . MsgTypePost ,
Type : ms . MsgTypePost ,
Brief : "在新发布的泡泡动态中@了你" ,
Brief : "在新发布的泡泡动态中@了你" ,
PostID : post . ID ,
PostID : post . ID ,
} )
} )
@ -291,7 +298,7 @@ func (s *privSrv) CreateTweet(req *web.CreateTweetReq) (_ *web.CreateTweetResp,
}
}
// 推送Search
// 推送Search
s . PushPostToSearch ( post )
s . PushPostToSearch ( post )
formatedPosts , err := s . Ds . RevampPosts ( [ ] * core . PostFormated { post . Format ( ) } )
formatedPosts , err := s . Ds . RevampPosts ( [ ] * ms . PostFormated { post . Format ( ) } )
if err != nil {
if err != nil {
logrus . Infof ( "Ds.RevampPosts err: %s" , err )
logrus . Infof ( "Ds.RevampPosts err: %s" , err )
return nil , web . ErrCreatePostFailed
return nil , web . ErrCreatePostFailed
@ -347,8 +354,8 @@ func (s *privSrv) DeleteCommentReply(req *web.DeleteCommentReplyReq) mir.Error {
func ( s * privSrv ) CreateCommentReply ( req * web . CreateCommentReplyReq ) ( * web . CreateCommentReplyResp , mir . Error ) {
func ( s * privSrv ) CreateCommentReply ( req * web . CreateCommentReplyReq ) ( * web . CreateCommentReplyResp , mir . Error ) {
var (
var (
post * core . Post
post * ms . Post
comment * core . Comment
comment * ms . Comment
atUserID int64
atUserID int64
err error
err error
)
)
@ -358,7 +365,7 @@ func (s *privSrv) CreateCommentReply(req *web.CreateCommentReplyReq) (*web.Creat
}
}
// 创建评论
// 创建评论
reply := & core . CommentReply {
reply := & ms . CommentReply {
CommentID : req . CommentID ,
CommentID : req . CommentID ,
UserID : req . Uid ,
UserID : req . Uid ,
Content : req . Content ,
Content : req . Content ,
@ -383,10 +390,10 @@ func (s *privSrv) CreateCommentReply(req *web.CreateCommentReplyReq) (*web.Creat
// 创建用户消息提醒
// 创建用户消息提醒
commentMaster , err := s . Ds . GetUserByID ( comment . UserID )
commentMaster , err := s . Ds . GetUserByID ( comment . UserID )
if err == nil && commentMaster . ID != req . Uid {
if err == nil && commentMaster . ID != req . Uid {
go s . Ds . CreateMessage ( & core . Message {
go s . Ds . CreateMessage ( & ms . Message {
SenderUserID : req . Uid ,
SenderUserID : req . Uid ,
ReceiverUserID : commentMaster . ID ,
ReceiverUserID : commentMaster . ID ,
Type : core . MsgTypeReply ,
Type : ms . MsgTypeReply ,
Brief : "在泡泡评论下回复了你" ,
Brief : "在泡泡评论下回复了你" ,
PostID : post . ID ,
PostID : post . ID ,
CommentID : comment . ID ,
CommentID : comment . ID ,
@ -395,10 +402,10 @@ func (s *privSrv) CreateCommentReply(req *web.CreateCommentReplyReq) (*web.Creat
}
}
postMaster , err := s . Ds . GetUserByID ( post . UserID )
postMaster , err := s . Ds . GetUserByID ( post . UserID )
if err == nil && postMaster . ID != req . Uid && commentMaster . ID != postMaster . ID {
if err == nil && postMaster . ID != req . Uid && commentMaster . ID != postMaster . ID {
go s . Ds . CreateMessage ( & core . Message {
go s . Ds . CreateMessage ( & ms . Message {
SenderUserID : req . Uid ,
SenderUserID : req . Uid ,
ReceiverUserID : postMaster . ID ,
ReceiverUserID : postMaster . ID ,
Type : core . MsgTypeReply ,
Type : ms . MsgTypeReply ,
Brief : "在泡泡评论下发布了新回复" ,
Brief : "在泡泡评论下发布了新回复" ,
PostID : post . ID ,
PostID : post . ID ,
CommentID : comment . ID ,
CommentID : comment . ID ,
@ -409,10 +416,10 @@ func (s *privSrv) CreateCommentReply(req *web.CreateCommentReplyReq) (*web.Creat
user , err := s . Ds . GetUserByID ( atUserID )
user , err := s . Ds . GetUserByID ( atUserID )
if err == nil && user . ID != req . Uid && commentMaster . ID != user . ID && postMaster . ID != user . ID {
if err == nil && user . ID != req . Uid && commentMaster . ID != user . ID && postMaster . ID != user . ID {
// 创建消息提醒
// 创建消息提醒
go s . Ds . CreateMessage ( & core . Message {
go s . Ds . CreateMessage ( & ms . Message {
SenderUserID : req . Uid ,
SenderUserID : req . Uid ,
ReceiverUserID : user . ID ,
ReceiverUserID : user . ID ,
Type : core . MsgTypeReply ,
Type : ms . MsgTypeReply ,
Brief : "在泡泡评论的回复中@了你" ,
Brief : "在泡泡评论的回复中@了你" ,
PostID : post . ID ,
PostID : post . ID ,
CommentID : comment . ID ,
CommentID : comment . ID ,
@ -475,7 +482,7 @@ func (s *privSrv) CreateComment(req *web.CreateCommentReq) (_ *web.CreateComment
if post . CommentCount >= conf . AppSetting . MaxCommentCount {
if post . CommentCount >= conf . AppSetting . MaxCommentCount {
return nil , web . ErrMaxCommentCount
return nil , web . ErrMaxCommentCount
}
}
comment := & core . Comment {
comment := & ms . Comment {
PostID : post . ID ,
PostID : post . ID ,
UserID : req . Uid ,
UserID : req . Uid ,
IP : req . ClientIP ,
IP : req . ClientIP ,
@ -489,12 +496,12 @@ func (s *privSrv) CreateComment(req *web.CreateCommentReq) (_ *web.CreateComment
for _ , item := range req . Contents {
for _ , item := range req . Contents {
// 检查附件是否是本站资源
// 检查附件是否是本站资源
if item . Type == core. ContentTypeImage || item . Type == core . ContentTypeVideo || item . Type == core . ContentTypeAttachment {
if item . Type == ms. ContentTypeImage || item . Type == ms . ContentTypeVideo || item . Type == ms . ContentTypeAttachment {
if err := s . Ds . CheckAttachment ( item . Content ) ; err != nil {
if err := s . Ds . CheckAttachment ( item . Content ) ; err != nil {
continue
continue
}
}
}
}
postContent := & core . CommentContent {
postContent := & ms . CommentContent {
CommentID : comment . ID ,
CommentID : comment . ID ,
UserID : req . Uid ,
UserID : req . Uid ,
Content : item . Content ,
Content : item . Content ,
@ -515,10 +522,10 @@ func (s *privSrv) CreateComment(req *web.CreateCommentReq) (_ *web.CreateComment
// 创建用户消息提醒
// 创建用户消息提醒
postMaster , err := s . Ds . GetUserByID ( post . UserID )
postMaster , err := s . Ds . GetUserByID ( post . UserID )
if err == nil && postMaster . ID != req . Uid {
if err == nil && postMaster . ID != req . Uid {
go s . Ds . CreateMessage ( & core . Message {
go s . Ds . CreateMessage ( & ms . Message {
SenderUserID : req . Uid ,
SenderUserID : req . Uid ,
ReceiverUserID : postMaster . ID ,
ReceiverUserID : postMaster . ID ,
Type : core . MsgtypeComment ,
Type : ms . MsgtypeComment ,
Brief : "在泡泡中评论了你" ,
Brief : "在泡泡中评论了你" ,
PostID : post . ID ,
PostID : post . ID ,
CommentID : comment . ID ,
CommentID : comment . ID ,
@ -531,10 +538,10 @@ func (s *privSrv) CreateComment(req *web.CreateCommentReq) (_ *web.CreateComment
}
}
// 创建消息提醒
// 创建消息提醒
go s . Ds . CreateMessage ( & core . Message {
go s . Ds . CreateMessage ( & ms . Message {
SenderUserID : req . Uid ,
SenderUserID : req . Uid ,
ReceiverUserID : user . ID ,
ReceiverUserID : user . ID ,
Type : core . MsgtypeComment ,
Type : ms . MsgtypeComment ,
Brief : "在泡泡评论中@了你" ,
Brief : "在泡泡评论中@了你" ,
PostID : post . ID ,
PostID : post . ID ,
CommentID : comment . ID ,
CommentID : comment . ID ,
@ -644,7 +651,7 @@ func (s *privSrv) LockTweet(req *web.LockTweetReq) (*web.LockTweetResp, mir.Erro
} , nil
} , nil
}
}
func ( s * privSrv ) deletePostCommentReply ( reply * core . CommentReply ) error {
func ( s * privSrv ) deletePostCommentReply ( reply * ms . CommentReply ) error {
err := s . Ds . DeleteCommentReply ( reply )
err := s . Ds . DeleteCommentReply ( reply )
if err != nil {
if err != nil {
return err
return err
@ -668,7 +675,7 @@ func (s *privSrv) deletePostCommentReply(reply *core.CommentReply) error {
return nil
return nil
}
}
func ( s * privSrv ) createPostPreHandler ( commentID int64 , userID , atUserID int64 ) ( * core. Post , * core . Comment , int64 ,
func ( s * privSrv ) createPostPreHandler ( commentID int64 , userID , atUserID int64 ) ( * ms. Post , * ms . Comment , int64 ,
error ) {
error ) {
// 加载Comment
// 加载Comment
comment , err := s . Ds . GetCommentByID ( commentID )
comment , err := s . Ds . GetCommentByID ( commentID )
@ -701,7 +708,7 @@ func (s *privSrv) createPostPreHandler(commentID int64, userID, atUserID int64)
return post , comment , atUserID , nil
return post , comment , atUserID , nil
}
}
func ( s * privSrv ) createPostStar ( postID , userID int64 ) ( * core . PostStar , mir . Error ) {
func ( s * privSrv ) createPostStar ( postID , userID int64 ) ( * ms . PostStar , mir . Error ) {
post , err := s . Ds . GetPostByID ( postID )
post , err := s . Ds . GetPostByID ( postID )
if err != nil {
if err != nil {
return nil , xerror . ServerError
return nil , xerror . ServerError
@ -727,7 +734,7 @@ func (s *privSrv) createPostStar(postID, userID int64) (*core.PostStar, mir.Erro
return star , nil
return star , nil
}
}
func ( s * privSrv ) deletePostStar ( star * core . PostStar ) mir . Error {
func ( s * privSrv ) deletePostStar ( star * ms . PostStar ) mir . Error {
post , err := s . Ds . GetPostByID ( star . PostID )
post , err := s . Ds . GetPostByID ( star . PostID )
if err != nil {
if err != nil {
return xerror . ServerError
return xerror . ServerError
@ -752,7 +759,7 @@ func (s *privSrv) deletePostStar(star *core.PostStar) mir.Error {
return nil
return nil
}
}
func ( s * privSrv ) createPostCollection ( postID , userID int64 ) ( * core . PostCollection , mir . Error ) {
func ( s * privSrv ) createPostCollection ( postID , userID int64 ) ( * ms . PostCollection , mir . Error ) {
post , err := s . Ds . GetPostByID ( postID )
post , err := s . Ds . GetPostByID ( postID )
if err != nil {
if err != nil {
return nil , xerror . ServerError
return nil , xerror . ServerError
@ -778,7 +785,7 @@ func (s *privSrv) createPostCollection(postID, userID int64) (*core.PostCollecti
return collection , nil
return collection , nil
}
}
func ( s * privSrv ) deletePostCollection ( collection * core . PostCollection ) mir . Error {
func ( s * privSrv ) deletePostCollection ( collection * ms . PostCollection ) mir . Error {
post , err := s . Ds . GetPostByID ( collection . PostID )
post , err := s . Ds . GetPostByID ( collection . PostID )
if err != nil {
if err != nil {
return xerror . ServerError
return xerror . ServerError
@ -807,7 +814,7 @@ func (s *privSrv) checkPostAttachmentIsPaid(postID, userID int64) bool {
return err == nil && bill . Model != nil && bill . ID > 0
return err == nil && bill . Model != nil && bill . ID > 0
}
}
func ( s * privSrv ) buyPostAttachment ( post * core. Post , user * core . User ) mir . Error {
func ( s * privSrv ) buyPostAttachment ( post * ms. Post , user * ms . User ) mir . Error {
if user . Balance < post . AttachmentPrice {
if user . Balance < post . AttachmentPrice {
return web . ErrInsuffientDownloadMoney
return web . ErrInsuffientDownloadMoney
}
}