aboutsummaryrefslogtreecommitdiff
path: root/api/user
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-03-14 18:55:15 +0100
committerlonkaars <l.leblansch@gmail.com>2021-03-14 18:55:15 +0100
commitc65d8f618df978919005b01142e70dc753551de0 (patch)
tree6569d6c4dfda9f2b04885d8b042e0303fb6ce394 /api/user
parent8a9060d5dcdc67d14fb5b1b6e856d9ea39ffb618 (diff)
WIP avatar upload
Diffstat (limited to 'api/user')
-rw-r--r--api/user/avatar.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/api/user/avatar.py b/api/user/avatar.py
index b0d2701..d3c86b8 100644
--- a/api/user/avatar.py
+++ b/api/user/avatar.py
@@ -3,6 +3,7 @@ from db import cursor
from auth.login_token import token_login
from user.info import valid_user_id
from os.path import exists
+from codecs import decode
default_avatar = open("database/avatars/default.png", "rb").read()
@@ -25,6 +26,15 @@ def get_avatar():
@avatar.route('/avatar', methods = ["POST"]) #TODO: pillow image size validation (client side resize)
def update_avatar():
+ token = request.cookies.get("token") or ""
+ if not token: return "", 401
+ if not request.data: return "", 400
+
+ login = token_login(token) or ""
+ if not login: return "", 403
+
+ open(f"database/avatars/{login}.png", "wb").write(decode(request.data, "base64"))
+
return "", 200
dynamic_route = ["/user", avatar]