🐛 Fix attachments in body issue

This commit is contained in:
2025-03-29 23:37:20 +08:00
parent fbe8e9b270
commit 3c2a14800e
2 changed files with 37 additions and 12 deletions

View File

@ -121,7 +121,15 @@ func ListPostV2(tx *gorm.DB, take int, offset int, order any, user *uint) ([]mod
log.Info().Int("attachments", len(attachments)).Int("users", len(users)).Msg("Batch loaded metadata for listing post...")
for idx, item := range posts {
var this []fmodels.Attachment
if val, ok := item.Body["attachments"].([]string); ok && len(val) > 0 {
var val []string
if raw, ok := item.Body["attachments"].([]any); ok && len(raw) > 0 {
val = lo.Map(raw, func(v any, _ int) string {
return v.(string) // Safe if you're sure all elements are strings
})
} else if raw, ok := item.Body["attachments"].([]string); ok {
val = raw
}
if len(val) > 0 {
this = lo.Filter(attachments, func(item fmodels.Attachment, _ int) bool {
return lo.Contains(val, item.Rid)
})