WIP: Add Twitter link previews for Discord with Nitter scraping and metadata injection

This commit is contained in:
Joakim Hellsén 2026-08-09 20:05:06 +02:00
commit 8406db5283
Signed by: Joakim Hellsén
SSH key fingerprint: SHA256:/9h/CsExpFp+PRhsfA0xznFx2CGfTT5R/kpuFfUgEQk
6 changed files with 440 additions and 19 deletions

View file

@ -1,29 +1,24 @@
import uvicorn
from litestar import Litestar
from litestar import get
from litestar.response import Response
from e.twitter import twitter
@get("/")
async def twitter() -> dict[str, str]: # ruff: ignore[unused-async]
"""Handle Twitter requests.
https://twitter.com/DiscussingFilm/status/2086143411984208230
https://e.lovinator.space/DiscussingFilm/status/2086143411984208230
If IP is from Discord:
Download the image/video.
Return custom HTML with metadata tags with the image/video.
Otherwise:
Redirect to the original URL.
Returns:
Redirect to the original URL, or custom HTML with metadata tags.
"""
return {"message": "Hello, World!"}
@get("/favicon.ico")
async def favicon() -> Response: # ruff: ignore[unused-async]
"""Return empty response."""
return Response(
content=b"",
media_type="image/x-icon",
status_code=204,
)
app = Litestar(route_handlers=[twitter])
app = Litestar(route_handlers=[twitter, favicon], debug=True)
if __name__ == "__main__":
uvicorn.run(app)
import os
uvicorn.run("e.main:app", port=int(os.getenv("PORT", str(8000))), reload=True)