From a9cf6986f8a084e439a7ee2a20f2dd3091188a9e Mon Sep 17 00:00:00 2001 From: Nataliia Volkova Date: Thu, 5 Feb 2026 15:30:04 +0000 Subject: [PATCH] validation length bloop on backend --- backend/endpoints.py | 12 ++++++++++-- backend/populate.py | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/backend/endpoints.py b/backend/endpoints.py index 0e177a0..bb2e72c 100644 --- a/backend/endpoints.py +++ b/backend/endpoints.py @@ -155,10 +155,18 @@ def send_bloom(): type_check_error = verify_request_fields({"content": str}) if type_check_error is not None: return type_check_error - + + content = request.json["content"] + + if len(content) > 280: + return { + "success": False, + "error": "Bloom content can't be more than 280 characters" + }, 400 + user = get_current_user() - blooms.add_bloom(sender=user, content=request.json["content"]) + blooms.add_bloom(sender=user, content=content) return jsonify( { diff --git a/backend/populate.py b/backend/populate.py index 414218b..84a643a 100644 --- a/backend/populate.py +++ b/backend/populate.py @@ -38,6 +38,25 @@ def send_bloom(access_token: str, text: str) -> None: post("/bloom", data={"content": text}, access_token=access_token) +MAX_BLOOM_LENGTH = 280 + +def send_long_bloom(access_token: str, text: str) -> None: + text = " ".join(text.split()) + + while text: + chunk = text[:MAX_BLOOM_LENGTH] + + if len(text) > MAX_BLOOM_LENGTH: + cut = chunk.rfind(" ") + if cut > 0: + chunk = chunk[:cut] + + send_bloom(access_token, chunk) + # print(len(chunk), repr(chunk)) + + text = text[len(chunk):].strip() + + def follow(*, follower_access_token: str, follow_username: str) -> None: post( "/follow",