修复 MinIO 端口冲突并优化顶栏 IP 展示

- MinIO 宿主机端口改为 9100/9101,避免与 hfb-minio 冲突
- 测试与配置默认 PublicBase 同步为 9100
- 工作台顶栏固定展示 IP|地区,详情回填会话元数据
- 种子数据补充访客 IP/地区示例
This commit is contained in:
yml2213
2026-07-15 12:39:39 +08:00
parent ec2f12c6ed
commit 32d88f42e7
8 changed files with 49 additions and 46 deletions
+5 -4
View File
@@ -34,13 +34,13 @@ type JWTConfig struct {
// StorageConfig S3 兼容对象存储(MinIO / OSS / COS / S3 共用字段)
type StorageConfig struct {
Endpoint string // 如 localhost:9000 或 oss-cn-hangzhou.aliyuncs.com
Endpoint string // 如 localhost:9100(开发 MinIO或 oss-cn-hangzhou.aliyuncs.com
AccessKey string
SecretKey string
Bucket string
UseSSL bool
Region string
PublicBase string // 浏览器可访问前缀,如 http://localhost:9000/kefu
PublicBase string // 浏览器可访问前缀,如 http://localhost:9100/kefu
MaxUploadMB int
MaxImageEdge int // 最长边像素
WebPQuality float32
@@ -65,13 +65,14 @@ func Load() *Config {
ExpireTime: 24 * time.Hour,
},
Storage: StorageConfig{
Endpoint: getEnv("STORAGE_ENDPOINT", "localhost:9000"),
// 默认映射宿主机 9100→容器 9000,避免与其它项目 MinIO 冲突
Endpoint: getEnv("STORAGE_ENDPOINT", "localhost:9100"),
AccessKey: getEnv("STORAGE_ACCESS_KEY", "minioadmin"),
SecretKey: getEnv("STORAGE_SECRET_KEY", "minioadmin"),
Bucket: getEnv("STORAGE_BUCKET", "kefu"),
UseSSL: getEnvBool("STORAGE_USE_SSL", false),
Region: getEnv("STORAGE_REGION", "us-east-1"),
PublicBase: getEnv("STORAGE_PUBLIC_BASE_URL", "http://localhost:9000/kefu"),
PublicBase: getEnv("STORAGE_PUBLIC_BASE_URL", "http://localhost:9100/kefu"),
MaxUploadMB: getEnvInt("STORAGE_MAX_UPLOAD_MB", 10),
MaxImageEdge: getEnvInt("STORAGE_MAX_IMAGE_EDGE", 1920),
WebPQuality: float32(getEnvInt("STORAGE_WEBP_QUALITY", 80)),
@@ -3,7 +3,7 @@ package handler
import "testing"
func TestValidateMessageContent(t *testing.T) {
SetImagePublicBase("http://localhost:9000/kefu")
SetImagePublicBase("http://localhost:9100/kefu")
if _, err := validateMessageContent("text", "hello"); err != nil {
t.Fatalf("文本消息应通过: %v", err)
@@ -12,7 +12,7 @@ func TestValidateMessageContent(t *testing.T) {
t.Fatal("空文本应失败")
}
validURL := "http://localhost:9000/kefu/tenants/1/chat/a.webp"
validURL := "http://localhost:9100/kefu/tenants/1/chat/a.webp"
if content, err := validateMessageContent("image", validURL); err != nil || content != validURL {
t.Fatalf("合法图片 URL 校验失败: content=%q err=%v", content, err)
}
@@ -36,9 +36,9 @@ func setupRouter(t *testing.T) *gin.Engine {
model.DB = db
middleware.InitJWT("test-secret")
router := gin.New()
mem := storage.NewMemory("http://localhost:9000/kefu")
mem := storage.NewMemory("http://localhost:9100/kefu")
handler.SetupRoutes(router, mem, config.StorageConfig{
PublicBase: "http://localhost:9000/kefu",
PublicBase: "http://localhost:9100/kefu",
MaxUploadMB: 10,
MaxImageEdge: 1920,
WebPQuality: 80,
+1 -1
View File
@@ -84,7 +84,7 @@ func (s *S3Storage) Delete(ctx context.Context, key string) error {
func (s *S3Storage) PublicBase() string { return s.base }
func (s *S3Storage) objectURL(key string) string {
// PublicBase 形如 http://localhost:9000/kefu
// PublicBase 形如 http://localhost:9100/kefu(宿主机映射端口)
return s.base + "/" + strings.TrimPrefix(key, "/")
}