Skip to content

Commit

Permalink
Add gallery view similar to FxTwitter
Browse files Browse the repository at this point in the history
  • Loading branch information
Wikidepia committed Mar 19, 2024
1 parent e54bda3 commit 51ffb5e
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions handlers/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ func Embed() fiber.Handler {
return c.Send(viewsBuf.Bytes())
}

isGallery, err := strconv.ParseBool(c.Query("gallery", "false"))
if err != nil {
viewsData.Description = "Invalid gallery parameter"
views.Embed(viewsData, viewsBuf)
return c.Send(viewsBuf.Bytes())
}

// Stories use mediaID (int) instead of postID
if strings.Contains(c.Path(), "/stories/") {
mediaID, err := strconv.Atoi(postID)
Expand Down Expand Up @@ -102,9 +109,12 @@ func Embed() fiber.Handler {
sb.Grow(32) // 32 bytes should be enough for most cases

viewsData.Title = "@" + utils.B2S(item.Username)
viewsData.Description = utils.B2S(item.Caption)
if len(viewsData.Description) > 255 {
viewsData.Description = viewsData.Description[:250] + "..."
// Gallery do not have any caption
if !isGallery {
viewsData.Description = utils.B2S(item.Caption)
if len(viewsData.Description) > 255 {
viewsData.Description = viewsData.Description[:250] + "..."
}
}

typename := item.Medias[max(1, mediaNum)-1].TypeName
Expand Down

0 comments on commit 51ffb5e

Please sign in to comment.