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

Commit

Permalink
fixup! media/create: add /create endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Sumner Evans <me@sumnerevans.com>
  • Loading branch information
sumnerevans committed Nov 9, 2023
1 parent 37c7970 commit acadec0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
8 changes: 3 additions & 5 deletions synapse/media/media_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions synapse/rest/media/create_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit acadec0

Please sign in to comment.