aboutsummaryrefslogtreecommitdiff
path: root/api/user/avatar.py
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-04-11 17:50:58 +0200
committerlonkaars <l.leblansch@gmail.com>2021-04-11 17:50:58 +0200
commit28f104de9ae9abe4b42abafbf3865ede5687996c (patch)
tree65e651f09d8fbf81380384692e45803cb4f9d61c /api/user/avatar.py
parent7b4859059b3bbabf4139ccdf3270a82c094f5d8e (diff)
dprint yapf python formatting
Diffstat (limited to 'api/user/avatar.py')
-rw-r--r--api/user/avatar.py37
1 files changed, 21 insertions, 16 deletions
diff --git a/api/user/avatar.py b/api/user/avatar.py
index b4edeed..1b5500a 100644
--- a/api/user/avatar.py
+++ b/api/user/avatar.py
@@ -10,29 +10,34 @@ default_avatar = open("database/avatars/default.png", "rb").read()
avatar = Blueprint('avatar', __name__)
-@avatar.route('/avatar', methods = ["GET"])
+
+@avatar.route('/avatar', methods=["GET"])
def get_avatar():
- token = request.cookies.get("token") or ""
- login = token_login(token) or ""
+ token = request.cookies.get("token") or ""
+ login = token_login(token) or ""
+
+ user_id = request.args.get("id") or login
+ if not user_id: return "", 400
+ if not valid_user_id(user_id): return "", 403
- user_id = request.args.get("id") or login
- if not user_id: return "", 400
- if not valid_user_id(user_id): return "", 403
+ avatar_path = f"database/avatars/{user_id}.png"
+ avatar = ""
+ if exists(avatar_path):
+ avatar = open(avatar_path, "rb").read()
+ return Response(avatar or default_avatar, 200, mimetype="image/png")
- avatar_path = f"database/avatars/{user_id}.png"
- avatar = ""
- if exists(avatar_path):
- avatar = open(avatar_path, "rb").read()
- return Response(avatar or default_avatar, 200, mimetype="image/png")
-@avatar.route('/avatar', methods = ["POST"]) #TODO: pillow image size validation (client side resize)
+@avatar.route(
+ '/avatar', methods=["POST"]
+) #TODO: pillow image size validation (client side resize)
@auth_required("user")
def update_avatar(login):
- if not request.data: return "", 400
+ if not request.data: return "", 400
- open(f"database/avatars/{login}.png", "wb").write(decode(request.data, "base64"))
+ open(f"database/avatars/{login}.png",
+ "wb").write(decode(request.data, "base64"))
- return "", 200
+ return "", 200
-dynamic_route = ["/user", avatar]
+dynamic_route = ["/user", avatar]