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

Asynchronous Uploads #15460

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/15460.feature
Original file line number Diff line number Diff line change
@@ -0,0 +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.
23 changes: 23 additions & 0 deletions docs/usage/configuration/config_documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -1664,6 +1664,19 @@ rc_third_party_invite:
burst_count: 10
```
---
### `rc_media_create`

This option ratelimits creation of MXC URIs via the MSC2246 asynchronous upload
`/_matrix/media/v1/create` endpoint based on the account that's creating the
media. Defaults to `per_second: 10`, `burst_count: 50`.

Example configuration:
```yaml
rc_media_create:
per_second: 10
burst_count: 50
```
---
### `rc_federation`

Defines limits on federation requests.
Expand Down Expand Up @@ -1725,6 +1738,16 @@ Example configuration:
media_store_path: "DATADIR/media_store"
```
---
### `unused_expiration_time`

How long to wait in milliseconds before expiring created media IDs when MSC2246
support is enabled. Defaults to "24h"

Example configuration:
```yaml
unused_expiration_time: "1h"
```
---
### `media_storage_providers`

Media storage providers allow media to be stored in different
Expand Down
1 change: 1 addition & 0 deletions synapse/api/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class Codes(str, Enum):
WEAK_PASSWORD = "M_WEAK_PASSWORD"
INVALID_SIGNATURE = "M_INVALID_SIGNATURE"
USER_DEACTIVATED = "M_USER_DEACTIVATED"
NOT_YET_UPLOADED = "M_NOT_YET_UPLOADED"

# Part of MSC3848
# https://github.com/matrix-org/matrix-spec-proposals/pull/3848
Expand Down
6 changes: 6 additions & 0 deletions synapse/config/ratelimiting.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,9 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
config.get("rc_third_party_invite", {}),
defaults={"per_second": 0.0025, "burst_count": 5},
)

# Ratelimit create media requests:
self.rc_media_create = RatelimitSettings(
config.get("rc_media_create", {}),
defaults={"per_second": 10, "burst_count": 50},
)
4 changes: 4 additions & 0 deletions synapse/config/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
self.max_image_pixels = self.parse_size(config.get("max_image_pixels", "32M"))
self.max_spider_size = self.parse_size(config.get("max_spider_size", "10M"))

self.unused_expiration_time = self.parse_duration(
config.get("unused_expiration_time", "24h")
)

self.media_store_path = self.ensure_directory(
config.get("media_store_path", "media_store")
)
Expand Down
6 changes: 6 additions & 0 deletions synapse/media/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@
"text/xml",
]

# Default timeout_ms for download and thumbnail requests
DEFAULT_MAX_TIMEOUT_MS = 20_000

# Maximum allowed timeout_ms for download and thumbnail requests
MAXIMUM_ALLOWED_MAX_TIMEOUT_MS = 60_000


def parse_media_id(request: Request) -> Tuple[str, str, Optional[str]]:
"""Parses the server name, media ID and optional file name from the request URI
Expand Down
Loading