Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 999bd77

Browse files
authored
Asynchronous Uploads (#15503)
Support asynchronous uploads as defined in MSC2246.
1 parent 80922dc commit 999bd77

14 files changed

+568
-59
lines changed

changelog.d/15503.feature

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add support for asynchronous uploads as defined by [MSC2246](https://github.com/matrix-org/matrix-spec-proposals/pull/2246). Contributed by @sumnerevans at @beeper.

docs/usage/configuration/config_documentation.md

+34
Original file line numberDiff line numberDiff line change
@@ -1753,6 +1753,19 @@ rc_third_party_invite:
17531753
burst_count: 10
17541754
```
17551755
---
1756+
### `rc_media_create`
1757+
1758+
This option ratelimits creation of MXC URIs via the `/_matrix/media/v1/create`
1759+
endpoint based on the account that's creating the media. Defaults to
1760+
`per_second: 10`, `burst_count: 50`.
1761+
1762+
Example configuration:
1763+
```yaml
1764+
rc_media_create:
1765+
per_second: 10
1766+
burst_count: 50
1767+
```
1768+
---
17561769
### `rc_federation`
17571770

17581771
Defines limits on federation requests.
@@ -1814,6 +1827,27 @@ Example configuration:
18141827
media_store_path: "DATADIR/media_store"
18151828
```
18161829
---
1830+
### `max_pending_media_uploads`
1831+
1832+
How many *pending media uploads* can a given user have? A pending media upload
1833+
is a created MXC URI that (a) is not expired (the `unused_expires_at` timestamp
1834+
has not passed) and (b) the media has not yet been uploaded for. Defaults to 5.
1835+
1836+
Example configuration:
1837+
```yaml
1838+
max_pending_media_uploads: 5
1839+
```
1840+
---
1841+
### `unused_expiration_time`
1842+
1843+
How long to wait in milliseconds before expiring created media IDs. Defaults to
1844+
"24h"
1845+
1846+
Example configuration:
1847+
```yaml
1848+
unused_expiration_time: "1h"
1849+
```
1850+
---
18171851
### `media_storage_providers`
18181852

18191853
Media storage providers allow media to be stored in different

synapse/api/errors.py

+2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ class Codes(str, Enum):
8383
USER_DEACTIVATED = "M_USER_DEACTIVATED"
8484
# USER_LOCKED = "M_USER_LOCKED"
8585
USER_LOCKED = "ORG_MATRIX_MSC3939_USER_LOCKED"
86+
NOT_YET_UPLOADED = "M_NOT_YET_UPLOADED"
87+
CANNOT_OVERWRITE_MEDIA = "M_CANNOT_OVERWRITE_MEDIA"
8688

8789
# Part of MSC3848
8890
# https://github.com/matrix-org/matrix-spec-proposals/pull/3848

synapse/config/ratelimiting.py

+7
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,10 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
204204
"rc_third_party_invite",
205205
defaults={"per_second": 0.0025, "burst_count": 5},
206206
)
207+
208+
# Ratelimit create media requests:
209+
self.rc_media_create = RatelimitSettings.parse(
210+
config,
211+
"rc_media_create",
212+
defaults={"per_second": 10, "burst_count": 50},
213+
)

synapse/config/repository.py

+6
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
141141
"prevent_media_downloads_from", []
142142
)
143143

144+
self.unused_expiration_time = self.parse_duration(
145+
config.get("unused_expiration_time", "24h")
146+
)
147+
148+
self.max_pending_media_uploads = config.get("max_pending_media_uploads", 5)
149+
144150
self.media_store_path = self.ensure_directory(
145151
config.get("media_store_path", "media_store")
146152
)

synapse/media/_base.py

+6
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@
8383
"audio/x-flac",
8484
]
8585

86+
# Default timeout_ms for download and thumbnail requests
87+
DEFAULT_MAX_TIMEOUT_MS = 20_000
88+
89+
# Maximum allowed timeout_ms for download and thumbnail requests
90+
MAXIMUM_ALLOWED_MAX_TIMEOUT_MS = 60_000
91+
8692

8793
def respond_404(request: SynapseRequest) -> None:
8894
assert request.path is not None

0 commit comments

Comments
 (0)