diff --git a/files/routes/admin.py b/files/routes/admin.py index 2b251b34d..57a6bceb8 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -414,7 +414,7 @@ def admin_home(v): with open('disable_signups', 'r') as f: x = f.read() if CF_ZONE == '3435tdfsdudebussylmaoxxt43': response = 'high' - else: response = requests.get(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/settings/security_level', headers=CF_HEADERS).json()['result']['value'] + else: response = requests.get(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/settings/security_level', headers=CF_HEADERS, timeout=5).json()['result']['value'] x2 = response == 'under_attack' @@ -450,7 +450,7 @@ def disable_signups(v): @admin_level_required(3) def purge_cache(v): cache.clear() - response = str(requests.post(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/purge_cache', headers=CF_HEADERS, data='{"purge_everything":true}')) + response = str(requests.post(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/purge_cache', headers=CF_HEADERS, data='{"purge_everything":true}', timeout=5)) ma = ModAction( kind="purge_cache", @@ -465,7 +465,7 @@ def purge_cache(v): @app.post("/admin/under_attack") @admin_level_required(3) def under_attack(v): - response = requests.get(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/settings/security_level', headers=CF_HEADERS).json()['result']['value'] + response = requests.get(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/settings/security_level', headers=CF_HEADERS, timeout=5).json()['result']['value'] if response == 'under_attack': ma = ModAction( @@ -475,7 +475,7 @@ def under_attack(v): g.db.add(ma) g.db.commit() - response = str(requests.patch(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/settings/security_level', headers=CF_HEADERS, data='{"value":"medium"}')) + response = str(requests.patch(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/settings/security_level', headers=CF_HEADERS, data='{"value":"medium"}', timeout=5)) if response == "": return {"message": "Under attack mode disabled!"} return {"error": "Failed to disable under attack mode."} else: @@ -486,7 +486,7 @@ def under_attack(v): g.db.add(ma) g.db.commit() - response = str(requests.patch(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/settings/security_level', headers=CF_HEADERS, data='{"value":"under_attack"}')) + response = str(requests.patch(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/settings/security_level', headers=CF_HEADERS, data='{"value":"under_attack"}', timeout=5)) if response == "": return {"message": "Under attack mode enabled!"} return {"error": "Failed to enable under attack mode."} @@ -1151,7 +1151,7 @@ def ban_post(post_id, v): v.coins += 1 g.db.add(v) - requests.post(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/purge_cache', headers=CF_HEADERS, json={'files': [f"{SITE_FULL}/logged_out/"]}) + requests.post(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/purge_cache', headers=CF_HEADERS, json={'files': [f"{SITE_FULL}/logged_out/"]}, timeout=5) g.db.commit() diff --git a/files/routes/comments.py b/files/routes/comments.py index 323b9f2b6..9f79efc26 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -259,7 +259,7 @@ def api_comment(v): filename = f'files/assets/images/badges/{badge.id}.webp' copyfile(oldname, filename) process_image(filename, 200) - requests.post(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/purge_cache', headers=CF_HEADERS, data={'files': [f"https://{request.host}/static/assets/images/badges/{badge.id}.webp"]}) + requests.post(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/purge_cache', headers=CF_HEADERS, data={'files': [f"https://{request.host}/static/assets/images/badges/{badge.id}.webp"]}, timeout=5) except Exception as e: return {"error": str(e)}, 400 elif v.admin_level > 2 and parent_post.id == 37838: @@ -278,7 +278,7 @@ def api_comment(v): filename = f'files/assets/images/emojis/{name}.webp' copyfile(oldname, filename) process_image(filename, 200) - requests.post(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/purge_cache', headers=CF_HEADERS, data={'files': [f"https://{request.host}/static/assets/images/emojis/{name}.webp"]}) + requests.post(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/purge_cache', headers=CF_HEADERS, data={'files': [f"https://{request.host}/static/assets/images/emojis/{name}.webp"]}, timeout=5) cache.delete_memoized(marsey_list) except Exception as e: return {"error": str(e)}, 400 @@ -286,7 +286,7 @@ def api_comment(v): elif file.content_type.startswith('video/'): file.save("video.mp4") with open("video.mp4", 'rb') as f: - try: url = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)]).json()['data']['link'] + try: url = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)], timeout=5).json()['data']['link'] except: return {"error": "Imgur error"}, 400 if url.endswith('.'): url += 'mp4' body += f"\n\n{url}" @@ -815,7 +815,7 @@ def edit_comment(cid, v): elif file.content_type.startswith('video/'): file.save("video.mp4") with open("video.mp4", 'rb') as f: - try: url = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)]).json()['data']['link'] + try: url = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)], timeout=5).json()['data']['link'] except: return {"error": "Imgur error"}, 400 if url.endswith('.'): url += 'mp4' body += f"\n\n{url}" diff --git a/files/routes/posts.py b/files/routes/posts.py index 912320541..d44a7d669 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -490,7 +490,7 @@ def edit_post(pid, v): elif file.content_type.startswith('video/'): file.save("video.mp4") with open("video.mp4", 'rb') as f: - try: url = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)]).json()['data']['link'] + try: url = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)], timeout=5).json()['data']['link'] except: return {"error": "Imgur error"}, 400 if url.endswith('.'): url += 'mp4' body += f"\n\n{url}" @@ -761,7 +761,7 @@ def thumbnail_thread(pid): word = random.choice(('rdrama','marsey')) try: - data = requests.get(f'https://api.pushshift.io/reddit/{t}/search?html_decode=true&q={word}&size=1') + data = requests.get(f'https://api.pushshift.io/reddit/{t}/search?html_decode=true&q={word}&size=1', timeout=5) if str(data) == "": data = data.json()["data"] else: break except: break @@ -789,7 +789,7 @@ def thumbnail_thread(pid): k,val = random.choice(tuple(REDDIT_NOTIFS.items())) - for i in requests.get(f'https://api.pushshift.io/reddit/{t}/search?html_decode=true&q={k}&size=1').json()["data"]: + for i in requests.get(f'https://api.pushshift.io/reddit/{t}/search?html_decode=true&q={k}&size=1', timeout=5).json()["data"]: body_html = sanitize(f'New mention of you: https://old.reddit.com{i["permalink"]}?context=89', noimages=True) existing_comment = db.query(Comment.id).filter_by(author_id=NOTIFICATIONS_ID, parent_submission=None, distinguish_level=6, body_html=body_html).one_or_none() @@ -812,7 +812,7 @@ def thumbnail_thread(pid): for t in ("submission","comment"): try: - data = requests.get(f'https://api.pushshift.io/reddit/{t}/search?html_decode=true&q=pcmemes.net&size=1').json()["data"] + data = requests.get(f'https://api.pushshift.io/reddit/{t}/search?html_decode=true&q=pcmemes.net&size=1', timeout=5).json()["data"] if str(data) == "": data = data.json()["data"] else: break except: break @@ -943,7 +943,7 @@ def submit_post(v, sub=None): reason = f"Remove the {domain_obj.domain} link from your post and try again. {domain_obj.reason}" return error(reason) elif "twitter.com" == domain: - try: embed = requests.get("https://publish.twitter.com/oembed", timeout=5, params={"url":url, "omit_script":"t"}).json()["html"] + try: embed = requests.get("https://publish.twitter.com/oembed", params={"url":url, "omit_script":"t"}, timeout=5).json()["html"] except: embed = None elif url.startswith('https://youtube.com/watch?v='): url = unquote(url).replace('?t', '&t') @@ -1071,7 +1071,7 @@ def submit_post(v, sub=None): elif file.content_type.startswith('video/'): file.save("video.mp4") with open("video.mp4", 'rb') as f: - try: url = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)]).json()['data']['link'] + try: url = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)], timeout=5).json()['data']['link'] except: return error( "Imgur error") if url.endswith('.'): url += 'mp4' body += f"\n\n{url}" @@ -1199,7 +1199,7 @@ def submit_post(v, sub=None): elif file.content_type.startswith('video/'): file.save("video.mp4") with open("video.mp4", 'rb') as f: - try: url = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)]).json()['data']['link'] + try: url = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)], timeout=5).json()['data']['link'] except: return error( "Imgur error") if url.endswith('.'): url += 'mp4' post.url = url diff --git a/files/routes/settings.py b/files/routes/settings.py index 8991bc9c1..b99eec2af 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -264,7 +264,7 @@ def settings_profile_post(v): elif file.content_type.startswith('video/'): file.save("video.mp4") with open("video.mp4", 'rb') as f: - try: url = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)]).json()['data']['link'] + try: url = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)], timeout=5).json()['data']['link'] except: return {"error": "Imgur error"}, 400 if url.endswith('.'): url += 'mp4' bio += f"\n\n{url}" @@ -458,7 +458,7 @@ def gumroad(v): return {"error": f"You must have a verified email to verify {patron} status and claim your rewards"}, 400 data = {'access_token': GUMROAD_TOKEN, 'email': v.email} - response = requests.get('https://api.gumroad.com/v2/sales', data=data).json()["sales"] + response = requests.get('https://api.gumroad.com/v2/sales', data=data, timeout=5).json()["sales"] if len(response) == 0: return {"error": "Email not found"}, 404 diff --git a/files/routes/static.py b/files/routes/static.py index 8f4b916a2..1a7591376 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -298,7 +298,7 @@ def submit_contact(v): elif file.content_type.startswith('video/'): file.save("video.mp4") with open("video.mp4", 'rb') as f: - try: url = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)]).json()['data']['link'] + try: url = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)], timeout=5).json()['data']['link'] except: return {"error": "Imgur error"}, 400 if url.endswith('.'): url += 'mp4' body_html += f"

