Add support for multiple images from Twitter links
- Fetch all images from Twitter syndication API (photos array) - Store images with unified 'image' media type (first = thumbnail by ID order) - Display multi-image tweets in grid layout on detail page - Add hover cycling through images on home grid (2s interval) - Show image count indicator on multi-image items - Extract shared downloadAndStoreImages() helper for create/refresh - Add migration to convert existing thumbnail/gallery types to image - Make images clickable to open in new tab on detail page
This commit is contained in:
parent
e917e67930
commit
007e167707
9 changed files with 625 additions and 403 deletions
|
|
@ -23,6 +23,7 @@ type itemResponse struct {
|
|||
MediaID *int64 `json:"mediaId,omitempty"`
|
||||
ThumbnailID *int64 `json:"thumbnailId,omitempty"`
|
||||
ThumbnailSourceURL *string `json:"thumbnailSourceUrl,omitempty"`
|
||||
GalleryIDs []int64 `json:"galleryIds,omitempty"` // Additional images (for multi-image tweets)
|
||||
}
|
||||
|
||||
type createItemRequest struct {
|
||||
|
|
@ -251,16 +252,23 @@ func buildItemResponse(ctx context.Context, rc *RequestContext, it item.Row) (it
|
|||
}
|
||||
|
||||
// Get media IDs
|
||||
// Media is ordered by ID, so first "image" is the thumbnail, rest are gallery
|
||||
mediaList, err := media.QFindByItemID(ctx, rc.DB, it.ID)
|
||||
if err != nil {
|
||||
return itemResponse{}, err
|
||||
}
|
||||
firstImage := true
|
||||
for _, m := range mediaList {
|
||||
if m.MediaType == "original" {
|
||||
resp.MediaID = &m.ID
|
||||
} else if m.MediaType == "thumbnail" {
|
||||
resp.ThumbnailID = &m.ID
|
||||
resp.ThumbnailSourceURL = m.SourceURL
|
||||
} else if m.MediaType == "image" {
|
||||
if firstImage {
|
||||
resp.ThumbnailID = &m.ID
|
||||
resp.ThumbnailSourceURL = m.SourceURL
|
||||
firstImage = false
|
||||
} else {
|
||||
resp.GalleryIDs = append(resp.GalleryIDs, m.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue