You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

media_admin_api.md 7.5 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. # Contents
  2. - [Querying media](#querying-media)
  3. * [List all media in a room](#list-all-media-in-a-room)
  4. * [List all media uploaded by a user](#list-all-media-uploaded-by-a-user)
  5. - [Quarantine media](#quarantine-media)
  6. * [Quarantining media by ID](#quarantining-media-by-id)
  7. * [Remove media from quarantine by ID](#remove-media-from-quarantine-by-id)
  8. * [Quarantining media in a room](#quarantining-media-in-a-room)
  9. * [Quarantining all media of a user](#quarantining-all-media-of-a-user)
  10. * [Protecting media from being quarantined](#protecting-media-from-being-quarantined)
  11. * [Unprotecting media from being quarantined](#unprotecting-media-from-being-quarantined)
  12. - [Delete local media](#delete-local-media)
  13. * [Delete a specific local media](#delete-a-specific-local-media)
  14. * [Delete local media by date or size](#delete-local-media-by-date-or-size)
  15. - [Purge Remote Media API](#purge-remote-media-api)
  16. # Querying media
  17. These APIs allow extracting media information from the homeserver.
  18. ## List all media in a room
  19. This API gets a list of known media in a room.
  20. However, it only shows media from unencrypted events or rooms.
  21. The API is:
  22. ```
  23. GET /_synapse/admin/v1/room/<room_id>/media
  24. ```
  25. To use it, you will need to authenticate by providing an `access_token` for a
  26. server admin: see [Admin API](../../usage/administration/admin_api).
  27. The API returns a JSON body like the following:
  28. ```json
  29. {
  30. "local": [
  31. "mxc://localhost/xwvutsrqponmlkjihgfedcba",
  32. "mxc://localhost/abcdefghijklmnopqrstuvwx"
  33. ],
  34. "remote": [
  35. "mxc://matrix.org/xwvutsrqponmlkjihgfedcba",
  36. "mxc://matrix.org/abcdefghijklmnopqrstuvwx"
  37. ]
  38. }
  39. ```
  40. ## List all media uploaded by a user
  41. Listing all media that has been uploaded by a local user can be achieved through
  42. the use of the [List media of a user](user_admin_api.rst#list-media-of-a-user)
  43. Admin API.
  44. # Quarantine media
  45. Quarantining media means that it is marked as inaccessible by users. It applies
  46. to any local media, and any locally-cached copies of remote media.
  47. The media file itself (and any thumbnails) is not deleted from the server.
  48. ## Quarantining media by ID
  49. This API quarantines a single piece of local or remote media.
  50. Request:
  51. ```
  52. POST /_synapse/admin/v1/media/quarantine/<server_name>/<media_id>
  53. {}
  54. ```
  55. Where `server_name` is in the form of `example.org`, and `media_id` is in the
  56. form of `abcdefg12345...`.
  57. Response:
  58. ```json
  59. {}
  60. ```
  61. ## Remove media from quarantine by ID
  62. This API removes a single piece of local or remote media from quarantine.
  63. Request:
  64. ```
  65. POST /_synapse/admin/v1/media/unquarantine/<server_name>/<media_id>
  66. {}
  67. ```
  68. Where `server_name` is in the form of `example.org`, and `media_id` is in the
  69. form of `abcdefg12345...`.
  70. Response:
  71. ```json
  72. {}
  73. ```
  74. ## Quarantining media in a room
  75. This API quarantines all local and remote media in a room.
  76. Request:
  77. ```
  78. POST /_synapse/admin/v1/room/<room_id>/media/quarantine
  79. {}
  80. ```
  81. Where `room_id` is in the form of `!roomid12345:example.org`.
  82. Response:
  83. ```json
  84. {
  85. "num_quarantined": 10
  86. }
  87. ```
  88. The following fields are returned in the JSON response body:
  89. * `num_quarantined`: integer - The number of media items successfully quarantined
  90. Note that there is a legacy endpoint, `POST
  91. /_synapse/admin/v1/quarantine_media/<room_id>`, that operates the same.
  92. However, it is deprecated and may be removed in a future release.
  93. ## Quarantining all media of a user
  94. This API quarantines all *local* media that a *local* user has uploaded. That is to say, if
  95. you would like to quarantine media uploaded by a user on a remote homeserver, you should
  96. instead use one of the other APIs.
  97. Request:
  98. ```
  99. POST /_synapse/admin/v1/user/<user_id>/media/quarantine
  100. {}
  101. ```
  102. URL Parameters
  103. * `user_id`: string - User ID in the form of `@bob:example.org`
  104. Response:
  105. ```json
  106. {
  107. "num_quarantined": 10
  108. }
  109. ```
  110. The following fields are returned in the JSON response body:
  111. * `num_quarantined`: integer - The number of media items successfully quarantined
  112. ## Protecting media from being quarantined
  113. This API protects a single piece of local media from being quarantined using the
  114. above APIs. This is useful for sticker packs and other shared media which you do
  115. not want to get quarantined, especially when
  116. [quarantining media in a room](#quarantining-media-in-a-room).
  117. Request:
  118. ```
  119. POST /_synapse/admin/v1/media/protect/<media_id>
  120. {}
  121. ```
  122. Where `media_id` is in the form of `abcdefg12345...`.
  123. Response:
  124. ```json
  125. {}
  126. ```
  127. ## Unprotecting media from being quarantined
  128. This API reverts the protection of a media.
  129. Request:
  130. ```
  131. POST /_synapse/admin/v1/media/unprotect/<media_id>
  132. {}
  133. ```
  134. Where `media_id` is in the form of `abcdefg12345...`.
  135. Response:
  136. ```json
  137. {}
  138. ```
  139. # Delete local media
  140. This API deletes the *local* media from the disk of your own server.
  141. This includes any local thumbnails and copies of media downloaded from
  142. remote homeservers.
  143. This API will not affect media that has been uploaded to external
  144. media repositories (e.g https://github.com/turt2live/matrix-media-repo/).
  145. See also [Purge Remote Media API](#purge-remote-media-api).
  146. ## Delete a specific local media
  147. Delete a specific `media_id`.
  148. Request:
  149. ```
  150. DELETE /_synapse/admin/v1/media/<server_name>/<media_id>
  151. {}
  152. ```
  153. URL Parameters
  154. * `server_name`: string - The name of your local server (e.g `matrix.org`)
  155. * `media_id`: string - The ID of the media (e.g `abcdefghijklmnopqrstuvwx`)
  156. Response:
  157. ```json
  158. {
  159. "deleted_media": [
  160. "abcdefghijklmnopqrstuvwx"
  161. ],
  162. "total": 1
  163. }
  164. ```
  165. The following fields are returned in the JSON response body:
  166. * `deleted_media`: an array of strings - List of deleted `media_id`
  167. * `total`: integer - Total number of deleted `media_id`
  168. ## Delete local media by date or size
  169. Request:
  170. ```
  171. POST /_synapse/admin/v1/media/<server_name>/delete?before_ts=<before_ts>
  172. {}
  173. ```
  174. URL Parameters
  175. * `server_name`: string - The name of your local server (e.g `matrix.org`).
  176. * `before_ts`: string representing a positive integer - Unix timestamp in ms.
  177. Files that were last used before this timestamp will be deleted. It is the timestamp of
  178. last access and not the timestamp creation.
  179. * `size_gt`: Optional - string representing a positive integer - Size of the media in bytes.
  180. Files that are larger will be deleted. Defaults to `0`.
  181. * `keep_profiles`: Optional - string representing a boolean - Switch to also delete files
  182. that are still used in image data (e.g user profile, room avatar).
  183. If `false` these files will be deleted. Defaults to `true`.
  184. Response:
  185. ```json
  186. {
  187. "deleted_media": [
  188. "abcdefghijklmnopqrstuvwx",
  189. "abcdefghijklmnopqrstuvwz"
  190. ],
  191. "total": 2
  192. }
  193. ```
  194. The following fields are returned in the JSON response body:
  195. * `deleted_media`: an array of strings - List of deleted `media_id`
  196. * `total`: integer - Total number of deleted `media_id`
  197. # Purge Remote Media API
  198. The purge remote media API allows server admins to purge old cached remote media.
  199. The API is:
  200. ```
  201. POST /_synapse/admin/v1/purge_media_cache?before_ts=<unix_timestamp_in_ms>
  202. {}
  203. ```
  204. URL Parameters
  205. * `unix_timestamp_in_ms`: string representing a positive integer - Unix timestamp in ms.
  206. All cached media that was last accessed before this timestamp will be removed.
  207. Response:
  208. ```json
  209. {
  210. "deleted": 10
  211. }
  212. ```
  213. The following fields are returned in the JSON response body:
  214. * `deleted`: integer - The number of media items successfully deleted
  215. To use it, you will need to authenticate by providing an `access_token` for a
  216. server admin: see [Admin API](../../usage/administration/admin_api).
  217. If the user re-requests purged remote media, synapse will re-request the media
  218. from the originating server.