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"
|
||||
|
|
@ -18,16 +19,18 @@ type itemPageContent struct {
|
|||
}
|
||||
|
||||
type itemPageData struct {
|
||||
ID string
|
||||
Title *string
|
||||
Description *string
|
||||
LinkURL *string
|
||||
ItemType string
|
||||
EmbedHTML *string
|
||||
Tags []string
|
||||
CreatedAt string
|
||||
ThumbnailID *int64
|
||||
MediaID *int64
|
||||
ID string
|
||||
Title *string
|
||||
Description *string
|
||||
LinkURL *string
|
||||
ItemType string
|
||||
EmbedHTML *string
|
||||
EmbedVideoURL *string
|
||||
Tags []string
|
||||
CreatedAt string
|
||||
ThumbnailID *int64
|
||||
MediaID *int64
|
||||
MediaIsVideo bool
|
||||
}
|
||||
|
||||
func (c itemPageContent) Render(sw *ssr.Writer) error {
|
||||
|
|
@ -48,7 +51,13 @@ func (c itemPageContent) Render(sw *ssr.Writer) error {
|
|||
</video>
|
||||
</div>
|
||||
{{else if eq .Item.ItemType "embed"}}
|
||||
{{if .Item.ThumbnailID}}
|
||||
{{if .Item.EmbedVideoURL}}
|
||||
<div class="video-container">
|
||||
<video controls poster="{{if .Item.ThumbnailID}}/media/{{.Item.ThumbnailID}}{{end}}">
|
||||
<source src="{{.Item.EmbedVideoURL}}" type="video/mp4">
|
||||
</video>
|
||||
</div>
|
||||
{{else if .Item.ThumbnailID}}
|
||||
<div class="image-container">
|
||||
<img src="/media/{{.Item.ThumbnailID}}" alt="{{if .Item.Title}}{{.Item.Title}}{{else}}Embed{{end}}">
|
||||
</div>
|
||||
|
|
@ -162,6 +171,7 @@ func HandleItemPage(rc *RequestContext, w http.ResponseWriter, r *http.Request)
|
|||
|
||||
// Get media
|
||||
var thumbnailID, mediaID *int64
|
||||
var mediaIsVideo bool
|
||||
mediaList, err := media.QFindByItemID(ctx, rc.DB, it.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -171,28 +181,31 @@ func HandleItemPage(rc *RequestContext, w http.ResponseWriter, r *http.Request)
|
|||
thumbnailID = &m.ID
|
||||
} else if m.MediaType == "original" {
|
||||
mediaID = &m.ID
|
||||
mediaIsVideo = strings.HasPrefix(m.ContentType, "video/")
|
||||
}
|
||||
}
|
||||
|
||||
data := itemPageData{
|
||||
ID: it.PubID,
|
||||
Title: it.Title,
|
||||
Description: it.Description,
|
||||
LinkURL: it.LinkURL,
|
||||
ItemType: it.ItemType,
|
||||
EmbedHTML: it.EmbedHTML,
|
||||
Tags: tagNames,
|
||||
CreatedAt: it.CreatedAt.Format("Jan 2, 2006"),
|
||||
ThumbnailID: thumbnailID,
|
||||
MediaID: mediaID,
|
||||
ID: it.PubID,
|
||||
Title: item.Ptr(it.Title),
|
||||
Description: item.Ptr(it.Description),
|
||||
LinkURL: item.Ptr(it.LinkURL),
|
||||
ItemType: it.ItemType,
|
||||
EmbedHTML: item.Ptr(it.EmbedHTML),
|
||||
EmbedVideoURL: item.Ptr(it.EmbedVideoURL),
|
||||
Tags: tagNames,
|
||||
CreatedAt: it.CreatedAt.Format("Jan 2, 2006"),
|
||||
ThumbnailID: thumbnailID,
|
||||
MediaID: mediaID,
|
||||
MediaIsVideo: mediaIsVideo,
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
sw := ssr.NewWriter(w, rc.TmplCache)
|
||||
|
||||
var title string
|
||||
if it.Title != nil {
|
||||
title = *it.Title
|
||||
if it.Title.Valid {
|
||||
title = it.Title.V
|
||||
}
|
||||
|
||||
page := components.Page{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue