Compare commits
No commits in common. "3c2a14800e875494865c1f0f313419809cd02a2b" and "e588f2c87a857255f78cbe1c3b483d33ea22b5b6" have entirely different histories.
3c2a14800e
...
e588f2c87a
@ -12,7 +12,6 @@ import (
|
||||
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/nex"
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/cachekit"
|
||||
"github.com/goccy/go-json"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
||||
"git.solsynth.dev/hypernet/interactive/pkg/internal/gap"
|
||||
@ -679,21 +678,16 @@ func UpdatePostAttachmentMeta(item models.Post, old ...models.Post) error {
|
||||
sameAsOld = reflect.DeepEqual(old[0].Body, item.Body)
|
||||
}
|
||||
|
||||
var oldBody, newBody models.PostStoryBody
|
||||
if len(old) > 0 {
|
||||
raw, _ := json.Marshal(old[0].Body)
|
||||
json.Unmarshal(raw, &oldBody)
|
||||
}
|
||||
{
|
||||
raw, _ := json.Marshal(item.Body)
|
||||
json.Unmarshal(raw, &newBody)
|
||||
}
|
||||
var minusAttachments, plusAttachments []string
|
||||
if len(old) > 0 && !sameAsOld {
|
||||
minusAttachments = append(minusAttachments, oldBody.Attachments...)
|
||||
if val, ok := old[0].Body["attachments"].([]string); ok {
|
||||
minusAttachments = append(minusAttachments, val...)
|
||||
}
|
||||
}
|
||||
if len(old) == 0 || !sameAsOld {
|
||||
plusAttachments = append(plusAttachments, newBody.Attachments...)
|
||||
if val, ok := item.Body["attachments"].([]string); ok {
|
||||
plusAttachments = append(plusAttachments, val...)
|
||||
}
|
||||
}
|
||||
if dat, ok := item.Body["thumbnail"].(string); ok {
|
||||
plusAttachments = append(plusAttachments, dat)
|
||||
@ -757,18 +751,13 @@ func DeletePost(item models.Post) error {
|
||||
}
|
||||
|
||||
// Cleaning up related attachments
|
||||
var body models.PostStoryBody
|
||||
{
|
||||
raw, _ := json.Marshal(item.Body)
|
||||
json.Unmarshal(raw, &body)
|
||||
}
|
||||
if len(body.Attachments) > 0 {
|
||||
if val, ok := item.Body["attachments"].([]string); ok && len(val) > 0 {
|
||||
if item.Publisher.AccountID == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
err := filekit.CountAttachmentUsage(gap.Nx, &pproto.UpdateUsageRequest{
|
||||
Rid: lo.Uniq(body.Attachments),
|
||||
Rid: lo.Uniq(val),
|
||||
})
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("An error occurred when deleting post attachment...")
|
||||
@ -783,16 +772,10 @@ func DeletePostInBatch(items []models.Post) error {
|
||||
return err
|
||||
}
|
||||
|
||||
var bodies []models.PostStoryBody
|
||||
{
|
||||
raw, _ := json.Marshal(items)
|
||||
json.Unmarshal(raw, &bodies)
|
||||
}
|
||||
|
||||
var attachments []string
|
||||
for idx := range items {
|
||||
if len(bodies[idx].Attachments) > 0 {
|
||||
attachments = append(attachments, bodies[idx].Attachments...)
|
||||
for _, item := range items {
|
||||
if val, ok := item.Body["attachments"].([]string); ok && len(val) > 0 {
|
||||
attachments = append(attachments, val...)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,13 +92,8 @@ func ListPostV2(tx *gorm.DB, take int, offset int, order any, user *uint) ([]mod
|
||||
if info.Publisher.AccountID != nil {
|
||||
usersId = append(usersId, *info.Publisher.AccountID)
|
||||
}
|
||||
if raw, ok := info.Body["attachments"].([]any); ok && len(raw) > 0 {
|
||||
attachmentsRid := make([]string, 0, len(raw))
|
||||
for _, v := range raw {
|
||||
if str, ok := v.(string); ok {
|
||||
attachmentsRid = append(attachmentsRid, str)
|
||||
}
|
||||
}
|
||||
if val, ok := info.Body["attachments"].([]string); ok && len(val) > 0 {
|
||||
attachmentsRid = append(attachmentsRid, val...)
|
||||
}
|
||||
}
|
||||
log.Debug().Int("attachments", len(attachmentsRid)).Int("users", len(usersId)).Msg("Scanned metadata to load for listing post...")
|
||||
@ -121,15 +116,7 @@ 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
|
||||
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 {
|
||||
if val, ok := item.Body["attachments"].([]string); ok && len(val) > 0 {
|
||||
this = lo.Filter(attachments, func(item fmodels.Attachment, _ int) bool {
|
||||
return lo.Contains(val, item.Rid)
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user