Add Twitter video support and use sql.Null[T] for nullable columns
- Store Twitter video URLs in embed_video_url column instead of downloading - Play videos directly from Twitter's CDN in <video> element - Fix Twitter API parsing (content_type/url fields) - Strip t.co URLs from tweet text descriptions - Use sql.Null[T] generic type for nullable DB columns - Add Nullable[T] and Ptr[T] helper functions - Add play indicator overlay for video items in grid - Add migration for embed_video_url column
This commit is contained in:
parent
cdcc5b5293
commit
2887d9c430
8 changed files with 226 additions and 120 deletions
|
|
@ -3,6 +3,7 @@ package handlers
|
|||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.soup.land/soup/sxgo/ssr"
|
||||
|
|
@ -29,6 +30,7 @@ type homeItem struct {
|
|||
Tags []string
|
||||
ThumbnailID *int64
|
||||
MediaID *int64
|
||||
HasVideo bool
|
||||
}
|
||||
|
||||
func (h homeContent) Render(sw *ssr.Writer) error {
|
||||
|
|
@ -57,8 +59,10 @@ func (h homeContent) Render(sw *ssr.Writer) error {
|
|||
</div>
|
||||
{{else if .ThumbnailID}}
|
||||
<img src="/media/{{.ThumbnailID}}" alt="{{if .Title}}{{.Title}}{{else}}Image{{end}}" loading="lazy">
|
||||
{{if or .HasVideo (eq .ItemType "video")}}<div class="play-indicator">▶</div>{{end}}
|
||||
{{else if .MediaID}}
|
||||
<img src="/media/{{.MediaID}}" alt="{{if .Title}}{{.Title}}{{else}}Image{{end}}" loading="lazy">
|
||||
{{if or .HasVideo (eq .ItemType "video")}}<div class="play-indicator">▶</div>{{end}}
|
||||
{{else if eq .ItemType "embed"}}
|
||||
<div class="embed-placeholder">
|
||||
<span>▶</span>
|
||||
|
|
@ -160,11 +164,11 @@ func HandleHome(rc *RequestContext, w http.ResponseWriter, r *http.Request) erro
|
|||
for _, it := range items {
|
||||
hi := homeItem{
|
||||
ID: it.PubID,
|
||||
Title: it.Title,
|
||||
Description: it.Description,
|
||||
LinkURL: it.LinkURL,
|
||||
Title: item.Ptr(it.Title),
|
||||
Description: item.Ptr(it.Description),
|
||||
LinkURL: item.Ptr(it.LinkURL),
|
||||
ItemType: it.ItemType,
|
||||
EmbedHTML: it.EmbedHTML,
|
||||
EmbedHTML: item.Ptr(it.EmbedHTML),
|
||||
}
|
||||
|
||||
// Get tags
|
||||
|
|
@ -187,9 +191,17 @@ func HandleHome(rc *RequestContext, w http.ResponseWriter, r *http.Request) erro
|
|||
hi.ThumbnailID = &m.ID
|
||||
} else if m.MediaType == "original" {
|
||||
hi.MediaID = &m.ID
|
||||
if strings.HasPrefix(m.ContentType, "video/") {
|
||||
hi.HasVideo = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Also check for embed video URL
|
||||
if it.EmbedVideoURL.Valid && it.EmbedVideoURL.V != "" {
|
||||
hi.HasVideo = true
|
||||
}
|
||||
|
||||
homeItems = append(homeItems, hi)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue