feat(upload): integrate upload service for chat image validation and S3 uploads
All checks were successful
Build Backend / build (push) Successful in 13m35s
Build Backend / build-docker (push) Successful in 1m11s

- 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:
lafay
2026-03-25 03:57:40 +08:00
parent a887e8ea23
commit 28a45caad3
7 changed files with 150 additions and 13 deletions

View File

@@ -88,6 +88,18 @@ func (c *Client) UploadData(ctx context.Context, objectName string, data []byte,
return fmt.Sprintf("%s://%s/%s/%s", scheme, c.domain, c.bucket, objectName), nil
}
// TrustedPublicURLPrefix 本站公开对象 URL 前缀scheme://domain/bucket/),用于校验聊天图片等仅引用本地上传资源。
func (c *Client) TrustedPublicURLPrefix() string {
if c == nil || c.domain == "" || c.bucket == "" {
return ""
}
scheme := "https"
if c.domain == c.bucket {
scheme = "http"
}
return fmt.Sprintf("%s://%s/%s/", scheme, c.domain, c.bucket)
}
// GetURL 获取文件URL - 使用自定义域名
func (c *Client) GetURL(ctx context.Context, objectName string) (string, error) {
// 使用自定义域名构建URL包含bucket名称