forked from rDrama/rDrama
1
0
Fork 0
Aevann1 2021-09-27 22:26:34 +02:00
parent b66b7ea56f
commit dcd93cf03e
2 changed files with 6 additions and 17 deletions

View File

@ -244,7 +244,7 @@ def award_post(pid, v):
g.db.add(post.author) g.db.add(post.author)
g.db.commit() g.db.commit()
if request.referrer: return redirect(request.referrer) if len(request.referrer) > 1: return redirect(request.referrer)
else: return redirect("/") else: return redirect("/")

View File

@ -370,29 +370,18 @@ def edit_post(pid, v):
def get_post_title(v): def get_post_title(v):
url = request.values.get("url", None) url = request.values.get("url", None)
if not url: if not url: return abort(400)
return abort(400)
#mimic chrome browser agent #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"} 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: try: x = requests.get(url, headers=headers)
x = requests.get(url, headers=headers) except BaseException: return {"error": "Could not reach page"}, 400
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
if not x.status_code == 200: return {"error": f"Page returned {x.status_code}"}, x.status_code
try: try:
soup = BeautifulSoup(x.content, 'html.parser') soup = BeautifulSoup(x.content, 'html.parser')
return {"url": url, "title": soup.find('title').string}
data = {"url": url,
"title": soup.find('title').string
}
return data
except BaseException: except BaseException:
return {"error": f"Could not find a title"}, 400 return {"error": f"Could not find a title"}, 400