From 8ea52ba95ca29c214ba516d48025b950bbdfe84d Mon Sep 17 00:00:00 2001 From: justcool393 Date: Sun, 9 Oct 2022 00:20:28 -0700 Subject: [PATCH] constantify comment body length limit and transfer limit --- files/helpers/const.py | 2 ++ files/routes/comments.py | 2 +- files/routes/users.py | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/files/helpers/const.py b/files/helpers/const.py index 24735dc68..604c94b3e 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -265,6 +265,8 @@ POST_TITLE_LENGTH_LIMIT = 500 # do not make larger than 500 without altering the POST_TITLE_HTML_LENGTH_LIMIT = 1500 # do not make larger than 1500 without altering the table POST_BODY_LENGTH_LIMIT = 20000 # do not make larger than 20000 without altering the table POST_BODY_HTML_LENGTH_LIMIT = 40000 # do not make larger than 40000 without altering the table +COMMENT_BODY_LENGTH_LIMIT = 10000 # do not make larger than 10000 characters without altering the table +TRANSFER_MESSAGE_LENGTH_LIMIT = 200 # do not make larger than 10000 characters (comment limit) without altering the table LOGGEDIN_ACTIVE_TIME = 15 * 60 PFP_DEFAULT_MARSEY = True diff --git a/files/routes/comments.py b/files/routes/comments.py index 4c9928afa..773d3d86b 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -169,7 +169,7 @@ def comment(v): body = request.values.get("body", "").strip().replace('‎','') - body = body.replace('\r\n', '\n')[:10000] + body = body.replace('\r\n', '\n')[:COMMENT_BODY_LENGTH_LIMIT] if parent_post.id not in ADMIGGERS: if v.longpost and (len(body) < 280 or ' [](' in body or body.startswith('[](')): diff --git a/files/routes/users.py b/files/routes/users.py index ba7bd703e..a8cd94fb5 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -275,7 +275,7 @@ def transfer_coins(v, username): notif_text = f":marseycapitalistmanlet: @{v.username} has gifted you {amount-tax} coins!" if reason: - if len(reason) > 200: return {"error": "Reason is too long, max 200 characters"},400 + if len(reason) > TRANSFER_MESSAGE_LENGTH_LIMIT: return {"error": f"Reason is too long, max {TRANSFER_MESSAGE_LENGTH_LIMIT} characters"},400 notif_text += f"\n\n> {reason}" log_message += f"\n\n> {reason}" @@ -566,7 +566,7 @@ def message2(v, username): @auth_required def messagereply(v): body = request.values.get("body", "").strip().replace('‎','') - body = body.replace('\r\n', '\n')[:10000] + body = body.replace('\r\n', '\n')[:COMMENT_BODY_LENGTH_LIMIT] if not body and not request.files.get("file"): return {"error": "Message is empty!"}, 400