diff --git a/config/services/matrix-media-repo.nix b/config/services/matrix-media-repo.nix index 4eeb365b..03c1069d 100644 --- a/config/services/matrix-media-repo.nix +++ b/config/services/matrix-media-repo.nix @@ -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 { diff --git a/config/services/mautrix-discord.nix b/config/services/mautrix-discord.nix index 1d5b4e37..eccd3ee5 100644 --- a/config/services/mautrix-discord.nix +++ b/config/services/mautrix-discord.nix @@ -41,6 +41,7 @@ missed.channel = -1; }; }; + media_patterns.enabled = true; encryption = { allow = true; appservice = true;