1
0
This commit is contained in:
anoadragon453
2025-09-12 11:28:19 +00:00
parent 9ddcf4f62b
commit 2c4a8db8ee
6 changed files with 103 additions and 5 deletions

View File

@@ -206,6 +206,53 @@ enforce a different limit for the particular user.</p>
returns <code>True</code>, Synapse falls through to the next one. The value of the first callback that
returns <code>False</code> will be used. If this happens, Synapse will not call any of the subsequent
implementations of this callback.</p>
<h3 id="get_media_upload_limits_for_user"><a class="header" href="#get_media_upload_limits_for_user"><code>get_media_upload_limits_for_user</code></a></h3>
<p><em>First introduced in Synapse v1.139.0</em></p>
<pre><code class="language-python">async def get_media_upload_limits_for_user(user_id: str, size: int) -&gt; Optional[List[synapse.module_api.MediaUploadLimit]]
</code></pre>
<p><strong><span style="color:red">
Caution: This callback is currently experimental. The method signature or behaviour
may change without notice.
</span></strong></p>
<p>Called when processing a request to store content in the media repository. This can be used to dynamically override
the <a href="../usage/configuration/config_documentation.html#media_upload_limits">media upload limits configuration</a>.</p>
<p>The arguments passed to this callback are:</p>
<ul>
<li><code>user_id</code>: The Matrix user ID of the user (e.g. <code>@alice:example.com</code>) making the request.</li>
</ul>
<p>If the callback returns a list then it will be used as the limits instead of those in the configuration (if any).</p>
<p>If an empty list is returned then no limits are applied (<strong>warning:</strong> users will be able
to upload as much data as they desire).</p>
<p>If multiple modules implement this callback, they will be considered in order. If a
callback returns <code>None</code>, Synapse falls through to the next one. The value of the first
callback that does not return <code>None</code> will be used. If this happens, Synapse will not call
any of the subsequent implementations of this callback.</p>
<p>If there are no registered modules, or if all modules return <code>None</code>, then
the default
<a href="../usage/configuration/config_documentation.html#media_upload_limits">media upload limits configuration</a>
will be used.</p>
<h3 id="on_media_upload_limit_exceeded"><a class="header" href="#on_media_upload_limit_exceeded"><code>on_media_upload_limit_exceeded</code></a></h3>
<p><em>First introduced in Synapse v1.139.0</em></p>
<pre><code class="language-python">async def on_media_upload_limit_exceeded(user_id: str, limit: synapse.module_api.MediaUploadLimit, sent_bytes: int, attempted_bytes: int) -&gt; None
</code></pre>
<p><strong><span style="color:red">
Caution: This callback is currently experimental. The method signature or behaviour
may change without notice.
</span></strong></p>
<p>Called when a user attempts to upload media that would exceed a
<a href="../usage/configuration/config_documentation.html#media_upload_limits">configured media upload limit</a>.</p>
<p>This callback will only be called on workers which handle
<a href="https://spec.matrix.org/v1.15/client-server-api/#post_matrixmediav3upload">POST /_matrix/media/v3/upload</a>
requests.</p>
<p>This could be used to inform the user that they have reached a media upload limit through
some external method.</p>
<p>The arguments passed to this callback are:</p>
<ul>
<li><code>user_id</code>: The Matrix user ID of the user (e.g. <code>@alice:example.com</code>) making the request.</li>
<li><code>limit</code>: The <code>synapse.module_api.MediaUploadLimit</code> representing the limit that was reached.</li>
<li><code>sent_bytes</code>: The number of bytes already sent during the period of the limit.</li>
<li><code>attempted_bytes</code>: The number of bytes that the user attempted to send.</li>
</ul>
</main>

View File

