feat(upload): integrate upload service for chat image validation and S3 uploads
- Added UploadService to handle image uploads and validation for chat messages. - Updated ChatService and MessageService to utilize UploadService for validating image segments in messages. - Enhanced wire generation to inject UploadService into relevant services. - Introduced UploadImageBytes method in UploadService for uploading images directly from memory. - Added TrustedPublicURLPrefix method in S3 Client for generating public URLs for uploaded images.
This commit is contained in:
@@ -35,10 +35,12 @@ type MessageService struct {
|
||||
|
||||
// 基础缓存(用于简单缓存操作)
|
||||
baseCache cache.Cache
|
||||
|
||||
uploadService *UploadService
|
||||
}
|
||||
|
||||
// NewMessageService 创建消息服务
|
||||
func NewMessageService(db *gorm.DB, messageRepo *repository.MessageRepository, cacheBackend cache.Cache) *MessageService {
|
||||
func NewMessageService(db *gorm.DB, messageRepo *repository.MessageRepository, cacheBackend cache.Cache, uploadService *UploadService) *MessageService {
|
||||
// 创建适配器
|
||||
convRepoAdapter := cache.NewConversationRepositoryAdapter(messageRepo)
|
||||
msgRepoAdapter := cache.NewMessageRepositoryAdapter(messageRepo)
|
||||
@@ -56,6 +58,7 @@ func NewMessageService(db *gorm.DB, messageRepo *repository.MessageRepository, c
|
||||
messageRepo: messageRepo,
|
||||
conversationCache: conversationCache,
|
||||
baseCache: cacheBackend,
|
||||
uploadService: uploadService,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +77,12 @@ func (s *MessageService) SendMessage(ctx context.Context, senderID, receiverID s
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if s.uploadService != nil {
|
||||
if err := s.uploadService.ValidateChatMessageImageSegments(segments); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
msg := &model.Message{
|
||||
ConversationID: conv.ID,
|
||||
SenderID: senderID,
|
||||
|
||||
Reference in New Issue
Block a user