Browse Source

feat: handle tweets from suspended accounts

master
Marcus Noble 10 months ago
parent
commit
651f3683d2
  1. 17
      main.go
  2. 1
      suspendedTweet.svg

17
main.go

@ -19,7 +19,7 @@ import (
"github.com/joho/godotenv"
)
//go:embed index.html tweet.svg.tmpl
//go:embed index.html tweet.svg.tmpl suspendedTweet.svg
var content embed.FS
@ -77,6 +77,15 @@ func getTweet(w http.ResponseWriter, r *http.Request) {
}
tweet, err := api.GetTweet(i, nil)
if err != nil {
switch err := err.(type) {
case *anaconda.ApiError:
switch err.Decoded.Errors[0].Code {
case 63:
fmt.Printf("Generating suspended tweet image for %s\n", id)
suspendedTweet(w)
return
}
}
w.WriteHeader(404)
return
}
@ -192,3 +201,9 @@ func getTweet(w http.ResponseWriter, r *http.Request) {
return
}
}
func suspendedTweet(w http.ResponseWriter) {
w.Header().Set("Content-type", "image/svg+xml")
tweet, _ := content.ReadFile("suspendedTweet.svg")
w.Write(tweet)
}

1
suspendedTweet.svg

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="566" height="46" viewBox="0 0 566 46"><rect width="100%" height="100%" fill="rgba(0, 0, 0, 0)"/><path vector-effect="non-scaling-stroke" stroke="#f7f9f9" stroke-width="20" stroke-linejoin="round" fill="#f7f9f9" d="M-50-50V50H50V-50z" transform="matrix(5.46 0 0 .26 283 23.17)"/><g><text font-family="'Open Sans', sans-serif" font-size="15" style="white-space:pre" stroke-width="0" fill="#536471" transform="translate(221.5 21.91)"><tspan x="-202.5" y="5.34" style="white-space:pre" font-size="17">This Tweet is from a suspended account.</tspan></text></g></svg>

After

Width:  |  Height:  |  Size: 652 B

Loading…
Cancel
Save