To clone locally: $ git clone https://betagit.vosjedev.net/git/discord_image_bridge.git
9db406e753da utils.py:download_uncached: return right amount of arguments when file exists[checkout]
| Name | Size | Mode |
|---|---|---|
| .gitignore | 34B | 100644 |
| README.md | 2.4KiB | 100644 |
| env.sh | 97B | 100644 |
| poetry.lock | 34.85KiB | 100644 |
| pyproject.toml | 741B | 100644 |
| src/ | - | 040000 |
| tests/ | - | 040000 |
Image Bridge¶
Why¶
In a recent (at the time of writing) discussion in the Pine64 community, I noticed someone noting discord urls when bridged to IRC and Telegram aren't valid for very long (the bridge forwarded discord's attachment URL plainly, and discord attachment URLs expire after some point - needed against abuse but not usefull for bridging). This point was brought to the table because someone else noted about the URLs being too long (also fair, who wants a URL taking up 2-3 lines for every attachment ever sent).
Given I've recently been working with cherrypy and the discord API a lot, and has files around for connecting to the discord gateway from a cherrypy plugin, I thought I'd write this 'quick' URL shortener and discord attachment 'bridge' (it's more like a proxy to discord's api I guess).
Todo¶
- [ ] also bridge telegram attachments
How¶
This program works by listening on a chat application gateway (currently only discord), and downloading every attachment that comes by. It also stores a reference on how to redownload that image. Your bridge can then send a GET request to an endpoint of this webserver, providing a unique thing identifying the attachment. This webserver then sends a URL back for the bridge to send instead of the original attachment URL.
This new URL will stay valid as long as this bridge knows how to download the image.
Usage¶
Installing should be done using pip install ..
For using this, one sets a few env variables and runs the thing (discord_image_bridge).
List of env vars:
Note if you want downloaded attachments to be deleted after some time, you should set up a cron job that sends a GET request to /run_cron. This API endpoint requires one query parameter: one should set token to the value of your CRON_TOKEN env variable.
Example: