diff --git a/internal/core/assets.go b/internal/core/assets.go deleted file mode 100644 index a0e4eea6..00000000 --- a/internal/core/assets.go +++ /dev/null @@ -1,5 +0,0 @@ -package core - -type AttachmentCheckService interface { - Check(uri string) error -} diff --git a/internal/core/authority.go b/internal/core/authority.go index b27db923..0b60d05c 100644 --- a/internal/core/authority.go +++ b/internal/core/authority.go @@ -42,6 +42,7 @@ type Action struct { UserId int64 } +// AuthorizationManageService 授权管理服务 type AuthorizationManageService interface { IsAllow(user *model.User, action *Action) bool GetFriendFilter(userId int64) FriendFilter diff --git a/internal/core/cache.go b/internal/core/cache.go index 7ea40217..ecbc8e35 100644 --- a/internal/core/cache.go +++ b/internal/core/cache.go @@ -32,7 +32,6 @@ func (a IndexActionT) String() string { // CacheIndexService cache index service interface type CacheIndexService interface { - VersionInfo IndexPostsService SendAction(active IndexActionT) diff --git a/internal/core/comments.go b/internal/core/comments.go new file mode 100644 index 00000000..9be29ed3 --- /dev/null +++ b/internal/core/comments.go @@ -0,0 +1,24 @@ +package core + +import ( + "github.com/rocboss/paopao-ce/internal/model" +) + +// CommentService 评论检索服务 +type CommentService interface { + GetComments(conditions *model.ConditionsT, offset, limit int) ([]*model.Comment, error) + GetCommentByID(id int64) (*model.Comment, error) + GetCommentCount(conditions *model.ConditionsT) (int64, error) + GetCommentReplyByID(id int64) (*model.CommentReply, error) + GetCommentContentsByIDs(ids []int64) ([]*model.CommentContent, error) + GetCommentRepliesByID(ids []int64) ([]*model.CommentReplyFormated, error) +} + +// CommentManageService 评论管理服务 +type CommentManageService interface { + DeleteComment(comment *model.Comment) error + CreateComment(comment *model.Comment) (*model.Comment, error) + CreateCommentReply(reply *model.CommentReply) (*model.CommentReply, error) + DeleteCommentReply(reply *model.CommentReply) error + CreateCommentContent(content *model.CommentContent) (*model.CommentContent, error) +} diff --git a/internal/core/core.go b/internal/core/core.go index 934a77e2..0c86d5ed 100644 --- a/internal/core/core.go +++ b/internal/core/core.go @@ -1,77 +1,34 @@ package core -import ( - "github.com/rocboss/paopao-ce/internal/model" -) - -// DataService data service interface that process data related logic on database +// DataService 数据服务集成 type DataService interface { + // 钱包服务 WalletService - IndexPostsService - GetComments(conditions *model.ConditionsT, offset, limit int) ([]*model.Comment, error) - GetCommentByID(id int64) (*model.Comment, error) - DeleteComment(comment *model.Comment) error - GetCommentCount(conditions *model.ConditionsT) (int64, error) - CreateComment(comment *model.Comment) (*model.Comment, error) - CreateCommentReply(reply *model.CommentReply) (*model.CommentReply, error) - GetCommentReplyByID(id int64) (*model.CommentReply, error) - DeleteCommentReply(reply *model.CommentReply) error - GetCommentContentsByIDs(ids []int64) ([]*model.CommentContent, error) - GetCommentRepliesByID(ids []int64) ([]*model.CommentReplyFormated, error) - CreateCommentContent(content *model.CommentContent) (*model.CommentContent, error) + // 消息服务 + MessageService + + // 话题服务 + TopicService + + // 广场泡泡服务 + IndexPostsService - CreateMessage(msg *model.Message) (*model.Message, error) - GetUnreadCount(userID int64) (int64, error) - GetMessageByID(id int64) (*model.Message, error) - ReadMessage(message *model.Message) error - GetMessages(conditions *model.ConditionsT, offset, limit int) ([]*model.MessageFormated, error) - GetMessageCount(conditions *model.ConditionsT) (int64, error) + // 推文服务 + TweetService + TweetManageService + TweetHelpService - CreateAttachment(attachment *model.Attachment) (*model.Attachment, error) - CreatePost(post *model.Post) (*model.Post, error) - DeletePost(post *model.Post) error - LockPost(post *model.Post) error - StickPost(post *model.Post) error - VisiblePost(post *model.Post, visibility model.PostVisibleT) error - GetPostByID(id int64) (*model.Post, error) - GetPosts(conditions *model.ConditionsT, offset, limit int) ([]*model.Post, error) - MergePosts(posts []*model.Post) ([]*model.PostFormated, error) - RevampPosts(posts []*model.PostFormated) ([]*model.PostFormated, error) - GetPostCount(conditions *model.ConditionsT) (int64, error) - UpdatePost(post *model.Post) error - GetUserPostStar(postID, userID int64) (*model.PostStar, error) - GetUserPostStars(userID int64, offset, limit int) ([]*model.PostStar, error) - GetUserPostStarCount(userID int64) (int64, error) - CreatePostStar(postID, userID int64) (*model.PostStar, error) - DeletePostStar(p *model.PostStar) error - GetUserPostCollection(postID, userID int64) (*model.PostCollection, error) - GetUserPostCollections(userID int64, offset, limit int) ([]*model.PostCollection, error) - GetUserPostCollectionCount(userID int64) (int64, error) - GetUserWalletBills(userID int64, offset, limit int) ([]*model.WalletStatement, error) - GetUserWalletBillCount(userID int64) (int64, error) - CreatePostCollection(postID, userID int64) (*model.PostCollection, error) - DeletePostCollection(p *model.PostCollection) error - GetPostAttatchmentBill(postID, userID int64) (*model.PostAttachmentBill, error) - CreatePostContent(content *model.PostContent) (*model.PostContent, error) - GetPostContentsByIDs(ids []int64) ([]*model.PostContent, error) - GetPostContentByID(id int64) (*model.PostContent, error) + // 附件检测服务 + AttachmentCheckService - CreateTag(tag *model.Tag) (*model.Tag, error) - DeleteTag(tag *model.Tag) error - GetTags(conditions *model.ConditionsT, offset, limit int) ([]*model.Tag, error) + // 评论服务 + CommentService + CommentManageService - GetUserByID(id int64) (*model.User, error) - GetUserByUsername(username string) (*model.User, error) - GetUserByPhone(phone string) (*model.User, error) - GetUsersByIDs(ids []int64) ([]*model.User, error) - GetUsersByKeyword(keyword string) ([]*model.User, error) - GetTagsByKeyword(keyword string) ([]*model.Tag, error) - CreateUser(user *model.User) (*model.User, error) - UpdateUser(user *model.User) error - GetLatestPhoneCaptcha(phone string) (*model.Captcha, error) - UsePhoneCaptcha(captcha *model.Captcha) error - SendPhoneCaptcha(phone string) error + // 用户服务 + UserManageService - IsFriend(userID int64, friendID int64) bool + // 安全服务 + SecurityService } diff --git a/internal/core/index.go b/internal/core/index.go deleted file mode 100644 index be83abec..00000000 --- a/internal/core/index.go +++ /dev/null @@ -1,9 +0,0 @@ -package core - -import ( - "github.com/rocboss/paopao-ce/internal/model" -) - -type IndexPostsService interface { - IndexPosts(user *model.User, offset int, limit int) ([]*model.PostFormated, error) -} diff --git a/internal/core/messages.go b/internal/core/messages.go new file mode 100644 index 00000000..aa08a1f8 --- /dev/null +++ b/internal/core/messages.go @@ -0,0 +1,15 @@ +package core + +import ( + "github.com/rocboss/paopao-ce/internal/model" +) + +// MessageService 消息服务 +type MessageService interface { + CreateMessage(msg *model.Message) (*model.Message, error) + GetUnreadCount(userID int64) (int64, error) + GetMessageByID(id int64) (*model.Message, error) + ReadMessage(message *model.Message) error + GetMessages(conditions *model.ConditionsT, offset, limit int) ([]*model.MessageFormated, error) + GetMessageCount(conditions *model.ConditionsT) (int64, error) +} diff --git a/internal/core/search.go b/internal/core/search.go index 7e8b1db5..ce738d2f 100644 --- a/internal/core/search.go +++ b/internal/core/search.go @@ -26,8 +26,6 @@ type DocItems []map[string]interface{} // TweetSearchService tweet search service interface type TweetSearchService interface { - VersionInfo - IndexName() string AddDocuments(documents DocItems, primaryKey ...string) (bool, error) DeleteDocuments(identifiers []string) error diff --git a/internal/core/security.go b/internal/core/security.go new file mode 100644 index 00000000..63a7ac21 --- /dev/null +++ b/internal/core/security.go @@ -0,0 +1,17 @@ +package core + +import ( + "github.com/rocboss/paopao-ce/internal/model" +) + +// SecurityService 安全相关服务 +type SecurityService interface { + GetLatestPhoneCaptcha(phone string) (*model.Captcha, error) + UsePhoneCaptcha(captcha *model.Captcha) error + SendPhoneCaptcha(phone string) error +} + +// 附件检测服务 +type AttachmentCheckService interface { + CheckAttachment(uri string) error +} diff --git a/internal/core/storage.go b/internal/core/storage.go index 1be1d690..f1aa7ce7 100644 --- a/internal/core/storage.go +++ b/internal/core/storage.go @@ -6,8 +6,6 @@ import ( // ObjectStorageService storage service interface that implement base AliOSS、MINIO or other type ObjectStorageService interface { - VersionInfo - PutObject(objectKey string, reader io.Reader, objectSize int64, contentType string) (string, error) SignURL(objectKey string, expiredInSec int64) (string, error) ObjectURL(objetKey string) string diff --git a/internal/core/topics.go b/internal/core/topics.go new file mode 100644 index 00000000..a894f9b2 --- /dev/null +++ b/internal/core/topics.go @@ -0,0 +1,13 @@ +package core + +import ( + "github.com/rocboss/paopao-ce/internal/model" +) + +// TopicService 话题服务 +type TopicService interface { + CreateTag(tag *model.Tag) (*model.Tag, error) + DeleteTag(tag *model.Tag) error + GetTags(conditions *model.ConditionsT, offset, limit int) ([]*model.Tag, error) + GetTagsByKeyword(keyword string) ([]*model.Tag, error) +} diff --git a/internal/core/tweets.go b/internal/core/tweets.go new file mode 100644 index 00000000..5c61ba2d --- /dev/null +++ b/internal/core/tweets.go @@ -0,0 +1,48 @@ +package core + +import ( + "github.com/rocboss/paopao-ce/internal/model" +) + +// TweetService 推文检索服务 +type TweetService interface { + GetPostByID(id int64) (*model.Post, error) + GetPosts(conditions *model.ConditionsT, offset, limit int) ([]*model.Post, error) + GetPostCount(conditions *model.ConditionsT) (int64, error) + GetUserPostStar(postID, userID int64) (*model.PostStar, error) + GetUserPostStars(userID int64, offset, limit int) ([]*model.PostStar, error) + GetUserPostStarCount(userID int64) (int64, error) + GetUserPostCollection(postID, userID int64) (*model.PostCollection, error) + GetUserPostCollections(userID int64, offset, limit int) ([]*model.PostCollection, error) + GetUserPostCollectionCount(userID int64) (int64, error) + GetPostAttatchmentBill(postID, userID int64) (*model.PostAttachmentBill, error) + GetPostContentsByIDs(ids []int64) ([]*model.PostContent, error) + GetPostContentByID(id int64) (*model.PostContent, error) +} + +// TweetManageService 推文管理服务,包括创建/删除/更新推文 +type TweetManageService interface { + CreateAttachment(attachment *model.Attachment) (*model.Attachment, error) + CreatePost(post *model.Post) (*model.Post, error) + DeletePost(post *model.Post) error + LockPost(post *model.Post) error + StickPost(post *model.Post) error + VisiblePost(post *model.Post, visibility model.PostVisibleT) error + UpdatePost(post *model.Post) error + CreatePostStar(postID, userID int64) (*model.PostStar, error) + DeletePostStar(p *model.PostStar) error + CreatePostCollection(postID, userID int64) (*model.PostCollection, error) + DeletePostCollection(p *model.PostCollection) error + CreatePostContent(content *model.PostContent) (*model.PostContent, error) +} + +// TweetHelpService 推文辅助服务 +type TweetHelpService interface { + RevampPosts(posts []*model.PostFormated) ([]*model.PostFormated, error) + MergePosts(posts []*model.Post) ([]*model.PostFormated, error) +} + +// IndexPostsService 广场首页推文列表服务 +type IndexPostsService interface { + IndexPosts(user *model.User, offset int, limit int) ([]*model.PostFormated, error) +} diff --git a/internal/core/user.go b/internal/core/user.go new file mode 100644 index 00000000..36ceabfc --- /dev/null +++ b/internal/core/user.go @@ -0,0 +1,17 @@ +package core + +import ( + "github.com/rocboss/paopao-ce/internal/model" +) + +// UserManageService 用户管理服务 +type UserManageService interface { + GetUserByID(id int64) (*model.User, error) + GetUserByUsername(username string) (*model.User, error) + GetUserByPhone(phone string) (*model.User, error) + GetUsersByIDs(ids []int64) ([]*model.User, error) + GetUsersByKeyword(keyword string) ([]*model.User, error) + CreateUser(user *model.User) (*model.User, error) + UpdateUser(user *model.User) error + IsFriend(userID int64, friendID int64) bool +} diff --git a/internal/core/version.go b/internal/core/version.go deleted file mode 100644 index fd8bab2d..00000000 --- a/internal/core/version.go +++ /dev/null @@ -1,10 +0,0 @@ -package core - -import ( - "github.com/Masterminds/semver/v3" -) - -type VersionInfo interface { - Name() string - Version() *semver.Version -} diff --git a/internal/core/wallet.go b/internal/core/wallet.go index e6cea7c9..5b3a3391 100644 --- a/internal/core/wallet.go +++ b/internal/core/wallet.go @@ -6,6 +6,8 @@ import ( // WalletService wallet service interface type WalletService interface { + GetUserWalletBills(userID int64, offset, limit int) ([]*model.WalletStatement, error) + GetUserWalletBillCount(userID int64) (int64, error) GetRechargeByID(id int64) (*model.WalletRecharge, error) CreateRecharge(userId, amount int64) (*model.WalletRecharge, error) HandleRechargeSuccess(recharge *model.WalletRecharge, tradeNo string) error diff --git a/internal/dao/attachment.go b/internal/dao/attachment.go index 3bb1c82c..9e56f6f6 100644 --- a/internal/dao/attachment.go +++ b/internal/dao/attachment.go @@ -11,7 +11,7 @@ func (d *dataServant) CreateAttachment(attachment *model.Attachment) (*model.Att return attachment.Create(d.engine) } -func (s *attachmentCheckServant) Check(uri string) error { +func (s *attachmentCheckServant) CheckAttachment(uri string) error { if strings.Index(uri, s.domain) != 0 { return fmt.Errorf("附件非本站资源") } diff --git a/internal/dao/cache_index_big.go b/internal/dao/cache_index_big.go index e39cfab1..c6a21e99 100644 --- a/internal/dao/cache_index_big.go +++ b/internal/dao/cache_index_big.go @@ -14,7 +14,7 @@ import ( "github.com/sirupsen/logrus" ) -func newBigCacheIndexServant(getIndexPosts indexPostsFunc) *bigCacheIndexServant { +func newBigCacheIndexServant(getIndexPosts indexPostsFunc) (*bigCacheIndexServant, versionInfo) { s := conf.BigCacheIndexSetting config := bigcache.DefaultConfig(s.ExpireInSecond) @@ -46,7 +46,7 @@ func newBigCacheIndexServant(getIndexPosts indexPostsFunc) *bigCacheIndexServant // 启动索引更新器 go cacheIndex.startIndexPosts() - return cacheIndex + return cacheIndex, cacheIndex } func (s *bigCacheIndexServant) IndexPosts(user *model.User, offset int, limit int) ([]*model.PostFormated, error) { @@ -153,10 +153,10 @@ func (s *bigCacheIndexServant) startIndexPosts() { } } -func (s *bigCacheIndexServant) Name() string { +func (s *bigCacheIndexServant) name() string { return "BigCacheIndex" } -func (s *bigCacheIndexServant) Version() *semver.Version { +func (s *bigCacheIndexServant) version() *semver.Version { return semver.MustParse("v0.1.0") } diff --git a/internal/dao/cache_index_none.go b/internal/dao/cache_index_none.go index d0431c6e..db44fbe0 100644 --- a/internal/dao/cache_index_none.go +++ b/internal/dao/cache_index_none.go @@ -6,10 +6,11 @@ import ( "github.com/rocboss/paopao-ce/internal/model" ) -func newNoneCacheIndexServant(getIndexPosts indexPostsFunc) *noneCacheIndexServant { - return &noneCacheIndexServant{ +func newNoneCacheIndexServant(getIndexPosts indexPostsFunc) (*noneCacheIndexServant, versionInfo) { + obj := &noneCacheIndexServant{ getIndexPosts: getIndexPosts, } + return obj, obj } func (s *noneCacheIndexServant) IndexPosts(user *model.User, offset int, limit int) ([]*model.PostFormated, error) { @@ -20,10 +21,10 @@ func (s *noneCacheIndexServant) SendAction(act core.IndexActionT) { // empty } -func (s *noneCacheIndexServant) Name() string { +func (s *noneCacheIndexServant) name() string { return "NoneCacheIndex" } -func (s *noneCacheIndexServant) Version() *semver.Version { +func (s *noneCacheIndexServant) version() *semver.Version { return semver.MustParse("v0.1.0") } diff --git a/internal/dao/cache_index_simple.go b/internal/dao/cache_index_simple.go index 1d82a37e..47ad6f78 100644 --- a/internal/dao/cache_index_simple.go +++ b/internal/dao/cache_index_simple.go @@ -1,7 +1,6 @@ package dao import ( - "errors" "time" "github.com/Masterminds/semver/v3" @@ -11,11 +10,7 @@ import ( "github.com/sirupsen/logrus" ) -var ( - errNotExist = errors.New("index posts cache not exist") -) - -func newSimpleCacheIndexServant(getIndexPosts indexPostsFunc) *simpleCacheIndexServant { +func newSimpleCacheIndexServant(getIndexPosts indexPostsFunc) (*simpleCacheIndexServant, versionInfo) { s := conf.SimpleCacheIndexSetting cacheIndex := &simpleCacheIndexServant{ getIndexPosts: getIndexPosts, @@ -46,7 +41,7 @@ func newSimpleCacheIndexServant(getIndexPosts indexPostsFunc) *simpleCacheIndexS cacheIndex.atomicIndex.Store(cacheIndex.indexPosts) go cacheIndex.startIndexPosts() - return cacheIndex + return cacheIndex, cacheIndex } func (s *simpleCacheIndexServant) IndexPosts(user *model.User, offset int, limit int) ([]*model.PostFormated, error) { @@ -114,10 +109,10 @@ func (s *simpleCacheIndexServant) startIndexPosts() { } } -func (s *simpleCacheIndexServant) Name() string { +func (s *simpleCacheIndexServant) name() string { return "SimpleCacheIndex" } -func (s *simpleCacheIndexServant) Version() *semver.Version { +func (s *simpleCacheIndexServant) version() *semver.Version { return semver.MustParse("v0.1.0") } diff --git a/internal/dao/dao.go b/internal/dao/dao.go index 00a0fcff..e7ce2317 100644 --- a/internal/dao/dao.go +++ b/internal/dao/dao.go @@ -9,12 +9,12 @@ import ( var ( _ core.DataService = (*dataServant)(nil) - _ core.AttachmentCheckService = (*attachmentCheckServant)(nil) _ core.AuthorizationManageService = (*simpleAuthorizationManageService)(nil) ) type dataServant struct { core.CacheIndexService + core.AttachmentCheckService ams core.AuthorizationManageService engine *gorm.DB @@ -30,29 +30,32 @@ type attachmentCheckServant struct { func NewDataService() core.DataService { ds := &dataServant{ + ams: newAuthorizationManageService(), + AttachmentCheckService: NewAttachmentCheckService(), + engine: conf.DBEngine, - ams: NewAuthorizationManageService(), } // initialize CacheIndex if needed + var v versionInfo if conf.CfgIf("SimpleCacheIndex") { - ds.CacheIndexService = newSimpleCacheIndexServant(ds.simpleCacheIndexGetPosts) + ds.CacheIndexService, v = newSimpleCacheIndexServant(ds.simpleCacheIndexGetPosts) } else if conf.CfgIf("BigCacheIndex") { - ds.CacheIndexService = newBigCacheIndexServant(ds.getIndexPosts) + ds.CacheIndexService, v = newBigCacheIndexServant(ds.getIndexPosts) } else { - ds.CacheIndexService = newNoneCacheIndexServant(ds.getIndexPosts) + ds.CacheIndexService, v = newNoneCacheIndexServant(ds.getIndexPosts) } - logrus.Infof("use %s as cache index service by version: %s", ds.CacheIndexService.Name(), ds.CacheIndexService.Version()) + logrus.Infof("use %s as cache index service by version: %s", v.name(), v.version()) return ds } -func NewAuthorizationManageService() core.AuthorizationManageService { - return newSimpleAuthorizationManageService() -} - func NewAttachmentCheckService() core.AttachmentCheckService { return &attachmentCheckServant{ domain: getOssDomain(), } } + +func newAuthorizationManageService() core.AuthorizationManageService { + return newSimpleAuthorizationManageService() +} diff --git a/internal/dao/oss.go b/internal/dao/oss.go index a85bb8d9..62294e1e 100644 --- a/internal/dao/oss.go +++ b/internal/dao/oss.go @@ -34,22 +34,23 @@ type minioServant struct { type s3Servant = minioServant func NewObjectStorageService() (oss core.ObjectStorageService) { + var v versionInfo if conf.CfgIf("AliOSS") { - oss = newAliossServent() + oss, v = newAliossServent() } else if conf.CfgIf("MinIO") { - oss = newMinioServeant() + oss, v = newMinioServeant() } else if conf.CfgIf("S3") { - oss = newS3Servent() - logrus.Infof("use S3 as object storage by version %s", oss.Version()) + oss, v = newS3Servent() + logrus.Infof("use S3 as object storage by version %s", v.version()) return } else if conf.CfgIf("LocalOSS") { - oss = newLocalossServent() + oss, v = newLocalossServent() } else { // default use AliOSS as object storage service - oss = newAliossServent() - logrus.Infof("use default AliOSS as object storage by version %s", oss.Version()) + oss, v = newAliossServent() + logrus.Infof("use default AliOSS as object storage by version %s", v.version()) return } - logrus.Infof("use %s as object storage by version %s", oss.Name(), oss.Version()) + logrus.Infof("use %s as object storage by version %s", v.name(), v.version()) return } diff --git a/internal/dao/oss_alioss.go b/internal/dao/oss_alioss.go index 641d4a54..71c8aa1d 100644 --- a/internal/dao/oss_alioss.go +++ b/internal/dao/oss_alioss.go @@ -11,7 +11,7 @@ import ( "github.com/sirupsen/logrus" ) -func newAliossServent() *aliossServant { +func newAliossServent() (*aliossServant, versionInfo) { client, err := oss.New(conf.AliOSSSetting.Endpoint, conf.AliOSSSetting.AccessKeyID, conf.AliOSSSetting.AccessKeySecret) if err != nil { logrus.Fatalf("alioss.New err: %v", err) @@ -22,17 +22,18 @@ func newAliossServent() *aliossServant { logrus.Fatalf("client.Bucket err: %v", err) } - return &aliossServant{ + obj := &aliossServant{ bucket: bucket, domain: getOssDomain(), } + return obj, obj } -func (s *aliossServant) Name() string { +func (s *aliossServant) name() string { return "AliOSS" } -func (s *aliossServant) Version() *semver.Version { +func (s *aliossServant) version() *semver.Version { return semver.MustParse("v0.1.0") } diff --git a/internal/dao/oss_local.go b/internal/dao/oss_local.go index 46983260..a7fa5dfa 100644 --- a/internal/dao/oss_local.go +++ b/internal/dao/oss_local.go @@ -14,23 +14,24 @@ import ( "github.com/sirupsen/logrus" ) -func newLocalossServent() *localossServant { +func newLocalossServent() (*localossServant, versionInfo) { savePath, err := filepath.Abs(conf.LocalOSSSetting.SavePath) if err != nil { logrus.Fatalf("get localOSS save path err: %v", err) } - return &localossServant{ + obj := &localossServant{ savePath: savePath + "/" + conf.LocalOSSSetting.Bucket + "/", domain: getOssDomain(), } + return obj, obj } -func (s *localossServant) Name() string { +func (s *localossServant) name() string { return "LocalOSS" } -func (s *localossServant) Version() *semver.Version { +func (s *localossServant) version() *semver.Version { return semver.MustParse("v0.1.0") } diff --git a/internal/dao/oss_minio.go b/internal/dao/oss_minio.go index 470f03b1..c10ee1a7 100644 --- a/internal/dao/oss_minio.go +++ b/internal/dao/oss_minio.go @@ -14,7 +14,7 @@ import ( "github.com/sirupsen/logrus" ) -func newMinioServeant() *minioServant { +func newMinioServeant() (*minioServant, versionInfo) { // Initialize minio client object. client, err := minio.New(conf.MinIOSetting.Endpoint, &minio.Options{ Creds: credentials.NewStaticV4(conf.MinIOSetting.AccessKey, conf.MinIOSetting.SecretKey, ""), @@ -23,18 +23,20 @@ func newMinioServeant() *minioServant { if err != nil { logrus.Fatalf("minio.New err: %v", err) } - return &minioServant{ + + obj := &minioServant{ client: client, bucket: conf.MinIOSetting.Bucket, domain: getOssDomain(), } + return obj, obj } -func (s *minioServant) Name() string { +func (s *minioServant) name() string { return "MinIO" } -func (s *minioServant) Version() *semver.Version { +func (s *minioServant) version() *semver.Version { return semver.MustParse("v0.1.0") } diff --git a/internal/dao/oss_s3.go b/internal/dao/oss_s3.go index ee8c1284..a0672e5b 100644 --- a/internal/dao/oss_s3.go +++ b/internal/dao/oss_s3.go @@ -7,7 +7,7 @@ import ( "github.com/sirupsen/logrus" ) -func newS3Servent() *s3Servant { +func newS3Servent() (*s3Servant, versionInfo) { // Initialize s3 client object use minio-go. client, err := minio.New(conf.S3Setting.Endpoint, &minio.Options{ Creds: credentials.NewStaticV4(conf.S3Setting.AccessKey, conf.S3Setting.SecretKey, ""), @@ -16,9 +16,11 @@ func newS3Servent() *s3Servant { if err != nil { logrus.Fatalf("s3.New err: %v", err) } - return &s3Servant{ + + obj := &s3Servant{ client: client, bucket: conf.MinIOSetting.Bucket, domain: getOssDomain(), } + return obj, obj } diff --git a/internal/dao/search.go b/internal/dao/search.go index fb310ffe..5c51e066 100644 --- a/internal/dao/search.go +++ b/internal/dao/search.go @@ -59,15 +59,16 @@ func NewTweetSearchService() core.TweetSearchService { } bts.updateDocsCh = make(chan *documents, capacity) + var v versionInfo if conf.CfgIf("Zinc") { - bts.ts = newZincTweetSearchServant() + bts.ts, v = newZincTweetSearchServant() } else if conf.CfgIf("Meili") { - bts.ts = newMeiliTweetSearchServant() + bts.ts, v = newMeiliTweetSearchServant() } else { // default use Zinc as tweet search service - bts.ts = newZincTweetSearchServant() + bts.ts, v = newZincTweetSearchServant() } - logrus.Infof("use %s as tweet search serice by version %s", bts.ts.Name(), bts.ts.Version()) + logrus.Infof("use %s as tweet search serice by version %s", v.name(), v.version()) numWorker := conf.TweetSearchSetting.MinWorker if numWorker < 5 { diff --git a/internal/dao/search_bridge.go b/internal/dao/search_bridge.go index f4d1c1b3..5625810f 100644 --- a/internal/dao/search_bridge.go +++ b/internal/dao/search_bridge.go @@ -1,20 +1,11 @@ package dao import ( - "github.com/Masterminds/semver/v3" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/model" "github.com/sirupsen/logrus" ) -func (s *bridgeTweetSearchServant) Name() string { - return "BridgeTweetSearch" -} - -func (s *bridgeTweetSearchServant) Version() *semver.Version { - return semver.MustParse("v0.1.0") -} - func (s *bridgeTweetSearchServant) IndexName() string { return s.ts.IndexName() } diff --git a/internal/dao/search_meili.go b/internal/dao/search_meili.go index 32eb4a7a..1544dd33 100644 --- a/internal/dao/search_meili.go +++ b/internal/dao/search_meili.go @@ -12,7 +12,7 @@ import ( "github.com/sirupsen/logrus" ) -func newMeiliTweetSearchServant() *meiliTweetSearchServant { +func newMeiliTweetSearchServant() (*meiliTweetSearchServant, versionInfo) { s := conf.MeiliSetting client := meilisearch.NewClient(meilisearch.ClientConfig{ Host: s.Endpoint(), @@ -35,9 +35,9 @@ func newMeiliTweetSearchServant() *meiliTweetSearchServant { index.UpdateFilterableAttributes(&filterableAttributes) } - return &meiliTweetSearchServant{ + obj := &meiliTweetSearchServant{ tweetSearchFilter: tweetSearchFilter{ - ams: NewAuthorizationManageService(), + ams: newAuthorizationManageService(), }, client: client, index: client.Index(s.Index), @@ -45,13 +45,14 @@ func newMeiliTweetSearchServant() *meiliTweetSearchServant { privateFilter: fmt.Sprintf("visibility=%d AND user_id=", model.PostVisitPrivate), friendFilter: fmt.Sprintf("visibility=%d", model.PostVisitFriend), } + return obj, obj } -func (s *meiliTweetSearchServant) Name() string { +func (s *meiliTweetSearchServant) name() string { return "Meili" } -func (s *meiliTweetSearchServant) Version() *semver.Version { +func (s *meiliTweetSearchServant) version() *semver.Version { return semver.MustParse("v0.2.0") } diff --git a/internal/dao/search_zinc.go b/internal/dao/search_zinc.go index b511749e..71f3c789 100644 --- a/internal/dao/search_zinc.go +++ b/internal/dao/search_zinc.go @@ -12,11 +12,11 @@ import ( "github.com/sirupsen/logrus" ) -func newZincTweetSearchServant() *zincTweetSearchServant { +func newZincTweetSearchServant() (*zincTweetSearchServant, versionInfo) { s := conf.ZincSetting zts := &zincTweetSearchServant{ tweetSearchFilter: tweetSearchFilter{ - ams: NewAuthorizationManageService(), + ams: newAuthorizationManageService(), }, indexName: s.Index, client: zinc.NewClient(s), @@ -26,14 +26,14 @@ func newZincTweetSearchServant() *zincTweetSearchServant { } zts.createIndex() - return zts + return zts, zts } -func (s *zincTweetSearchServant) Name() string { +func (s *zincTweetSearchServant) name() string { return "Zinc" } -func (s *zincTweetSearchServant) Version() *semver.Version { +func (s *zincTweetSearchServant) version() *semver.Version { return semver.MustParse("v0.2.0") } diff --git a/internal/dao/version.go b/internal/dao/version.go new file mode 100644 index 00000000..8cab2d84 --- /dev/null +++ b/internal/dao/version.go @@ -0,0 +1,11 @@ +package dao + +import ( + "github.com/Masterminds/semver/v3" +) + +// versionInfo 版本信息 +type versionInfo interface { + name() string + version() *semver.Version +} diff --git a/internal/routers/api/user.go b/internal/routers/api/user.go index 1b4e1807..068f5c87 100644 --- a/internal/routers/api/user.go +++ b/internal/routers/api/user.go @@ -204,7 +204,7 @@ func ChangeAvatar(c *gin.Context) { user = u.(*model.User) } - if err := attachmentChecker.Check(param.Avatar); err != nil { + if err := attachmentChecker.CheckAttachment(param.Avatar); err != nil { response.ToErrorResponse(errcode.InvalidParams) return } diff --git a/internal/service/comment.go b/internal/service/comment.go index 8805c106..1bf6bbeb 100644 --- a/internal/service/comment.go +++ b/internal/service/comment.go @@ -115,7 +115,7 @@ func CreatePostComment(ctx *gin.Context, userID int64, param CommentCreationReq) for _, item := range param.Contents { // 检查附件是否是本站资源 if item.Type == model.CONTENT_TYPE_IMAGE || item.Type == model.CONTENT_TYPE_VIDEO || item.Type == model.CONTENT_TYPE_ATTACHMENT { - if err := attachmentChecker.Check(item.Content); err != nil { + if err := ds.CheckAttachment(item.Content); err != nil { continue } } diff --git a/internal/service/post.go b/internal/service/post.go index 4e2f6fec..c7876a15 100644 --- a/internal/service/post.go +++ b/internal/service/post.go @@ -75,7 +75,7 @@ func (p *PostContentItem) Check() error { // 检查附件是否是本站资源 if p.Type == model.CONTENT_TYPE_IMAGE || p.Type == model.CONTENT_TYPE_VIDEO || p.Type == model. CONTENT_TYPE_ATTACHMENT { - if err := attachmentChecker.Check(p.Content); err != nil { + if err := ds.CheckAttachment(p.Content); err != nil { return err } } diff --git a/internal/service/service.go b/internal/service/service.go index 8593f754..268a2558 100644 --- a/internal/service/service.go +++ b/internal/service/service.go @@ -9,13 +9,11 @@ import ( var ( ds core.DataService ts core.TweetSearchService - attachmentChecker core.AttachmentCheckService DisablePhoneVerify bool ) func Initialize() { ds = dao.NewDataService() ts = dao.NewTweetSearchService() - attachmentChecker = dao.NewAttachmentCheckService() DisablePhoneVerify = !conf.CfgIf("Sms") }