From 630db1e1e9704fd2762d96530ccf7b28832a4792 Mon Sep 17 00:00:00 2001 From: Luna Mendes Date: Sat, 17 Nov 2018 18:26:42 -0300 Subject: [PATCH] images: add always_icon kwarg to put() - guilds: use always_icon --- litecord/blueprints/guilds.py | 2 +- litecord/images.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/litecord/blueprints/guilds.py b/litecord/blueprints/guilds.py index 01b4e26..6755c08 100644 --- a/litecord/blueprints/guilds.py +++ b/litecord/blueprints/guilds.py @@ -96,7 +96,7 @@ async def put_guild_icon(guild_id: int, icon: str): else None) return await app.icons.put( - 'guild', guild_id, encoded, size=(128, 128)) + 'guild', guild_id, encoded, size=(128, 128), always_icon=True) @bp.route('', methods=['POST']) diff --git a/litecord/images.py b/litecord/images.py index 2d946ed..bb307a6 100644 --- a/litecord/images.py +++ b/litecord/images.py @@ -138,6 +138,14 @@ def _gen_update_sql(scope: str) -> str: """ +def _invalid(kwargs: dict): + """Send an invalid value.""" + if kwargs.get('always_icon', False): + return None + + return Icon(None, None, '') + + class IconManager: """Main icon manager.""" def __init__(self, app): @@ -205,7 +213,7 @@ class IconManager: b64_data: str, **kwargs) -> Icon: """Insert an icon.""" if b64_data is None: - return None + return _invalid(kwargs) mime, raw_data = parse_data_uri(b64_data) data_fd = BytesIO(raw_data) @@ -214,7 +222,7 @@ class IconManager: extension = _get_ext(mime) if 'bsize' in kwargs and len(raw_data) > kwargs['bsize']: - return None + return _invalid(kwargs) if 'size' in kwargs: image = Image.open(data_fd)