forked from rDrama/rDrama
1
0
Fork 0
master
Aevann1 2021-09-13 13:27:13 +02:00
parent b18a1115ac
commit c6f3698e0f
1 changed files with 125 additions and 121 deletions

View File

@ -234,14 +234,18 @@ def post_id(pid, anything=None, v=None):
@validate_formkey
def edit_post(pid, v):
title = request.form.get("title")
p = get_post(pid)
if not p.author_id == v.id:
abort(403)
if not p.author_id == v.id: abort(403)
title = request.form.get("title")
body = request.form.get("body", "")
if title != p.title:
p.title = title
p.title_html = filter_title(title)
if body != p.body:
for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|PNG|JPG|JPEG|GIF|9999))', body, re.MULTILINE): body = body.replace(i.group(1), f'![]({i.group(1)})')
with CustomRenderer() as renderer: body_md = renderer.render(mistletoe.Document(body))
body_html = sanitize(body_md)
@ -289,14 +293,8 @@ def edit_post(pid, v):
return {"error": f"The link `{badlink.link}` is not allowed. Reason: {badlink.reason}"}
p.body = body
p.body_html = body_html
p.title = title
p.title_html = filter_title(title)
if int(time.time()) - p.created_utc > 60 * 3: p.edited_utc = int(time.time())
g.db.add(p)
if "rdrama" in request.host and "ivermectin" in body_html.lower():
@ -371,6 +369,7 @@ def edit_post(pid, v):
n = Notification(comment_id=c_jannied.id, user_id=v.id)
g.db.add(n)
notify_users = set()
soup = BeautifulSoup(body_html, features="html.parser")
@ -381,6 +380,11 @@ def edit_post(pid, v):
for x in notify_users: send_notification(NOTIFICATIONS_ACCOUNT, x, f"@{v.username} has mentioned you: https://{site}{p.permalink}")
if title != p.title or body != p.body:
if int(time.time()) - p.created_utc > 60 * 3: p.edited_utc = int(time.time())
g.db.add(p)
return redirect(p.permalink)
@app.get("/submit/title")