Matrix Content Scanner
A web service for scanning media hosted on a Matrix media repository.
Installation
This project requires libmagic to be installed on the system. On Debian/Ubuntu:
sudo apt install libmagic1
Then, preferably in a virtual environment, install the Matrix Content Scanner:
pip install matrix-content-scanner
Usage
Copy and edit the sample configuration file. Each key is documented in this file.
Then run the content scanner (from within your virtual environment if one was created):
python -m matrix_content_scanner.mcs -c CONFIG_FILE
Where CONFIG_FILE is the path to your configuration file.
Docker
This project provides a Docker image to run it, published as
vectorim/matrix-content-scanner.
To use it, copy the sample configuration file into a dedicated
directory, edit it accordingly with your requirements, and then mount this directory as
/data in the image. Do not forget to also publish the port that the content scanner's
Web server is configured to listen on.
For example, assuming the port for the Web server is 8080:
docker run -p 8080:8080 -v /path/to/your/config/directory:/data vectorim/matrix-content-scanner
API
See the API documentation for information about how clients are expected to interact with the Matrix Content Scanner.
Migrating from the legacy Matrix Content Scanner
Because it uses the same APIs and Olm pickle format as the legacy Matrix Content Scanner, this project can be used as a drop-in replacement. The only change (apart from the deployment instructions) is the configuration format:
- the
serversection is renamedweb scan.tempDirectoryis renamedscan.temp_directoryscan.baseUrlis renameddownload.base_homeserver_url(and becomes optional)scan.doNotCacheExitCodesis renamedresult_cache.exit_codes_to_ignorescan.directDownloadis removed. Direct download always happens whendownload.base_homeserver_urlis absent from the configuration file, and setting a value for it will always cause files to be downloaded from the server configured.proxyis renameddownload.proxymiddleware.encryptedBody.pickleKeyis renamedcrypto.pickle_keymiddleware.encryptedBody.picklePathis renamedcrypto.pickle_pathacceptedMimeTypeis renamedscan.allowed_mimetypesrequestHeaderis renameddownload.additional_headersand turned into a dictionary.
Note that the format of the cryptographic pickle file and key are compatible between this project and the legacy Matrix Content Scanner. If no file exist at that path one will be created automatically.
Development
In a virtual environment with poetry (>=1.8.3) installed, run
poetry install
To run the unit tests, you can use:
tox -e py
To run the linters and mypy type checker, use ./scripts-dev/lint.sh.
Releasing
The exact steps for releasing will vary; but this is an approach taken by the Synapse developers (assuming a Unix-like shell):
-
Set a shell variable to the version you are releasing (this just makes subsequent steps easier):
version=X.Y.Z
-
Update
pyproject.tomlso that theversionis correct. -
Stage the changed files and commit.
git add -u git commit -m v$version -n
-
Push your changes.
git push -
When ready, create a signed tag for the release:
git tag -s v$version
Base the tag message on the changelog.
-
Push the tag.
git push origin tag v$version
-
Create a release, based on the tag you just pushed, on GitHub or GitLab.
-
Create a source distribution and upload it to PyPI:
python -m build twine upload dist/matrix_content_scanner-$version*
-
Double-check that the docker image build has succeeded, and that a new image tag for your release version has appeared on Docker Hub.
Metadata
Release files for matrix-content-scanner 1.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| matrix_content_scanner-1.4.1.tar.gz | 66.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| matrix_content_scanner-1.4.1-cp314-cp314-manylinux_2_40_x86_64.whl | CPython 3.14 | CPython 3.14 | Linux glibc 2.40+ x86-64 | Details |
Total release size: 576.7 kB
Release files / matrix_content_scanner-1.4.1.tar.gz
| Download URL | matrix_content_scanner-1.4.1.tar.gz |
|---|---|
| Size | 66.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
34966717ebcc74e24e85c487297f67213c4f8ac9165561851aacad28747ffcc6
|
|
BLAKE2b-256 checksum How to use checksums |
480e3b4dfaa23d2002cd9366ff8d25f3319b9c0863d158da3982736f07942562
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.2
|
Release files / matrix_content_scanner-1.4.1-cp314-cp314-manylinux_2_40_x86_64.whl
| Download URL | matrix_content_scanner-1.4.1-cp314-cp314-manylinux_2_40_x86_64.whl |
|---|---|
| Size | 510.7 kB |
| Tags | CPython 3.14 Linux glibc 2.40+ x86-64 |
|
SHA-256 checksum How to use checksums |
749e56adac9a99b693a83074e27e58db9490396ca2da379a36a787fe421a1d43
|
|
BLAKE2b-256 checksum How to use checksums |
18e0251b75cbbed80b148cf36d98293ce5d5b1c86b48c9cc00474c2714cd507a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.2
|