This commit is contained in:
Aevann1 2021-11-30 20:15:33 +02:00
parent 2637de952b
commit 0750035557
2 changed files with 24 additions and 5 deletions

View file

@ -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)})')