CustomMedia/README.md

49 lines
2.1 KiB
Markdown
Raw Permalink Normal View History

2024-03-27 13:14:38 -04:00
# CustomMedia
2024-06-15 20:23:24 -04:00
A fork of [Plan9's CustomMedia project](https://gitea.plan9.rocks/cat/CustomMedia) 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.
2024-03-27 13:14:38 -04:00
2024-09-23 16:34:44 -04:00
## "Will this work with the authenticated media update?"
CustomMedia will only work when pulling media from homeservers that have not disabled their unauthenticated media endpoints. Otherwise, you will get errors stating the media was not found. The best way to avoid this is to use custommedia-static.py, and point it to a server that has not yet made this change.
2024-03-27 13:14:38 -04:00
# 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
```
2024-09-23 18:53:30 -04:00
location ~ ^/_matrix(/media/(?<folder>[^/]+)|/client/v\d/media)/((download|thumbnail)/(?!(server\.org)/))(?<file>.*)$ {
2024-03-27 13:14:38 -04:00
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
2024-09-23 18:47:18 -04:00
CustomMedia uses a mapping.json file to cache which domain a homeserver's media is on (unless using the -static.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.