{url}

" diff --git a/files/templates/comments.html b/files/templates/comments.html index 3e6f1de4e..132bcc7c9 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -487,8 +487,8 @@ - {% elif c.body %} - + {% elif v and c.body %} + {% endif %} {% endif %} @@ -691,8 +691,7 @@ Unmark +18 {% else %} {% if c.body %} - View source - Hide source + View source {% endif %} {% if not c.ghost %} @@ -887,7 +886,7 @@ {% include "expanded_image_modal.html" %} - + - {% endif %} diff --git a/files/templates/header.html b/files/templates/header.html index e28b10e85..eb8867757 100644 --- a/files/templates/header.html +++ b/files/templates/header.html @@ -256,7 +256,7 @@ - + {% if v and not err %}
{{v.formkey}}
diff --git a/files/templates/submission.html b/files/templates/submission.html index 314dc9f27..ce2a9949b 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -592,8 +592,7 @@ {% else %} {% if p.body %} - - + {% endif %} {% if not p.ghost %} @@ -888,8 +887,8 @@ Edit {% endif %} - {% if not (v and v.id == p.author_id) and p.body %} - View source + {% if v and v.id != p.author_id and p.body %} + View source {% endif %} {% if v and v.id==p.author_id %} @@ -1088,7 +1087,7 @@ {% if p.body and not (v and v.id == p.author_id) %} -
{{p.body.strip()}}
+ {% endif %}