2020-12-09 11:19:57 -05:00
|
|
|
# Contents
|
2021-03-09 10:15:52 -05:00
|
|
|
- [Querying media](#querying-media)
|
|
|
|
* [List all media in a room](#list-all-media-in-a-room)
|
|
|
|
* [List all media uploaded by a user](#list-all-media-uploaded-by-a-user)
|
2020-12-09 11:19:57 -05:00
|
|
|
- [Quarantine media](#quarantine-media)
|
|
|
|
* [Quarantining media by ID](#quarantining-media-by-id)
|
2021-06-02 13:50:35 -04:00
|
|
|
* [Remove media from quarantine by ID](#remove-media-from-quarantine-by-id)
|
2020-12-09 11:19:57 -05:00
|
|
|
* [Quarantining media in a room](#quarantining-media-in-a-room)
|
|
|
|
* [Quarantining all media of a user](#quarantining-all-media-of-a-user)
|
2021-01-15 11:18:09 -05:00
|
|
|
* [Protecting media from being quarantined](#protecting-media-from-being-quarantined)
|
2021-05-26 06:19:47 -04:00
|
|
|
* [Unprotecting media from being quarantined](#unprotecting-media-from-being-quarantined)
|
2020-12-09 11:19:57 -05:00
|
|
|
- [Delete local media](#delete-local-media)
|
|
|
|
* [Delete a specific local media](#delete-a-specific-local-media)
|
|
|
|
* [Delete local media by date or size](#delete-local-media-by-date-or-size)
|
2021-08-11 15:29:59 -04:00
|
|
|
* [Delete media uploaded by a user](#delete-media-uploaded-by-a-user)
|
2020-12-09 11:19:57 -05:00
|
|
|
- [Purge Remote Media API](#purge-remote-media-api)
|
|
|
|
|
2021-03-09 10:15:52 -05:00
|
|
|
# Querying media
|
|
|
|
|
|
|
|
These APIs allow extracting media information from the homeserver.
|
|
|
|
|
|
|
|
## List all media in a room
|
2018-01-31 10:15:59 -05:00
|
|
|
|
|
|
|
This API gets a list of known media in a room.
|
2020-11-24 09:04:51 -05:00
|
|
|
However, it only shows media from unencrypted events or rooms.
|
2018-01-31 10:15:59 -05:00
|
|
|
|
|
|
|
The API is:
|
|
|
|
```
|
2019-05-01 10:18:58 -04:00
|
|
|
GET /_synapse/admin/v1/room/<room_id>/media
|
2018-01-31 10:15:59 -05:00
|
|
|
```
|
2020-06-05 12:31:05 -04:00
|
|
|
To use it, you will need to authenticate by providing an `access_token` for a
|
2021-06-16 08:15:52 -04:00
|
|
|
server admin: see [Admin API](../usage/administration/admin_api).
|
2018-01-31 10:15:59 -05:00
|
|
|
|
2020-06-05 12:31:05 -04:00
|
|
|
The API returns a JSON body like the following:
|
2020-12-09 11:19:57 -05:00
|
|
|
```json
|
2018-01-31 10:15:59 -05:00
|
|
|
{
|
2020-12-09 11:19:57 -05:00
|
|
|
"local": [
|
|
|
|
"mxc://localhost/xwvutsrqponmlkjihgfedcba",
|
|
|
|
"mxc://localhost/abcdefghijklmnopqrstuvwx"
|
|
|
|
],
|
|
|
|
"remote": [
|
|
|
|
"mxc://matrix.org/xwvutsrqponmlkjihgfedcba",
|
|
|
|
"mxc://matrix.org/abcdefghijklmnopqrstuvwx"
|
|
|
|
]
|
2018-01-31 10:15:59 -05:00
|
|
|
}
|
|
|
|
```
|
2019-12-03 13:20:39 -05:00
|
|
|
|
2021-03-09 10:15:52 -05:00
|
|
|
## List all media uploaded by a user
|
|
|
|
|
|
|
|
Listing all media that has been uploaded by a local user can be achieved through
|
2021-08-11 15:29:59 -04:00
|
|
|
the use of the
|
|
|
|
[List media uploaded by a user](user_admin_api.md#list-media-uploaded-by-a-user)
|
2021-03-09 10:15:52 -05:00
|
|
|
Admin API.
|
|
|
|
|
2020-01-13 13:10:43 -05:00
|
|
|
# Quarantine media
|
2019-12-03 13:20:39 -05:00
|
|
|
|
2020-01-13 13:10:43 -05:00
|
|
|
Quarantining media means that it is marked as inaccessible by users. It applies
|
|
|
|
to any local media, and any locally-cached copies of remote media.
|
2019-12-03 13:20:39 -05:00
|
|
|
|
2020-01-13 13:10:43 -05:00
|
|
|
The media file itself (and any thumbnails) is not deleted from the server.
|
|
|
|
|
|
|
|
## Quarantining media by ID
|
|
|
|
|
|
|
|
This API quarantines a single piece of local or remote media.
|
|
|
|
|
|
|
|
Request:
|
2019-12-03 13:20:39 -05:00
|
|
|
|
|
|
|
```
|
2020-01-13 13:10:43 -05:00
|
|
|
POST /_synapse/admin/v1/media/quarantine/<server_name>/<media_id>
|
2019-12-03 13:20:39 -05:00
|
|
|
|
|
|
|
{}
|
|
|
|
```
|
|
|
|
|
2020-01-13 13:10:43 -05:00
|
|
|
Where `server_name` is in the form of `example.org`, and `media_id` is in the
|
|
|
|
form of `abcdefg12345...`.
|
|
|
|
|
|
|
|
Response:
|
|
|
|
|
2020-12-09 11:19:57 -05:00
|
|
|
```json
|
2020-01-13 13:10:43 -05:00
|
|
|
{}
|
|
|
|
```
|
|
|
|
|
2021-06-02 13:50:35 -04:00
|
|
|
## Remove media from quarantine by ID
|
|
|
|
|
|
|
|
This API removes a single piece of local or remote media from quarantine.
|
|
|
|
|
|
|
|
Request:
|
|
|
|
|
|
|
|
```
|
|
|
|
POST /_synapse/admin/v1/media/unquarantine/<server_name>/<media_id>
|
|
|
|
|
|
|
|
{}
|
|
|
|
```
|
|
|
|
|
|
|
|
Where `server_name` is in the form of `example.org`, and `media_id` is in the
|
|
|
|
form of `abcdefg12345...`.
|
|
|
|
|
|
|
|
Response:
|
|
|
|
|
|
|
|
```json
|
|
|
|
{}
|
|
|
|
```
|
|
|
|
|
2020-01-13 13:10:43 -05:00
|
|
|
## Quarantining media in a room
|
|
|
|
|
|
|
|
This API quarantines all local and remote media in a room.
|
|
|
|
|
|
|
|
Request:
|
|
|
|
|
|
|
|
```
|
|
|
|
POST /_synapse/admin/v1/room/<room_id>/media/quarantine
|
|
|
|
|
|
|
|
{}
|
|
|
|
```
|
|
|
|
|
|
|
|
Where `room_id` is in the form of `!roomid12345:example.org`.
|
|
|
|
|
|
|
|
Response:
|
|
|
|
|
2020-12-09 11:19:57 -05:00
|
|
|
```json
|
2020-01-13 13:10:43 -05:00
|
|
|
{
|
2020-12-09 11:19:57 -05:00
|
|
|
"num_quarantined": 10
|
2020-01-13 13:10:43 -05:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2020-12-09 11:19:57 -05:00
|
|
|
The following fields are returned in the JSON response body:
|
|
|
|
|
|
|
|
* `num_quarantined`: integer - The number of media items successfully quarantined
|
|
|
|
|
2020-01-13 13:10:43 -05:00
|
|
|
Note that there is a legacy endpoint, `POST
|
2020-12-09 11:19:57 -05:00
|
|
|
/_synapse/admin/v1/quarantine_media/<room_id>`, that operates the same.
|
2020-01-13 13:10:43 -05:00
|
|
|
However, it is deprecated and may be removed in a future release.
|
|
|
|
|
|
|
|
## Quarantining all media of a user
|
|
|
|
|
|
|
|
This API quarantines all *local* media that a *local* user has uploaded. That is to say, if
|
|
|
|
you would like to quarantine media uploaded by a user on a remote homeserver, you should
|
|
|
|
instead use one of the other APIs.
|
|
|
|
|
|
|
|
Request:
|
|
|
|
|
|
|
|
```
|
|
|
|
POST /_synapse/admin/v1/user/<user_id>/media/quarantine
|
|
|
|
|
|
|
|
{}
|
|
|
|
```
|
|
|
|
|
2020-12-09 11:19:57 -05:00
|
|
|
URL Parameters
|
|
|
|
|
|
|
|
* `user_id`: string - User ID in the form of `@bob:example.org`
|
2020-01-13 13:10:43 -05:00
|
|
|
|
|
|
|
Response:
|
|
|
|
|
2020-12-09 11:19:57 -05:00
|
|
|
```json
|
2020-01-13 13:10:43 -05:00
|
|
|
{
|
2020-12-09 11:19:57 -05:00
|
|
|
"num_quarantined": 10
|
2020-01-13 13:10:43 -05:00
|
|
|
}
|
|
|
|
```
|
2020-10-26 13:02:28 -04:00
|
|
|
|
2020-12-09 11:19:57 -05:00
|
|
|
The following fields are returned in the JSON response body:
|
|
|
|
|
|
|
|
* `num_quarantined`: integer - The number of media items successfully quarantined
|
|
|
|
|
2021-01-15 11:18:09 -05:00
|
|
|
## Protecting media from being quarantined
|
|
|
|
|
|
|
|
This API protects a single piece of local media from being quarantined using the
|
|
|
|
above APIs. This is useful for sticker packs and other shared media which you do
|
|
|
|
not want to get quarantined, especially when
|
|
|
|
[quarantining media in a room](#quarantining-media-in-a-room).
|
|
|
|
|
|
|
|
Request:
|
|
|
|
|
|
|
|
```
|
|
|
|
POST /_synapse/admin/v1/media/protect/<media_id>
|
|
|
|
|
|
|
|
{}
|
|
|
|
```
|
|
|
|
|
|
|
|
Where `media_id` is in the form of `abcdefg12345...`.
|
|
|
|
|
|
|
|
Response:
|
|
|
|
|
|
|
|
```json
|
|
|
|
{}
|
|
|
|
```
|
|
|
|
|
2021-05-26 06:19:47 -04:00
|
|
|
## Unprotecting media from being quarantined
|
|
|
|
|
|
|
|
This API reverts the protection of a media.
|
|
|
|
|
|
|
|
Request:
|
|
|
|
|
|
|
|
```
|
|
|
|
POST /_synapse/admin/v1/media/unprotect/<media_id>
|
|
|
|
|
|
|
|
{}
|
|
|
|
```
|
|
|
|
|
|
|
|
Where `media_id` is in the form of `abcdefg12345...`.
|
|
|
|
|
|
|
|
Response:
|
|
|
|
|
|
|
|
```json
|
|
|
|
{}
|
|
|
|
```
|
|
|
|
|
2020-10-26 13:02:28 -04:00
|
|
|
# Delete local media
|
|
|
|
This API deletes the *local* media from the disk of your own server.
|
|
|
|
This includes any local thumbnails and copies of media downloaded from
|
|
|
|
remote homeservers.
|
|
|
|
This API will not affect media that has been uploaded to external
|
|
|
|
media repositories (e.g https://github.com/turt2live/matrix-media-repo/).
|
2020-12-09 11:19:57 -05:00
|
|
|
See also [Purge Remote Media API](#purge-remote-media-api).
|
2020-10-26 13:02:28 -04:00
|
|
|
|
|
|
|
## Delete a specific local media
|
|
|
|
Delete a specific `media_id`.
|
|
|
|
|
|
|
|
Request:
|
|
|
|
|
|
|
|
```
|
|
|
|
DELETE /_synapse/admin/v1/media/<server_name>/<media_id>
|
|
|
|
|
|
|
|
{}
|
|
|
|
```
|
|
|
|
|
|
|
|
URL Parameters
|
|
|
|
|
|
|
|
* `server_name`: string - The name of your local server (e.g `matrix.org`)
|
|
|
|
* `media_id`: string - The ID of the media (e.g `abcdefghijklmnopqrstuvwx`)
|
|
|
|
|
|
|
|
Response:
|
|
|
|
|
|
|
|
```json
|
2020-12-09 11:19:57 -05:00
|
|
|
{
|
|
|
|
"deleted_media": [
|
|
|
|
"abcdefghijklmnopqrstuvwx"
|
|
|
|
],
|
|
|
|
"total": 1
|
|
|
|
}
|
2020-10-26 13:02:28 -04:00
|
|
|
```
|
|
|
|
|
|
|
|
The following fields are returned in the JSON response body:
|
|
|
|
|
|
|
|
* `deleted_media`: an array of strings - List of deleted `media_id`
|
|
|
|
* `total`: integer - Total number of deleted `media_id`
|
|
|
|
|
|
|
|
## Delete local media by date or size
|
|
|
|
|
|
|
|
Request:
|
|
|
|
|
|
|
|
```
|
|
|
|
POST /_synapse/admin/v1/media/<server_name>/delete?before_ts=<before_ts>
|
|
|
|
|
|
|
|
{}
|
|
|
|
```
|
|
|
|
|
|
|
|
URL Parameters
|
|
|
|
|
|
|
|
* `server_name`: string - The name of your local server (e.g `matrix.org`).
|
2021-10-20 10:41:48 -04:00
|
|
|
* `before_ts`: string representing a positive integer - Unix timestamp in milliseconds.
|
2020-10-26 13:02:28 -04:00
|
|
|
Files that were last used before this timestamp will be deleted. It is the timestamp of
|
2021-10-20 10:41:48 -04:00
|
|
|
last access, not the timestamp when the file was created.
|
2020-10-26 13:02:28 -04:00
|
|
|
* `size_gt`: Optional - string representing a positive integer - Size of the media in bytes.
|
|
|
|
Files that are larger will be deleted. Defaults to `0`.
|
|
|
|
* `keep_profiles`: Optional - string representing a boolean - Switch to also delete files
|
|
|
|
that are still used in image data (e.g user profile, room avatar).
|
|
|
|
If `false` these files will be deleted. Defaults to `true`.
|
|
|
|
|
|
|
|
Response:
|
|
|
|
|
|
|
|
```json
|
2020-12-09 11:19:57 -05:00
|
|
|
{
|
|
|
|
"deleted_media": [
|
|
|
|
"abcdefghijklmnopqrstuvwx",
|
|
|
|
"abcdefghijklmnopqrstuvwz"
|
|
|
|
],
|
|
|
|
"total": 2
|
|
|
|
}
|
2020-10-26 13:02:28 -04:00
|
|
|
```
|
|
|
|
|
|
|
|
The following fields are returned in the JSON response body:
|
|
|
|
|
|
|
|
* `deleted_media`: an array of strings - List of deleted `media_id`
|
|
|
|
* `total`: integer - Total number of deleted `media_id`
|
2020-12-09 11:19:57 -05:00
|
|
|
|
2021-08-11 15:29:59 -04:00
|
|
|
## Delete media uploaded by a user
|
|
|
|
|
|
|
|
You can find details of how to delete multiple media uploaded by a user in
|
|
|
|
[User Admin API](user_admin_api.md#delete-media-uploaded-by-a-user).
|
|
|
|
|
2020-12-09 11:19:57 -05:00
|
|
|
# Purge Remote Media API
|
|
|
|
|
|
|
|
The purge remote media API allows server admins to purge old cached remote media.
|
|
|
|
|
|
|
|
The API is:
|
|
|
|
|
|
|
|
```
|
|
|
|
POST /_synapse/admin/v1/purge_media_cache?before_ts=<unix_timestamp_in_ms>
|
|
|
|
|
|
|
|
{}
|
|
|
|
```
|
|
|
|
|
|
|
|
URL Parameters
|
|
|
|
|
2021-10-20 10:41:48 -04:00
|
|
|
* `unix_timestamp_in_ms`: string representing a positive integer - Unix timestamp in milliseconds.
|
2020-12-09 11:19:57 -05:00
|
|
|
All cached media that was last accessed before this timestamp will be removed.
|
|
|
|
|
|
|
|
Response:
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"deleted": 10
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
The following fields are returned in the JSON response body:
|
|
|
|
|
|
|
|
* `deleted`: integer - The number of media items successfully deleted
|
|
|
|
|
|
|
|
To use it, you will need to authenticate by providing an `access_token` for a
|
2021-06-16 08:15:52 -04:00
|
|
|
server admin: see [Admin API](../usage/administration/admin_api).
|
2020-12-09 11:19:57 -05:00
|
|
|
|
|
|
|
If the user re-requests purged remote media, synapse will re-request the media
|
|
|
|
from the originating server.
|