@@ -5836,8 +5836,10 @@ Setting this to a high value allows users to report content quickly, possibly in
</code></pre>
<hr />
<h3 id="media_upload_limits"><a class="header" href="#media_upload_limits"><code>media_upload_limits</code></a></h3>
<p><em>(array)</em> A list of media upload limits defining how much data a given user can upload in a given time period.</p>
<p><em>(array)</em> A list of media upload limits defining how much data a given user can upload in a given time period.
These limits are applied in addition to the <code>max_upload_size</code> limit above (which applies to individual uploads).</p>
<p>An empty list means no limits are applied.</p>
<p>These settings can be overridden using the <code>get_media_upload_limits_for_user</code> module API <a href="usage/configuration/../../modules/media_repository_callbacks.html#get_media_upload_limits_for_user">callback</a>.</p>
<p>Defaults to <code>[]</code>.</p>
<p>Example configuration:</p>
<pre><code class="language-yaml">media_upload_limits:
@@ -11702,6 +11704,53 @@ enforce a different limit for the particular user.</p>
returns <code>True</code>, Synapse falls through to the next one. The value of the first callback that
returns <code>False</code> will be used. If this happens, Synapse will not call any of the subsequent
implementations of this callback.</p>
<h3 id="get_media_upload_limits_for_user"><a class="header" href="#get_media_upload_limits_for_user"><code>get_media_upload_limits_for_user</code></a></h3>
<p><em>First introduced in Synapse v1.139.0</em></p>
<pre><code class="language-python">async def get_media_upload_limits_for_user(user_id: str, size: int) -&gt; Optional[List[synapse.module_api.MediaUploadLimit]]
</code></pre>
<p><strong><span style="color:red">
Caution: This callback is currently experimental. The method signature or behaviour
may change without notice.
</span></strong></p>
<p>Called when processing a request to store content in the media repository. This can be used to dynamically override
the <a href="modules/../usage/configuration/config_documentation.html#media_upload_limits">media upload limits configuration</a>.</p>
<p>The arguments passed to this callback are:</p>
<ul>
<li><code>user_id</code>: The Matrix user ID of the user (e.g. <code>@alice:example.com</code>) making the request.</li>
</ul>
<p>If the callback returns a list then it will be used as the limits instead of those in the configuration (if any).</p>
<p>If an empty list is returned then no limits are applied (<strong>warning:</strong> users will be able
to upload as much data as they desire).</p>
<p>If multiple modules implement this callback, they will be considered in order. If a
callback returns <code>None</code>, Synapse falls through to the next one. The value of the first
callback that does not return <code>None</code> will be used. If this happens, Synapse will not call
any of the subsequent implementations of this callback.</p>
<p>If there are no registered modules, or if all modules return <code>None</code>, then
the default
<a href="modules/../usage/configuration/config_documentation.html#media_upload_limits">media upload limits configuration</a>
will be used.</p>
<h3 id="on_media_upload_limit_exceeded"><a class="header" href="#on_media_upload_limit_exceeded"><code>on_media_upload_limit_exceeded</code></a></h3>
<p><em>First introduced in Synapse v1.139.0</em></p>
<pre><code class="language-python">async def on_media_upload_limit_exceeded(user_id: str, limit: synapse.module_api.MediaUploadLimit, sent_bytes: int, attempted_bytes: int) -&gt; None
</code></pre>
<p><strong><span style="color:red">
Caution: This callback is currently experimental. The method signature or behaviour
may change without notice.
</span></strong></p>
<p>Called when a user attempts to upload media that would exceed a
<a href="modules/../usage/configuration/config_documentation.html#media_upload_limits">configured media upload limit</a>.</p>
<p>This callback will only be called on workers which handle
<a href="https://spec.matrix.org/v1.15/client-server-api/#post_matrixmediav3upload">POST /_matrix/media/v3/upload</a>
requests.</p>
<p>This could be used to inform the user that they have reached a media upload limit through
some external method.</p>
<p>The arguments passed to this callback are:</p>
<ul>
<li><code>user_id</code>: The Matrix user ID of the user (e.g. <code>@alice:example.com</code>) making the request.</li>
<li><code>limit</code>: The <code>synapse.module_api.MediaUploadLimit</code> representing the limit that was reached.</li>
<li><code>sent_bytes</code>: The number of bytes already sent during the period of the limit.</li>
<li><code>attempted_bytes</code>: The number of bytes that the user attempted to send.</li>
</ul>
<div style="break-before: page; page-break-before: always;"></div><h1 id="ratelimit-callbacks"><a class="header" href="#ratelimit-callbacks">Ratelimit callbacks</a></h1>
<p>Ratelimit callbacks allow module developers to override ratelimit settings dynamically whilst
Synapse is running. Ratelimit callbacks can be registered using the module API's

View File

@@ -2089,7 +2089,7 @@
},
"media_upload_limits": {
"type": "array",
"description": "A list of media upload limits defining how much data a given user can upload in a given time period.\n\nAn empty list means no limits are applied.",
"description": "A list of media upload limits defining how much data a given user can upload in a given time period.\nThese limits are applied in addition to the `max_upload_size` limit above (which applies to individual uploads).\n\nAn empty list means no limits are applied.\n\nThese settings can be overridden using the `get_media_upload_limits_for_user` module API [callback](../../modules/media_repository_callbacks.md#get_media_upload_limits_for_user).",
"default": [],
"items": {
"time_period": {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -2048,8 +2048,10 @@ Setting this to a high value allows users to report content quickly, possibly in
</code></pre>
<hr />
<h3 id="media_upload_limits"><a class="header" href="#media_upload_limits"><code>media_upload_limits</code></a></h3>
<p><em>(array)</em> A list of media upload limits defining how much data a given user can upload in a given time period.</p>
<p><em>(array)</em> A list of media upload limits defining how much data a given user can upload in a given time period.
These limits are applied in addition to the <code>max_upload_size</code> limit above (which applies to individual uploads).</p>
<p>An empty list means no limits are applied.</p>
<p>These settings can be overridden using the <code>get_media_upload_limits_for_user</code> module API <a href="../../modules/media_repository_callbacks.html#get_media_upload_limits_for_user">callback</a>.</p>
<p>Defaults to <code>[]</code>.</p>
<p>Example configuration:</p>
<pre><code class="language-yaml">media_upload_limits: