diff options
| author | Vosjedev <vosje@vosjedev.net> | 2026-01-25 17:13:04 +0100 |
|---|---|---|
| committer | Vosjedev <vosje@vosjedev.net> | 2026-01-25 17:13:04 +0100 |
| commit | 82559c70b19bfa1c8c69b99340984419828cfbd1 (patch) | |
| tree | 585756dff73edb633501172eb58011fcdc5c7ea9 | |
| parent | 78cf00a53d72f8e5d41e29392b8bd5dc9825f05a (diff) | |
| download | discord_image_bridge-82559c70b19bfa1c8c69b99340984419828cfbd1.tar.gz discord_image_bridge-82559c70b19bfa1c8c69b99340984419828cfbd1.tar.bz2 discord_image_bridge-82559c70b19bfa1c8c69b99340984419828cfbd1.tar.xz | |
Write a readme (fixes #2)
Signed-off-by: Vosjedev <vosje@vosjedev.net>
| -rw-r--r-- | README.md | 41 |
1 files changed, 41 insertions, 0 deletions
@@ -0,0 +1,41 @@ + +# 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](https://cherrypy.dev/) 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: + +```sh +DISCORD_TOKEN=secrettoken # this is the token for your discord bot + +BRIDGE_CACHE_DIR=~/.local/share/discord_image_bridge/ # where this should store files. +BRIDGE_CACHE_TIME=604800 # how much seconds to store an image for. defaults to 7 days. + +CRON_TOKEN=generate_a_random_sequence # the 'password' for the cron job +``` + +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: +```sh +CRON_TOKEN=d2VsbCBkaXNjb3ZlcmVkISB0aGlzIGlzIGluZGVlZCBiYXNlNjQhCg== + +curl -X GET 'https://localhost:8080/run_cron?token=d2VsbCBkaXNjb3ZlcmVkISB0aGlzIGlzIGluZGVlZCBiYXNlNjQhCg==' +# ^ replace with your domain ^ this is the value of CRON_TOKEN +``` + |
