**Major Features Added:** - **Inline Reply System**: Replace compose screen with inline reply boxes - **Thread Navigation**: Parent/child navigation with jump functionality - **Chain Flow UI**: Reply counts, expand/collapse animations, visual hierarchy - **Enhanced Animations**: Smooth transitions, hover effects, micro-interactions **Frontend Changes:** - **ThreadedCommentWidget**: Complete rewrite with animations and navigation - **ThreadNode Model**: Added parent references and descendant counting - **ThreadedConversationScreen**: Integrated navigation handlers - **PostDetailScreen**: Replaced with threaded conversation view - **ComposeScreen**: Added reply indicators and context - **PostActions**: Fixed visibility checks for chain buttons **Backend Changes:** - **API Route**: Added /posts/:id/thread endpoint - **Post Repository**: Include allow_chain and visibility fields in feed - **Thread Handler**: Support for fetching post chains **UI/UX Improvements:** - **Reply Context**: Clear indication when replying to specific posts - **Character Counting**: 500 character limit with live counter - **Visual Hierarchy**: Depth-based indentation and styling - **Smooth Animations**: SizeTransition, FadeTransition, hover states - **Chain Navigation**: Parent/child buttons with visual feedback **Technical Enhancements:** - **Animation Controllers**: Proper lifecycle management - **State Management**: Clean separation of concerns - **Navigation Callbacks**: Reusable navigation system - **Error Handling**: Graceful fallbacks and user feedback This creates a Reddit-style threaded conversation experience with smooth animations, inline replies, and intuitive navigation between posts in a chain.
88 lines
2 KiB
Go
88 lines
2 KiB
Go
package services
|
|
|
|
import (
|
|
"crypto/hmac"
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"fmt"
|
|
"net/url"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
type AssetService struct {
|
|
r2Secret string
|
|
r2Base string
|
|
imgDomain string
|
|
vidDomain string
|
|
}
|
|
|
|
func NewAssetService(secret, base, imgDomain, vidDomain string) *AssetService {
|
|
// Ensure domains have http/https prefix for url.Parse
|
|
if imgDomain != "" && !strings.HasPrefix(imgDomain, "http") {
|
|
imgDomain = "https://" + imgDomain
|
|
}
|
|
if vidDomain != "" && !strings.HasPrefix(vidDomain, "http") {
|
|
vidDomain = "https://" + vidDomain
|
|
}
|
|
|
|
return &AssetService{
|
|
r2Secret: secret,
|
|
r2Base: base,
|
|
imgDomain: imgDomain,
|
|
vidDomain: vidDomain,
|
|
}
|
|
}
|
|
|
|
// SignURL generates an HMAC-signed URL for Cloudflare R2 assets
|
|
func (s *AssetService) SignURL(rawPath string) string {
|
|
return s.signWithBase(rawPath, s.r2Base)
|
|
}
|
|
|
|
// SignImageURL generates an HMAC-signed URL using the image specialized domain
|
|
func (s *AssetService) SignImageURL(rawPath string) string {
|
|
if s.imgDomain == "" {
|
|
return s.SignURL(rawPath)
|
|
}
|
|
return s.signWithBase(rawPath, s.imgDomain)
|
|
}
|
|
|
|
// SignVideoURL generates an HMAC-signed URL using the video specialized domain
|
|
func (s *AssetService) SignVideoURL(rawPath string) string {
|
|
if s.vidDomain == "" {
|
|
return s.SignURL(rawPath)
|
|
}
|
|
return s.signWithBase(rawPath, s.vidDomain)
|
|
}
|
|
|
|
func (s *AssetService) signWithBase(rawPath, base string) string {
|
|
if rawPath == "" || strings.HasPrefix(rawPath, "http") {
|
|
return rawPath
|
|
}
|
|
|
|
// Remove leading slash if present
|
|
path := strings.TrimPrefix(rawPath, "/")
|
|
|
|
if s.r2Secret == "" {
|
|
return fmt.Sprintf("%s/%s", base, path)
|
|
}
|
|
|
|
expiry := time.Now().Add(24 * time.Hour).Unix()
|
|
mac := hmac.New(sha256.New, []byte(s.r2Secret))
|
|
data := fmt.Sprintf("%s:%d", path, expiry)
|
|
mac.Write([]byte(data))
|
|
signature := hex.EncodeToString(mac.Sum(nil))
|
|
|
|
u, err := url.Parse(fmt.Sprintf("%s/%s", base, path))
|
|
if err != nil {
|
|
return rawPath
|
|
}
|
|
|
|
q := u.Query()
|
|
q.Set("exp", fmt.Sprintf("%d", expiry))
|
|
q.Set("sig", signature)
|
|
u.RawQuery = q.Encode()
|
|
|
|
return u.String()
|
|
}
|