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
|
|
@ -9,7 +9,7 @@ import (
|
|||
type Row struct {
|
||||
ID int64
|
||||
ItemID int64
|
||||
MediaType string // 'original', 'thumbnail'
|
||||
MediaType string // 'original' (user uploads), 'image' (fetched from URLs)
|
||||
ContentType string // MIME type
|
||||
Data []byte
|
||||
Width *int
|
||||
|
|
@ -68,13 +68,13 @@ func QFindByID(ctx context.Context, db *sql.DB, id int64) (*Row, error) {
|
|||
return &row, nil
|
||||
}
|
||||
|
||||
// QFindByItemID finds all media for an item.
|
||||
// QFindByItemID finds all media for an item, ordered by ID.
|
||||
func QFindByItemID(ctx context.Context, db *sql.DB, itemID int64) ([]Row, error) {
|
||||
query := `
|
||||
SELECT id, item_id, media_type, content_type, data, width, height, source_url, created_at
|
||||
FROM media
|
||||
WHERE item_id = $1
|
||||
ORDER BY media_type ASC
|
||||
ORDER BY id ASC
|
||||
`
|
||||
|
||||
rows, err := db.QueryContext(ctx, query, itemID)
|
||||
|
|
@ -97,12 +97,13 @@ func QFindByItemID(ctx context.Context, db *sql.DB, itemID int64) ([]Row, error)
|
|||
return media, rows.Err()
|
||||
}
|
||||
|
||||
// QFindThumbnailByItemID finds the thumbnail for an item.
|
||||
// QFindThumbnailByItemID finds the first image for an item (used as thumbnail).
|
||||
func QFindThumbnailByItemID(ctx context.Context, db *sql.DB, itemID int64) (*Row, error) {
|
||||
query := `
|
||||
SELECT id, item_id, media_type, content_type, data, width, height, source_url, created_at
|
||||
FROM media
|
||||
WHERE item_id = $1 AND media_type = 'thumbnail'
|
||||
WHERE item_id = $1 AND media_type = 'image'
|
||||
ORDER BY id ASC
|
||||
LIMIT 1
|
||||
`
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue