From d9a1923e54e29f7006ef9e85558a81dd51057c3d Mon Sep 17 00:00:00 2001 From: Luna Mendes Date: Sat, 17 Nov 2018 18:19:47 -0300 Subject: [PATCH] images: add bytelimit - guild.emoji: add 128x128 limit and 128kb limit - types: add KILOBYTES --- litecord/blueprints/guild/emoji.py | 8 +++++++- litecord/images.py | 4 ++++ litecord/types.py | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/litecord/blueprints/guild/emoji.py b/litecord/blueprints/guild/emoji.py index 4db49c4..e4bf5c5 100644 --- a/litecord/blueprints/guild/emoji.py +++ b/litecord/blueprints/guild/emoji.py @@ -4,6 +4,7 @@ from litecord.auth import token_check from litecord.blueprints.checks import guild_check, guild_perm_check from litecord.schemas import validate, NEW_EMOJI, PATCH_EMOJI from litecord.snowflake import get_snowflake +from litecord.types import KILOBYTES bp = Blueprint('guild.emoji', __name__) @@ -45,7 +46,12 @@ async def _put_emoji(guild_id): emoji_id = get_snowflake() - icon = await app.icons.put('emoji', emoji_id, j['image']) + icon = await app.icons.put( + 'emoji', emoji_id, j['image'], + + # limits to emojis + bsize=128 * KILOBYTES, size=(128, 128) + ) await app.db.execute( """ diff --git a/litecord/images.py b/litecord/images.py index c33979d..64917f9 100644 --- a/litecord/images.py +++ b/litecord/images.py @@ -213,6 +213,10 @@ class IconManager: # get an extension for the given data uri extension = _get_ext(mime) + if 'bsize' in kwargs: + if len(raw_data) > kwargs['bsize']: + return Icon(None, None, '') + if 'size' in kwargs: image = Image.open(data_fd) diff --git a/litecord/types.py b/litecord/types.py index 4fddfff..ed2b366 100644 --- a/litecord/types.py +++ b/litecord/types.py @@ -1,3 +1,5 @@ +KILOBYTES = 1024 + class Color: """Custom color class"""