feat: enforce tenant content moderation

This commit is contained in:
richjohnrambo
2026-09-16 22:21:25 +08:00
parent 0ae4af0c31
commit 0f8e3b82b7
26 changed files with 891 additions and 1 deletions
+34
View File
@@ -0,0 +1,34 @@
package moderation
import "strings"
var visibleTextKeys = map[string]bool{
"txt": true, "text": true, "title": true, "caption": true,
"description": true, "file_name": true, "filename": true, "name": true,
}
func ExtractText(content any) string {
parts := make([]string, 0, 4)
var walk func(any, int, bool)
walk = func(value any, depth int, includeString bool) {
if depth > 6 || value == nil {
return
}
switch typed := value.(type) {
case string:
if text := strings.TrimSpace(typed); includeString && text != "" {
parts = append(parts, text)
}
case map[string]any:
for key, item := range typed {
walk(item, depth+1, visibleTextKeys[strings.ToLower(strings.TrimSpace(key))])
}
case []any:
for _, item := range typed {
walk(item, depth+1, includeString)
}
}
}
walk(content, 0, true)
return strings.TrimSpace(strings.Join(parts, "\n"))
}