gennyble / textual

Text Rendering as a Service
Other
9 stars 1 forks source link

Pick html or raw image based on user agent #1

Closed gennyble closed 3 years ago

gennyble commented 3 years ago

Send an html page with just the image and and the text put in the alt to everyone except... when we see that Discord is trying to embed, which we know it is because it includes itself in the user agent (discord/version), we send the raw image. I wish we were allowed to add alt.

Saying that, I wonder if we could get OpenGraph tags to give it alt. Maybe we can just use the kind of embed that GitHub uses for issues? Do we have access to that, or is it a GitHub elusive kind of thing like how YouTube has their web player? An embed might be ideal, we wouldn't have to detect user agent then and Discord would have alt.

gennyble commented 3 years ago

I was mislead (by myself!!)

Discord will make two requests to your server. This information comes from this issue in the discord-api-docs repo:

The first request, from Discordbot, is a crawl form Discord. I believe it's to see what's there, if it's an image, an html page, if it has meta tags for embedding.

Mozilla/5.0 (compatible; Discordbot/2.0; +https://discordapp.com)

The second request, the one that looks like a normal user request, is for proxying the image we generate. This lines up with experimental testing; if we responded to the Discorbbot agent with an image, but returned a 500 to the proxy request, we get an image that tries to embed, but never does so. It'll appear as if it's loading for a good solid while (probably because we don't disconnect our side, do we?) until it eventually shows the cute nothing-was-loaded poop error page.

Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Firefox/38.0

gennyble commented 3 years ago

Not sure why I was so caught up on this, we can just serve a small HTML page that has meta and a single <img>