Merge pull request 'use direct media for discord' (#102) from use-direct-media into main

Reviewed-on: #102
This commit is contained in:
Charlotte 🦝 Delenk 2023-06-11 18:35:25 +00:00
commit b8e903b6c9
Signed by: gitea-bot
GPG key ID: C9974EDF9932B558
2 changed files with 26 additions and 0 deletions

View file

@ -182,6 +182,31 @@ in {
logFormat = pkgs.lib.mkForce "";
extraConfig = ''
import baseConfig
handle /_matrix/media/*/download/example.com/discord_* {
header Access-Control-Allow-Origin *
# Remove path prefix
uri path_regexp ^/_matrix/media/.+/download/example\.com/discord_ /
# The mxc patterns use | instead of /, so replace it first turning it into attachments/1234/5678/filename.png
uri replace "%7C" /
reverse_proxy {
# reverse_proxy automatically includes the uri, so no {uri} at the end
to https://cdn.discordapp.com
# Caddy doesn't set the Host header automatically when reverse proxying
# (because usually reverse proxies are local and don't care about Host headers)
header_up Host cdn.discordapp.com
}
}
# Do the same for thumbnails, but redirect to media.discordapp.net (which is Discord's thumbnailing server, and happens to use similar width/height params as Matrix)
# Alternatively, you can point this at cdn.discordapp.com too. Clients shouldn't mind even if they get a bigger image than they asked for.
handle /_matrix/media/*/thumbnail/example.com/discord_* {
header Access-Control-Allow-Origin *
uri path_regexp ^/_matrix/media/.+/thumbnail/example\.com/discord_ /
uri replace "%7C" /
reverse_proxy {
to https://media.discordapp.net
header_up Host media.discordapp.net
}
}
handle /_matrix/media/* {
uri * replace /unstable/fi.mau.msc2246/ /v1/
reverse_proxy http://localhost:8008 {

View file

@ -41,6 +41,7 @@
missed.channel = -1;
};
};
media_patterns.enabled = true;
encryption = {
allow = true;
appservice = true;