From 2c9dca2e8e54f6c9ef2fc8db90316fd8597e066e Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Tue, 22 Mar 2022 05:45:32 +0200 Subject: [PATCH] fds --- env | 2 +- files/routes/comments.py | 6 ++++-- files/routes/posts.py | 9 ++++++--- files/routes/settings.py | 3 ++- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/env b/env index 782d84ee7..087598fda 100644 --- a/env +++ b/env @@ -10,7 +10,7 @@ export HCAPTCHA_SECRET="blahblahblah" export YOUTUBE_KEY="blahblahblah" export PUSHER_ID="blahblahblah" export PUSHER_KEY="blahblahblah" -export IMGUR_KEY="45ec598cad8462c" +export IMGUR_KEY="blahblahblah" export SPAM_SIMILARITY_THRESHOLD="0.5" export SPAM_URL_SIMILARITY_THRESHOLD="0.1" export SPAM_SIMILAR_COUNT_THRESHOLD="10" diff --git a/files/routes/comments.py b/files/routes/comments.py index 78155a6ca..fab641398 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -324,7 +324,8 @@ def api_comment(v): elif file.content_type.startswith('video/'): file.save("video.mp4") with open("video.mp4", 'rb') as f: - req = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)], timeout=5).json()['data'] + try: req = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)], timeout=5).json()['data'] + except requests.Timeout: return {"error": "Video upload timed out, please try again!"} try: url = req['link'] except: return {"error": req['error']}, 400 if url.endswith('.'): url += 'mp4' @@ -804,7 +805,8 @@ def edit_comment(cid, v): elif file.content_type.startswith('video/'): file.save("video.mp4") with open("video.mp4", 'rb') as f: - req = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)], timeout=5).json()['data'] + try: req = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)], timeout=5).json()['data'] + except requests.Timeout: return {"error": "Video upload timed out, please try again!"} try: url = req['link'] except: return {"error": req['error']}, 400 if url.endswith('.'): url += 'mp4' diff --git a/files/routes/posts.py b/files/routes/posts.py index 93cafb7d2..b66afcdc4 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -468,7 +468,8 @@ def edit_post(pid, v): elif file.content_type.startswith('video/'): file.save("video.mp4") with open("video.mp4", 'rb') as f: - req = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)], timeout=5).json()['data'] + try: req = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)], timeout=5).json()['data'] + except requests.Timeout: return {"error": "Video upload timed out, please try again!"} try: url = req['link'] except: return {"error": req['error']}, 400 if url.endswith('.'): url += 'mp4' @@ -1024,7 +1025,8 @@ def submit_post(v, sub=None): elif file.content_type.startswith('video/'): file.save("video.mp4") with open("video.mp4", 'rb') as f: - req = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)], timeout=5).json()['data'] + try: req = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)], timeout=5).json()['data'] + except requests.Timeout: return {"error": "Video upload timed out, please try again!"} try: url = req['link'] except: return {"error": req['error']}, 400 if url.endswith('.'): url += 'mp4' @@ -1130,7 +1132,8 @@ def submit_post(v, sub=None): elif file.content_type.startswith('video/'): file.save("video.mp4") with open("video.mp4", 'rb') as f: - req = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)], timeout=5).json()['data'] + try: req = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)], timeout=5).json()['data'] + except requests.Timeout: return {"error": "Video upload timed out, please try again!"} try: url = req['link'] except: return {"error": req['error']}, 400 if url.endswith('.'): url += 'mp4' diff --git a/files/routes/settings.py b/files/routes/settings.py index 685dae022..efa69e740 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -257,7 +257,8 @@ def settings_profile_post(v): elif file.content_type.startswith('video/'): file.save("video.mp4") with open("video.mp4", 'rb') as f: - req = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)], timeout=5).json()['data'] + try: req = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)], timeout=5).json()['data'] + except requests.Timeout: return {"error": "Video upload timed out, please try again!"} try: url = req['link'] except: return {"error": req['error']}, 400 if url.endswith('.'): url += 'mp4'