set_avatar_from_file: raise if file isn't an image

This commit is contained in:
miruka 2019-11-12 09:48:11 -04:00
parent 5f04628178
commit 9f3bb1aa4d
3 changed files with 15 additions and 7 deletions

View File

@ -1,7 +1,7 @@
- Media
- Verify things work with chat.privacytools.io (subdomain weirdness)
- Confirmation box after picking file to upload
- Handle upload errors: non existent path, path is a dir, file too big, etc
- Handle upload/set avatar errors: bad path, is a dir, file too big, etc
- Show real progression for mxc thumbnail loadings, uploads and downloads
- Show reason under broken thumbnail icons
@ -52,11 +52,9 @@
- Don't store states in delegates
- [hr not working](https://bugreports.qt.io/browse/QTBUG-74342)
- Terrible performance using `QT_QPA_PLATFORM=wayland-egl`, must use `xcb`
- Verify big avatars aren't downloaded uselessly
- Quote links color in room subtitles (e.g. "> http://foo.orgA)" )
- UI
- Show error if uploading avatar fails or file is corrupted
- Way to open context menus without a right mouse button
- `smartVerticalFlick()` gradual acceleration
@ -166,7 +164,6 @@
the message with `decrypt_event()`" - poljar
- [Soft logouts](https://github.com/poljar/matrix-nio/commit/aba10)
- `translated` arg for avatar upload and login errors
- Check if username exists on login screen
- `pyotherside.atexit()`
- Logout previous session if adding an account that's already connected

View File

@ -62,6 +62,13 @@ class InvalidUserInContext(Exception):
class UneededThumbnail(Exception):
pass
@dataclass
class UnthumbnailableError(Exception):
exception: Optional[Exception] = None
@dataclass
class BadMimeType(Exception):
wanted: str = field()
got: str = field()

View File

@ -25,8 +25,8 @@ import nio
from . import __about__, utils
from .errors import (
InvalidUserInContext, MatrixError, UneededThumbnail, UnthumbnailableError,
UserNotFound,
BadMimeType, InvalidUserInContext, MatrixError, UneededThumbnail,
UnthumbnailableError, UserNotFound,
)
from .html_filter import HTML_FILTER
from .models.items import (
@ -617,7 +617,11 @@ class MatrixClient(nio.AsyncClient):
async def set_avatar_from_file(self, path: Union[Path, str]) -> None:
# TODO: check if mime is image
mime = utils.guess_mime(path)
if mime.split("/")[0] != "image":
raise BadMimeType(wanted="image/*", got=mime)
await self.set_avatar((await self.upload_file(path))[0])