Merge pull request #146 from alimy/pr-optimize-service-define

optimize core service define
pull/147/head
Michael Li 2 years ago committed by GitHub
commit 2531ed940f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,5 +0,0 @@
package core
type AttachmentCheckService interface {
Check(uri string) error
}

@ -42,6 +42,7 @@ type Action struct {
UserId int64
}
// AuthorizationManageService 授权管理服务
type AuthorizationManageService interface {
IsAllow(user *model.User, action *Action) bool
GetFriendFilter(userId int64) FriendFilter

@ -32,7 +32,6 @@ func (a IndexActionT) String() string {
// CacheIndexService cache index service interface
type CacheIndexService interface {
VersionInfo
IndexPostsService
SendAction(active IndexActionT)

@ -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)
}

@ -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
}

@ -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)
}

@ -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)
}

@ -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

@ -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
}

@ -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

@ -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)
}

@ -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)
}

@ -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
}

@ -1,10 +0,0 @@
package core
import (
"github.com/Masterminds/semver/v3"
)
type VersionInfo interface {
Name() string
Version() *semver.Version
}

@ -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

@ -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("附件非本站资源")
}

@ -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")
}

@ -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")
}

@ -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")
}

@ -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()
}

@ -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
}

@ -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")
}

@ -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")
}

@ -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")
}

@ -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
}

@ -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 {

@ -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()
}

@ -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")
}

@ -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")
}

@ -0,0 +1,11 @@
package dao
import (
"github.com/Masterminds/semver/v3"
)
// versionInfo 版本信息
type versionInfo interface {
name() string
version() *semver.Version
}

@ -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
}

@ -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
}
}

@ -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
}
}

@ -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")
}

Loading…
Cancel
Save