From acadec01455702236a3b59fd94328e091c6d3a4e Mon Sep 17 00:00:00 2001 From: Sumner Evans Date: Thu, 9 Nov 2023 16:28:14 -0700 Subject: [PATCH] fixup! media/create: add /create endpoint Signed-off-by: Sumner Evans --- synapse/media/media_repository.py | 8 +++----- synapse/rest/media/create_resource.py | 4 +--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/synapse/media/media_repository.py b/synapse/media/media_repository.py index 4e4e8843790c..7d8788ffcc5f 100644 --- a/synapse/media/media_repository.py +++ b/synapse/media/media_repository.py @@ -84,6 +84,7 @@ def __init__(self, hs: "HomeServer"): self.max_upload_size = hs.config.media.max_upload_size self.max_image_pixels = hs.config.media.max_image_pixels self.unused_expiration_time = hs.config.media.unused_expiration_time + self.max_pending_media_uploads = hs.config.media.max_pending_media_uploads Thumbnailer.set_limits(self.max_image_pixels) @@ -211,14 +212,11 @@ async def create_media_id(self, auth_user: UserID) -> Tuple[str, int]: return f"mxc://{self.server_name}/{media_id}", now + self.unused_expiration_time @trace - async def reached_pending_media_limit( - self, auth_user: UserID, limit: int - ) -> Tuple[bool, int]: + async def reached_pending_media_limit(self, auth_user: UserID) -> Tuple[bool, int]: """Check if the user is over the limit for pending media uploads. Args: auth_user: The user_id of the uploader - limit: The maximum number of pending media uploads a user is allowed to have Returns: A tuple with a boolean and an integer indicating whether the user has too @@ -228,7 +226,7 @@ async def reached_pending_media_limit( pending, first_expiration_ts = await self.store.count_pending_media( user_id=auth_user ) - return pending >= limit, first_expiration_ts + return pending >= self.max_pending_media_uploads, first_expiration_ts @trace async def verify_can_upload(self, media_id: str, auth_user: UserID) -> None: diff --git a/synapse/rest/media/create_resource.py b/synapse/rest/media/create_resource.py index 09d1d3caf003..7717435a1e2e 100644 --- a/synapse/rest/media/create_resource.py +++ b/synapse/rest/media/create_resource.py @@ -59,9 +59,7 @@ async def _async_render_POST(self, request: SynapseRequest) -> None: ( reached_pending_limit, first_expiration_ts, - ) = await self.media_repo.reached_pending_media_limit( - requester.user, self.max_pending_media_uploads - ) + ) = await self.media_repo.reached_pending_media_limit(requester.user) if reached_pending_limit: raise LimitExceededError( limiter_name="max_pending_media_uploads",