forked from rDrama/rDrama
jdjufrw
parent
a3d090dfbd
commit
fbab4ff6da
|
@ -105,13 +105,11 @@ def upload_video(file):
|
||||||
try:
|
try:
|
||||||
r = requests.post('https://api.imgur.com/3/upload', headers=headers, files={"video": f})
|
r = requests.post('https://api.imgur.com/3/upload', headers=headers, files={"video": f})
|
||||||
|
|
||||||
print(r.text)
|
r.raise_for_status()
|
||||||
#r.raise_for_status()
|
|
||||||
|
|
||||||
resp = r.json()['data']
|
resp = r.json()['data']
|
||||||
except requests.HTTPError as e:
|
except requests.HTTPError as e:
|
||||||
if r: print(r.json())
|
raise UploadException("Invalid video. Make sure it's 1 minute long or shorter.")
|
||||||
raise UploadException(f"Status code {e.response.status_code} not in range 2**")
|
|
||||||
except Exception:
|
except Exception:
|
||||||
raise UploadException("Error, please try again later.")
|
raise UploadException("Error, please try again later.")
|
||||||
finally:
|
finally:
|
||||||
|
|
|
@ -857,7 +857,21 @@ def submit_post(v):
|
||||||
if file.content_type.startswith('image/'):
|
if file.content_type.startswith('image/'):
|
||||||
new_post.url = upload_imgur(file)
|
new_post.url = upload_imgur(file)
|
||||||
else:
|
else:
|
||||||
|
try:
|
||||||
new_post.url = upload_video(file)
|
new_post.url = upload_video(file)
|
||||||
|
except UploadException as e:
|
||||||
|
if request.headers.get("Authorization"):
|
||||||
|
return {
|
||||||
|
"error": str(e),
|
||||||
|
}, 400
|
||||||
|
else:
|
||||||
|
return render_template(
|
||||||
|
"submit.html",
|
||||||
|
v=v,
|
||||||
|
error=str(e),
|
||||||
|
title=title,
|
||||||
|
body=request.form.get("body", "")
|
||||||
|
), 400
|
||||||
|
|
||||||
g.db.add(new_post)
|
g.db.add(new_post)
|
||||||
g.db.add(new_post.submission_aux)
|
g.db.add(new_post.submission_aux)
|
||||||
|
|
Loading…
Reference in New Issue