this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: Twitter card rendering when a 404 occurs

+23 -3
+20 -2
internal/handler/preview.go
··· 75 75 json.NewEncoder(w).Encode(meta) 76 76 return 77 77 } 78 + // If OEmbed returned ANY error (404, 403, etc.), we trust it. Do not fall back to scrape. 79 + if strings.Contains(err.Error(), "oembed status") { 80 + var code int 81 + if n, _ := fmt.Sscanf(err.Error(), "oembed status %d", &code); n != 1 { 82 + code = 404 83 + } 84 + json.NewEncoder(w).Encode(map[string]interface{}{ 85 + "error": "Tweet Unavailable", 86 + "status": code, 87 + }) 88 + return 89 + } 78 90 } else if strings.Contains(urlParam, "youtube.com") || strings.Contains(urlParam, "youtu.be") { 79 91 meta, err := h.GetYouTubePreview(urlParam) 80 92 if err == nil { ··· 82 94 return 83 95 } 84 96 // If we detected a soft 404, stop here and return 404 so UI can render "missing" badge 85 - if err != nil && err.Error() == "status 404" { 97 + if err.Error() == "status 404" { 86 98 json.NewEncoder(w).Encode(map[string]interface{}{ 87 99 "error": "Video Unavailable", 88 100 "status": 404, ··· 197 209 json.NewEncoder(w).Encode(map[string]interface{}{ 198 210 "error": "HTTP Error", 199 211 // Extract status code if possible, or default to 400 200 - "status": 400, 212 + "status": func() int { 213 + var code int 214 + if n, _ := fmt.Sscanf(err.Error(), "status %d", &code); n == 1 { 215 + return code 216 + } 217 + return 400 218 + }(), 201 219 }) 202 220 } else { 203 221 json.NewEncoder(w).Encode(map[string]string{"error": "Failed to fetch metadata"})
+3 -1
internal/service/content.go
··· 82 82 matches := re.FindStringSubmatch(item.URL) 83 83 if len(matches) > 1 { 84 84 // standard embed code 85 - embed := fmt.Sprintf(`<blockquote class="twitter-tweet"><a href="%s"></a></blockquote><script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>`, item.URL) 85 + // Force twitter.com domain for embed compatibility as widgets.js might not support x.com fully yet 86 + embedURL := strings.Replace(item.URL, "x.com", "twitter.com", 1) 87 + embed := fmt.Sprintf(`<blockquote class="twitter-tweet"><a href="%s">%s</a></blockquote><script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>`, embedURL, item.Title) 86 88 d.Content = template.HTML(embed) 87 89 isTwitter = true 88 90 }