this repo has no description
1
fork

Configure Feed

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

fix: Do proper 404 handling for missing youtube videos

+28 -1
+8
internal/handler/preview.go
··· 80 80 json.NewEncoder(w).Encode(meta) 81 81 return 82 82 } 83 + // If we detected a soft 404, stop here and return 404 so UI can render "missing" badge 84 + if err != nil && err.Error() == "status 404" { 85 + json.NewEncoder(w).Encode(map[string]interface{}{ 86 + "error": "Video Unavailable", 87 + "status": 404, 88 + }) 89 + return 90 + } 83 91 } 84 92 85 93 // 1. Try OEmbed
+9 -1
internal/handler/preview_youtube.go
··· 2 2 3 3 import ( 4 4 "fmt" 5 + "strings" 5 6 ) 6 7 7 8 // GetYouTubePreview handles preview logic for YouTube. ··· 18 19 // Check for YouTube "soft 404" 19 20 // Extracted from original scrapeOpenGraph 20 21 title, hasTitle := meta["title"] 21 - if !hasTitle || title == " - YouTube" || title == "YouTube" { 22 + 23 + if !hasTitle { 24 + return nil, fmt.Errorf("status 404") 25 + } 26 + 27 + // Make check more permissible using Contains 28 + if strings.Contains(title, " - YouTube") || title == "YouTube" { 22 29 // Special handling for caller to know it's a 404 23 30 return nil, fmt.Errorf("status 404") 24 31 } 32 + 25 33 meta["type"] = "video" 26 34 27 35 return meta, nil
+11
tests/api_test.sh
··· 58 58 check_200 "/v0/" 59 59 check_200 "/v0/search.cgi?search=test" 60 60 61 + # 6. YouTube 404 Check 62 + echo -n "Checking YouTube value for missing video (Expect 200 OK + status: 404)... " 63 + resp=$(curl -s "$BASE_URL/ogpreview.cgi?url=https://www.youtube.com/watch?v=video_gone") 64 + # Check if response contains '"status": 404' (or 'status":404' depending on spacing) 65 + if [[ "$resp" == *'"status":404'* ]] || [[ "$resp" == *'"status": 404'* ]]; then 66 + echo "OK" 67 + else 68 + echo "FAIL (Got: $resp)" 69 + FAIL=1 70 + fi 71 + 61 72 if [ $FAIL -eq 0 ]; then 62 73 echo "All tests passed!" 63 74 exit 0