diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | api/user/avatar.py | 31 | ||||
-rw-r--r-- | database/avatars/default.png | bin | 0 -> 3135 bytes |
3 files changed, 33 insertions, 0 deletions
@@ -18,6 +18,8 @@ ENV/ database/*.db database/*.db-journal database/*.sqlext +database/avatars/* +!database/avatars/default.png # node / ts *.js diff --git a/api/user/avatar.py b/api/user/avatar.py new file mode 100644 index 0000000..b0d2701 --- /dev/null +++ b/api/user/avatar.py @@ -0,0 +1,31 @@ +from flask import Blueprint, request, Response +from db import cursor +from auth.login_token import token_login +from user.info import valid_user_id +from os.path import exists + +default_avatar = open("database/avatars/default.png", "rb").read() + +avatar = Blueprint('avatar', __name__) + +@avatar.route('/avatar', methods = ["GET"]) +def get_avatar(): + 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 + + 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) +def update_avatar(): + return "", 200 + +dynamic_route = ["/user", avatar] + diff --git a/database/avatars/default.png b/database/avatars/default.png Binary files differnew file mode 100644 index 0000000..ae6313e --- /dev/null +++ b/database/avatars/default.png |