From b2cd037ac626d828556d5c4e505758dac6a7ba0e Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Tue, 30 Nov 2021 20:15:33 +0200 Subject: [PATCH] sfdsfd --- files/routes/posts.py | 13 +++++++++++++ files/templates/submission.html | 16 +++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/files/routes/posts.py b/files/routes/posts.py index efda7c19a..24cc88b34 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -221,6 +221,9 @@ def post_id(pid, anything=None, v=None): @auth_required @validate_formkey def edit_post(pid, v): + if v and v.patron: + if request.content_length > 8 * 1024 * 1024: return "Max file size is 8 MB.", 413 + elif request.content_length > 4 * 1024 * 1024: return "Max file size is 4 MB.", 413 p = get_post(pid) @@ -264,6 +267,16 @@ def edit_post(pid, v): p.title = title p.title_html = title_html + if request.files.get("file") and request.headers.get("cf-ipcountry") != "T1": + file=request.files["file"] + if not file.content_type.startswith('image/'): return {"error": "That wasn't an image!"}, 400 + + name = f'/images/{int(time.time())}{secrets.token_urlsafe(2)}.webp' + file.save(name) + url = request.host_url[:-1] + process_image(name) + + body += f"\n\n![]({url})" + if body != p.body: for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999))', body, re.MULTILINE): if "wikipedia" not in i.group(1): body = body.replace(i.group(1), f'![]({i.group(1)})') diff --git a/files/templates/submission.html b/files/templates/submission.html index c60150e0a..b1bda38b6 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -483,11 +483,17 @@
- - - - - + + + + + + + +