diff --git a/env b/env index 782d84ee7f..087598fda9 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 78155a6ca9..fab6413982 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 93cafb7d2c..b66afcdc49 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 685dae0223..efa69e7403 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'