Improve Twitter/X link handling and text formatting

- Use FxTwitter API for full note tweet text (with syndication API fallback)
- Save Twitter posts based on media content:
  - Videos → embed type (proxied video)
  - Images → image type (gallery)
  - Text-only → quote type
- Add granular preview badges: 'X VIDEO', 'X GALLERY', 'X POST'
- Preserve formatting/spacing with white-space: pre-wrap for quotes and descriptions
- Rename VideoInfo to EmbedInfo for better semantic clarity
This commit is contained in:
soup 2026-01-18 00:03:30 -05:00
parent 8a046728ef
commit 4a2cb341fa
Signed by: soup
SSH key fingerprint: SHA256:GYxje8eQkJ6HZKzVWDdyOUF1TyDiprruGhE0Ym8qYDY
7 changed files with 249 additions and 137 deletions

View file

@ -12,18 +12,17 @@ import (
)
type itemResponse struct {
ID string `json:"id"`
Title *string `json:"title,omitempty"`
Description *string `json:"description,omitempty"`
LinkURL *string `json:"linkUrl,omitempty"`
ItemType string `json:"itemType"`
EmbedHTML *string `json:"embedHtml,omitempty"`
Tags []string `json:"tags"`
CreatedAt string `json:"createdAt"`
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)
ID string `json:"id"`
Title *string `json:"title,omitempty"`
Description *string `json:"description,omitempty"`
LinkURL *string `json:"linkUrl,omitempty"`
ItemType string `json:"itemType"`
EmbedHTML *string `json:"embedHtml,omitempty"`
Tags []string `json:"tags"`
CreatedAt string `json:"createdAt"`
MediaID *int64 `json:"mediaId,omitempty"`
ImageIDs []int64 `json:"imageIds,omitempty"` // Fetched images (from URLs/embeds)
ImageURLs []string `json:"imageUrls,omitempty"` // Source URLs for fetched images
}
type createItemRequest struct {
@ -252,22 +251,17 @@ 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 == "image" {
if firstImage {
resp.ThumbnailID = &m.ID
resp.ThumbnailSourceURL = m.SourceURL
firstImage = false
} else {
resp.GalleryIDs = append(resp.GalleryIDs, m.ID)
resp.ImageIDs = append(resp.ImageIDs, m.ID)
if m.SourceURL != nil {
resp.ImageURLs = append(resp.ImageURLs, *m.SourceURL)
}
}
}