From 5708d4d64e2748a64ed325d3d752e99f76373ce5 Mon Sep 17 00:00:00 2001 From: Aevann Date: Thu, 9 Mar 2023 07:52:20 +0200 Subject: [PATCH] dont wipe saved shit in /submit unless post is successful --- files/assets/js/submit.js | 23 +++++++++++++---------- files/routes/posts.py | 6 +++--- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/files/assets/js/submit.js b/files/assets/js/submit.js index fdc565a86..64365a895 100644 --- a/files/assets/js/submit.js +++ b/files/assets/js/submit.js @@ -180,17 +180,20 @@ function submit(form) { upload_prog.classList.add("d-none") if (xhr.status >= 200 && xhr.status < 300) { - const post_id = JSON.parse(xhr.response)['post_id']; + const res = JSON.parse(xhr.response) + const post_id = res['post_id']; - localStorage.setItem("post-title", "") - localStorage.setItem("post-text", "") - localStorage.setItem("post-url", "") - localStorage.setItem("sub", "") - localStorage.setItem("post-notify", true) - localStorage.setItem("post-new", false) - localStorage.setItem("post-nsfw", false) - localStorage.setItem("post-private", false) - localStorage.setItem("post-ghost", false) + if (res['success']) { + localStorage.setItem("post-title", "") + localStorage.setItem("post-text", "") + localStorage.setItem("post-url", "") + localStorage.setItem("sub", "") + localStorage.setItem("post-notify", true) + localStorage.setItem("post-new", false) + localStorage.setItem("post-nsfw", false) + localStorage.setItem("post-private", false) + localStorage.setItem("post-ghost", false) + } location.href = "/post/" + post_id } else { diff --git a/files/routes/posts.py b/files/routes/posts.py index 8f19c7f8d..51435a1ed 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -513,7 +513,7 @@ def submit_post(v:User, sub=None): Submission.is_banned == False ).first() if repost and FEATURES['REPOST_DETECTION'] and not v.admin_level >= PERMS['POST_BYPASS_REPOST_CHECKING']: - return {"post_id": repost.id} + return {"post_id": repost.id, "success": False} y = tldextract.extract(url).registered_domain + parsed_url.path y = y.lower() @@ -547,7 +547,7 @@ def submit_post(v:User, sub=None): Submission.body == body ).one_or_none() if dup: - return {"post_id": dup.id} + return {"post_id": dup.id, "success": False} if not execute_antispam_submission_check(title, v, url): return redirect("/notifications") @@ -704,7 +704,7 @@ def submit_post(v:User, sub=None): if v.client: return p.json(g.db) else: p.voted = 1 - return {"post_id": p.id} + return {"post_id": p.id, "success": True} @app.post("/delete_post/") @limiter.limit('1/second', scope=rpath)