From dcd93cf03e6777beefdc9de841e3ed3403d4855d Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Mon, 27 Sep 2021 22:26:34 +0200 Subject: [PATCH] g --- files/routes/awards.py | 2 +- files/routes/posts.py | 21 +++++---------------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/files/routes/awards.py b/files/routes/awards.py index 8b0c41bf57..51b6f4fe20 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -244,7 +244,7 @@ def award_post(pid, v): g.db.add(post.author) g.db.commit() - if request.referrer: return redirect(request.referrer) + if len(request.referrer) > 1: return redirect(request.referrer) else: return redirect("/") diff --git a/files/routes/posts.py b/files/routes/posts.py index 9348c02878..6630d7d5ca 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -370,29 +370,18 @@ def edit_post(pid, v): def get_post_title(v): url = request.values.get("url", None) - if not url: - return abort(400) + if not url: return abort(400) #mimic chrome browser agent headers = {"User-Agent": f"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.72 Safari/537.36"} - try: - x = requests.get(url, headers=headers) - except BaseException: - return {"error": "Could not reach page"}, 400 - - - if not x.status_code == 200: - return {"error": f"Page returned {x.status_code}"}, x.status_code + try: x = requests.get(url, headers=headers) + except BaseException: return {"error": "Could not reach page"}, 400 + if not x.status_code == 200: return {"error": f"Page returned {x.status_code}"}, x.status_code try: soup = BeautifulSoup(x.content, 'html.parser') - - data = {"url": url, - "title": soup.find('title').string - } - - return data + return {"url": url, "title": soup.find('title').string} except BaseException: return {"error": f"Could not find a title"}, 400