images: add bytelimit

- guild.emoji: add 128x128 limit and 128kb limit
 - types: add KILOBYTES
This commit is contained in:
Luna Mendes 2018-11-17 18:19:47 -03:00
parent d3bc826504
commit d9a1923e54
3 changed files with 13 additions and 1 deletions

View File

@ -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(
"""

View File

@ -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)

View File

@ -1,3 +1,5 @@
KILOBYTES = 1024
class Color:
"""Custom color class"""