实现 MinIO 对象存储图片流水线(可迁移 OSS)

- 新增 S3 兼容 Storage 抽象与 MinIO 实现,compose 启动 MinIO
- 上传接口:校验 → 缩放 → WebP → 主图/缩略图入库
- 消息图片 content 改为对象 URL,拒绝 base64
- 工作台/访客端改为先上传再发消息
This commit is contained in:
yml2213
2026-07-15 12:21:31 +08:00
parent 85b407fddf
commit ec2f12c6ed
20 changed files with 907 additions and 108 deletions
+27
View File
@@ -0,0 +1,27 @@
package storage
import (
"crypto/rand"
"encoding/hex"
"strings"
)
func randomHex(n int) string {
b := make([]byte, n)
_, _ = rand.Read(b)
return hex.EncodeToString(b)
}
// NormalizePublicBase 去掉末尾斜杠
func NormalizePublicBase(base string) string {
return strings.TrimRight(strings.TrimSpace(base), "/")
}
// IsAllowedObjectURL 判断 url 是否属于当前存储公网前缀
func IsAllowedObjectURL(publicBase, url string) bool {
base := NormalizePublicBase(publicBase)
if base == "" || url == "" {
return false
}
return strings.HasPrefix(url, base+"/") || url == base
}