Skip to content

Commit

Permalink
api: Fixed profile picture upload and self block
Browse files Browse the repository at this point in the history
  • Loading branch information
okbrandon committed Nov 15, 2024
1 parent af8719a commit 27581f0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 12 additions & 3 deletions backend/api/validators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import re
import base64
import logging

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

def validate_username(username):
if username is None:
Expand All @@ -20,12 +24,17 @@ def validate_lang(lang):
def validate_image(image):
if image is None:
return True

if not image.startswith('data:image/'):
return False

try:
decoded_image = base64.b64decode(image)
if len(decoded_image) > 1 * 1024 * 1024:
decoded_image = base64.b64decode(image.split(',')[1])

if len(decoded_image) * 3 / 4 > 1_048_576:
return False
return True
except:
except Exception as _:
return False

def validate_phone_number(phone):
Expand Down
2 changes: 2 additions & 0 deletions backend/api/views/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ def put(self, request, *args, **kwargs):

if target_user_id == "user_ai":
return Response({"error": "There's no escaping prune, nice try."}, status=status.HTTP_400_BAD_REQUEST)
if target_user_id == me.userID:
return Response({"error": "You cannot create a relationship with yourself"}, status=status.HTTP_400_BAD_REQUEST)

try:
target_user = User.objects.get(userID=target_user_id)
Expand Down

0 comments on commit 27581f0

Please sign in to comment.