Skip to content

Commit

Permalink
fix(kemono): Fix file field being ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Jun 27, 2024
1 parent d14b3a5 commit c954004
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
20 changes: 13 additions & 7 deletions internal/kemono/creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,20 @@ func (c *Creator) FetchPostPage(ctx context.Context, page uint64, query string)

for _, post := range posts {
post.Creator = c
seen := make([]string, 0, len(post.Attachments))
post.Attachments = slices.DeleteFunc(post.Attachments, func(attachment *Attachment) bool {
if slices.Contains(seen, attachment.Path) {
return true
if len(post.Attachments) == 0 {
if post.File != nil && post.File.Path != "" {
post.Attachments = append(post.Attachments, post.File)
}
seen = append(seen, attachment.Path)
return false
})
} else {
seen := make([]string, 0, len(post.Attachments))
post.Attachments = slices.DeleteFunc(post.Attachments, func(attachment *Attachment) bool {
if slices.Contains(seen, attachment.Path) {
return true
}
seen = append(seen, attachment.Path)
return false
})
}
for _, attachment := range post.Attachments {
attachment.post = post
}
Expand Down
1 change: 1 addition & 0 deletions internal/kemono/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Post struct {
Published string `json:"published"`
Edited string `json:"edited"`
Tags Tags `json:"tags"`
File *Attachment `json:"file"`
Attachments []*Attachment `json:"attachments"`
}

Expand Down

0 comments on commit c954004

Please sign in to comment.