Skip to content

Commit

Permalink
Fix unrelated linter errors...
Browse files Browse the repository at this point in the history
  • Loading branch information
devonh committed May 3, 2024
1 parent 0bdcf0d commit a50d304
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions synapse/handlers/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#
import logging
import random
from typing import TYPE_CHECKING, Optional, Union
from typing import TYPE_CHECKING, List, Optional, Union

from synapse.api.errors import (
AuthError,
Expand Down Expand Up @@ -64,8 +64,10 @@ def __init__(self, hs: "HomeServer"):
self.user_directory_handler = hs.get_user_directory_handler()
self.request_ratelimiter = hs.get_request_ratelimiter()

self.max_avatar_size = hs.config.server.max_avatar_size
self.allowed_avatar_mimetypes = hs.config.server.allowed_avatar_mimetypes
self.max_avatar_size: Optional[int] = hs.config.server.max_avatar_size
self.allowed_avatar_mimetypes: Optional[List[str]] = (
hs.config.server.allowed_avatar_mimetypes
)

self._is_mine_server_name = hs.is_mine_server_name

Expand Down Expand Up @@ -338,7 +340,10 @@ async def check_avatar_size_and_mime_type(self, mxc: str) -> bool:

if self.max_avatar_size:
# Ensure avatar does not exceed max allowed avatar size
if media_info.media_length > self.max_avatar_size:
if (
media_info.media_length
and media_info.media_length > self.max_avatar_size
):
logger.warning(
"Forbidding avatar change to %s: %d bytes is above the allowed size "
"limit",
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/sso.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ def is_allowed_mime_type(content_type: str) -> bool:
server_name = profile["avatar_url"].split("/")[-2]
media_id = profile["avatar_url"].split("/")[-1]
if self._is_mine_server_name(server_name):
media = await self._media_repo.store.get_local_media(media_id)
media = await self._media_repo.store.get_local_media(media_id) # type: ignore[has-type]
if media is not None and upload_name == media.upload_name:
logger.info("skipping saving the user avatar")
return True
Expand Down

0 comments on commit a50d304

Please sign in to comment.