Newer
Older
# Media repository administration
All the API calls here require your user ID to be listed in the configuration as an administrator. After that, your access token for your homeserver will grant you access to these APIs. The URLs should be hit against a configured homeserver. For example, if you have `t2bot.io` configured as a homeserver, then the admin API can be used at `https://t2bot.io/_matrix/media/r0/admin/...`.
## Remote media purge
URL: `POST /_matrix/media/unstable/admin/purge_remote?before_ts=1234567890&access_token=your_access_token` (`before_ts` is in milliseconds)
This will delete remote media from the file store that was downloaded before the timestamp specified. If the file is referenced by newer remote media or local files to any of the configured homeservers, it will not be deleted. Be aware that removing a homeserver from the config will cause it to be considered a remote server, and therefore the media may be deleted.
Any remote media that is deleted and requested by a user will be downloaded again.
## Quarantine media
URL: `POST /_matrix/media/unstable/admin/quarantine/<server>/<media id>?access_token=your_access_token`
The `<server>` and `<media id>` can be retrieved from an MXC URI (`mxc://<server>/<media id>`).
The quarantine media API allows administrators to quarantine media that may not be appropriate for their server. Using this API will prevent the media from being downloaded any further. It will *not* delete the file from your storage though: that is a task left for the administrator.
Remote media that has been quarantined will not be purged either. This is so that the media remains flagged as quarantined. It is safe to delete the file on your disk, but not delete the media from the database.
Quarantining media will also quarantine any media with the same file hash.
This API is unique in that it can allow administrators of configured homeservers to quarantine media on their homeserver only. This will not allow local administrators to quarantine remote media or media on other homeservers though, just on theirs.
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
## Datastore management
Datastores are used by the media repository to put files. Typically these match what is configured in the config file, such as s3 and directories.
#### Listing available datastores
URL: `GET /_matrix/media/unstable/admin/datastores?access_token=your_access_token`
The result will be something like:
```json
{
"00be9363007feb66de554a79e16b7b49": {
"type": "file",
"uri": "/mnt/media"
},
"2e17bad1bf76c9618e3cde30166dc674": {
"type": "s3",
"uri": "s3:\/\/example.org\/bucket-name"
}
}
```
In the above response, `00be9363007feb66de554a79e16b7b49` and `2e17bad1bf76c9618e3cde30166dc674` are datastore IDs.
#### Estimating size of a datastore
URL: `GET /_matrix/media/unstable/admin/datastores/<datastore id>/size_estimate?access_token=your_access_token`
Sample response:
```json
{
"thumbnails_affected": 672,
"thumbnail_hashes_affected": 598,
"thumbnail_bytes": 49087657,
"media_affected": 372,
"media_hashes_affected": 346,
"media_bytes": 340907359,
"total_hashes_affected": 779,
"total_bytes": 366601489
}
```
#### Transferring media between datastores
URL: `POST /_matrix/media/unstable/admin/datastores/<source datastore id>/transfer_to/<destination datastore id>?access_token=your_access_token`
The response is the estimated amount of data being transferred:
```json
{
"thumbnails_affected": 672,
"thumbnail_hashes_affected": 598,
"thumbnail_bytes": 49087657,
"media_affected": 372,
"media_hashes_affected": 346,
"media_bytes": 340907359,
"total_hashes_affected": 779,
"total_bytes": 366601489
}
```
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
## Data usage for servers/users
Individual servers and users can often hoard data in the media repository. These endpoints will tell you how much. These endpoints can only be called by repository admins - they are not available to admins of the homeservers.
**Caution**: These endpoints may return *lots* of data. Making very specific requests is recommended.
#### Per-server usage
URL: `GET /_matrix/media/unstable/admin/usage/<server name>?access_token=your_access_token`
The response is how much data the server is using:
```json
{
"raw_bytes": {
"total": 1594009,
"media": 1392009,
"thumbnails": 202000
},
"raw_counts": {
"total": 7,
"media": 4,
"thumbnails": 3
}
}
```
**Note**: The endpoint may return values which represent duplicated media across itself and other hosts.
#### Per-user usage (all known users)
URL: `GET /_matrix/media/unstable/admin/usage/<server name>/users?access_token=your_access_token`
The response is how much data the server is using:
```json
{
"@alice:example.org": {
"raw_bytes": {
"total": 1392009,
"media": 1392009
},
"raw_counts": {
"total": 4,
"media": 4
},
"uploaded": [
"mxc://example.org/abc123",
"mxc://example.org/abc124",
"mxc://example.org/abc125"
]
}
}
```
**Note**: The endpoint may return values which represent duplicated media across itself and other hosts.
**Note**: Thumbnails are not associated with users and therefore are not included by this endpoint.
#### Per-user usage (batch of users / single user)
Use the same endpoint as above, but specifying one or more `?user_id=@alice:example.org` query parameters. Note that encoding the values may be required (not shown here). Users that are unknown to the media repo will not be returned.
#### Per-upload usage (all uploads)
URL: `GET /_matrix/media/unstable/admin/usage/<server name>/uploads?access_token=your_access_token`
The response is how much data the server is using:
```json
{
"mxc://example.org/abc123": {
"size_bytes": 102400,
"uploaded_by": "@alice:example.org",
"datastore_id": "def456",
"datastore_location": "/var/media-repo/ab/cd/12345",
"sha256_hash": "ghi789",
"quarantined": false,
"upload_name": "info.txt",
"content_type": "text/plain",
"created_ts": 1561514528225
}
}
```
#### Per-upload usage (batch of uploads / single upload)
Use the same endpoint as above, but specifying one or more `?mxc=mxc://example.org/abc123` query parameters. Note that encoding the values may be required (not shown here).