Go to file
2024-09-23 16:25:32 -04:00
blacklist.txt Adding blacklist version 2024-06-15 20:23:24 -04:00
custommedia-blacklist.py Adding support for redirecting authenticated media paths 2024-09-23 16:25:32 -04:00
custommedia-static.py Adding support for redirecting authenticated media paths 2024-09-23 16:20:07 -04:00
custommedia-whitelist.py Adding support for redirecting authenticated media paths 2024-09-23 16:25:32 -04:00
custommedia.py Adding support for redirecting authenticated media paths 2024-09-23 16:25:32 -04:00
LICENSE Initial fork 2024-03-27 13:14:38 -04:00
mapping.json Initial fork 2024-03-27 13:14:38 -04:00
README.md Adding blacklist version 2024-06-15 20:23:24 -04:00
whitelist.txt Initial fork 2024-03-27 13:14:38 -04:00

CustomMedia

A fork of Plan9's CustomMedia project that adds whitelist and blacklist versions for choosing specific homeservers to pull media from directly. Conserve your matrix homeserver's precious storage space and bandwidth with this one simple webserver.

Requirements

  • Python 3
  • gunicorn - pip3 install gunicorn

Nginx configuration

Add this inside of the block that matches for requests to /_matrix, replacing server\.org with your own homeserver

location ~ ^/_matrix/media/(?<folder>[^/]+)/((download|thumbnail)/(?!(server\.org)/))(?<file>.*)$ {
proxy_pass http://localhost:9999;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_read_timeout 3600s;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
}

systemd Service

Clone this repository into /opt, check that custommedia.py has permission to execute, then use this systemd service (replacing custommedia.py with one of the other ones if desired):

[Unit]
Description=Custom media
After=network.target
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=always
RestartSec=5
User=root
WorkingDirectory=/opt/CustomMedia
ExecStart=/opt/CustomMedia/custommedia.py

[Install]
WantedBy=multi-user.target

Mappings

CustomMedia uses a mapping.json file to cache which domain a homeserver's media is on (unless using the -morg.py version). This file will automatically be created in the working directory if one does not exist, but one has been provided here with some common homeservers.