topfans/backend/services/moderationService/config/moderation_config.go
2026-07-06 16:22:26 +08:00

83 lines
2.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package config
import (
"os"
"strings"
"time"
)
// ModerationConfig 举报反馈服务配置 (spec §11.1)
type ModerationConfig struct {
AutoHideThreshold int
CounterTTL time.Duration
UserMarkerTTL time.Duration
LockTTL time.Duration
MaxDescriptionLen int
MaxEvidenceCount int
MaxContactLen int
MaxReplyLen int
MaxEvidenceSize int64
AllowedMimeTypes []string
RateLimitUserPerDay int
RateLimitIPPerDay int
RateLimitDevPerDay int
RateLimitFbUserDay int
ClaimTimeout time.Duration
PIIAnonymizeAfter time.Duration
AutoArchiveAfter time.Duration
RedisKeyPrefix string
PathDCounterPolicy string
// OSSBaseURL OSS bucket 公开访问的 host不含末尾斜杠用于把证据 oss_key 拼成完整 URL 写入 oss_url 列。
// 由环境变量 OSS_BASE_URL 覆盖main.go
OSSBaseURL string
}
var Default = ModerationConfig{
AutoHideThreshold: 5,
CounterTTL: 7 * 24 * time.Hour,
UserMarkerTTL: 24 * time.Hour,
LockTTL: 5 * time.Second,
MaxDescriptionLen: 500,
MaxEvidenceCount: 5,
MaxContactLen: 320,
MaxReplyLen: 2000,
MaxEvidenceSize: 5 * 1024 * 1024,
AllowedMimeTypes: []string{"image/png", "image/jpeg"},
RateLimitUserPerDay: 30,
RateLimitIPPerDay: 200,
RateLimitDevPerDay: 200,
RateLimitFbUserDay: 5,
ClaimTimeout: 15 * time.Minute,
PIIAnonymizeAfter: 90 * 24 * time.Hour,
AutoArchiveAfter: 90 * 24 * time.Hour,
RedisKeyPrefix: "mod:report",
PathDCounterPolicy: "preserve",
OSSBaseURL: "https://top-fans-test.oss-cn-shanghai.aliyuncs.com",
}
// BuildOSSURL 把 oss_key 还原成可访问的完整 URL。
// 入参已是 http(s):// 开头则原样返回(兼容历史上传时就传完整 URL 的客户端);
// 否则按 OSSBaseURL/<key> 拼接。返回空串表示入参为空。
func BuildOSSURL(ossBaseURL, key string) string {
if key == "" {
return ""
}
if strings.HasPrefix(key, "http://") || strings.HasPrefix(key, "https://") {
return key
}
base := strings.TrimRight(ossBaseURL, "/")
if base == "" {
return key
}
return base + "/" + strings.TrimLeft(key, "/")
}
// LoadEnvOverrides 用环境变量覆盖 Default 里的可调字段。
func LoadEnvOverrides() ModerationConfig {
c := Default
if v := os.Getenv("OSS_BASE_URL"); v != "" {
c.OSSBaseURL = v
}
return c
}