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

View File

@ -62,6 +62,13 @@ class InvalidUserInContext(Exception):
class UneededThumbnail(Exception): class UneededThumbnail(Exception):
pass pass
@dataclass @dataclass
class UnthumbnailableError(Exception): class UnthumbnailableError(Exception):
exception: Optional[Exception] = None 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 . import __about__, utils
from .errors import ( from .errors import (
InvalidUserInContext, MatrixError, UneededThumbnail, UnthumbnailableError, BadMimeType, InvalidUserInContext, MatrixError, UneededThumbnail,
UserNotFound, UnthumbnailableError, UserNotFound,
) )
from .html_filter import HTML_FILTER from .html_filter import HTML_FILTER
from .models.items import ( from .models.items import (
@ -617,7 +617,11 @@ class MatrixClient(nio.AsyncClient):
async def set_avatar_from_file(self, path: Union[Path, str]) -> None: 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]) await self.set_avatar((await self.upload_file(path))[0])