From e3a8d0354935d8669bb67482e95bc248fa15e40c Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sat, 19 Mar 2022 16:59:56 +0200 Subject: [PATCH] cmon --- files/routes/comments.py | 10 ++++++---- files/routes/posts.py | 15 +++++++++------ files/routes/settings.py | 5 +++-- files/routes/static.py | 5 +++-- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/files/routes/comments.py b/files/routes/comments.py index 0d064695f..db844cd54 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -323,8 +323,9 @@ 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)], timeout=5).json()['data']['link'] - except: return {"error": "Imgur error"}, 400 + 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: url = req['link'] + except: return {"error": req['error']}, 400 if url.endswith('.'): url += 'mp4' body += f"\n\n{url}" else: return {"error": "Image/Video files only"}, 400 @@ -802,8 +803,9 @@ 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)], timeout=5).json()['data']['link'] - except: return {"error": "Imgur error"}, 400 + 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: url = req['link'] + except: return {"error": req['error']}, 400 if url.endswith('.'): url += 'mp4' body += f"\n\n{url}" else: return {"error": "Image/Video files only"}, 400 diff --git a/files/routes/posts.py b/files/routes/posts.py index b4d991ac4..e6cbcc77d 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -468,8 +468,9 @@ 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)], timeout=5).json()['data']['link'] - except: return {"error": "Imgur error"}, 400 + 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: url = req['link'] + except: return {"error": req['error']}, 400 if url.endswith('.'): url += 'mp4' body += f"\n\n{url}" else: return {"error": "Image/Video files only"}, 400 @@ -1017,8 +1018,9 @@ 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)], timeout=5).json()['data']['link'] - except: return error( "Imgur error") + 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: url = req['link'] + except: return {"error": req['error']}, 400 if url.endswith('.'): url += 'mp4' body += f"\n\n{url}" else: @@ -1122,8 +1124,9 @@ 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)], timeout=5).json()['data']['link'] - except: return error( "Imgur error") + 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: url = req['link'] + except: return {"error": req['error']}, 400 if url.endswith('.'): url += 'mp4' post.url = url else: diff --git a/files/routes/settings.py b/files/routes/settings.py index df5c8ebbc..611602a3c 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -257,8 +257,9 @@ 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)], timeout=5).json()['data']['link'] - except: return {"error": "Imgur error"}, 400 + 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: url = req['link'] + except: return {"error": req['error']}, 400 if url.endswith('.'): url += 'mp4' bio += f"\n\n{url}" else: diff --git a/files/routes/static.py b/files/routes/static.py index c52d1eb0a..91fa9efb8 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -305,8 +305,9 @@ 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)], timeout=5).json()['data']['link'] - except: return {"error": "Imgur error"}, 400 + 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: url = req['link'] + except: return {"error": req['error']}, 400 if url.endswith('.'): url += 'mp4' body_html += f"

{url}

" else: return {"error": "Image/Video files only"}, 400