fd
This commit is contained in:
parent
d595242dca
commit
22461f5434
1 changed files with 72 additions and 72 deletions
|
@ -533,40 +533,40 @@ def filter_title(title):
|
||||||
IMGUR_KEY = environ.get("IMGUR_KEY", "").strip()
|
IMGUR_KEY = environ.get("IMGUR_KEY", "").strip()
|
||||||
|
|
||||||
|
|
||||||
def check_processing_thread(v, post, link, db):
|
# def check_processing_thread(v, post, link, db):
|
||||||
|
|
||||||
image_id = link.split('/')[-1].rstrip('.mp4')
|
# image_id = link.split('/')[-1].rstrip('.mp4')
|
||||||
headers = {"Authorization": f"Client-ID {IMGUR_KEY}"}
|
# headers = {"Authorization": f"Client-ID {IMGUR_KEY}"}
|
||||||
|
|
||||||
while True:
|
# while True:
|
||||||
# break on error to prevent zombie threads
|
# # break on error to prevent zombie threads
|
||||||
try:
|
# try:
|
||||||
time.sleep(15)
|
# time.sleep(15)
|
||||||
|
|
||||||
req = requests.get(f"https://api.imgur.com/3/image/{image_id}", headers=headers)
|
# req = requests.get(f"https://api.imgur.com/3/image/{image_id}", headers=headers)
|
||||||
|
|
||||||
status = req.json()['data']['processing']['status']
|
# status = req.json()['data']['processing']['status']
|
||||||
if status == 'completed':
|
# if status == 'completed':
|
||||||
post.processing = False
|
# post.processing = False
|
||||||
db.add(post)
|
# db.add(post)
|
||||||
|
|
||||||
send_notification(
|
# send_notification(
|
||||||
NOTIFICATIONS_ACCOUNT,
|
# NOTIFICATIONS_ACCOUNT,
|
||||||
v,
|
# v,
|
||||||
f"Your video has finished processing and your [post](/post/{post.id}) is now live.",
|
# f"Your video has finished processing and your [post](/post/{post.id}) is now live.",
|
||||||
db=db
|
# db=db
|
||||||
)
|
# )
|
||||||
|
|
||||||
db.commit()
|
# db.commit()
|
||||||
break
|
# break
|
||||||
# just in case
|
# # just in case
|
||||||
elif status == 'failed':
|
# elif status == 'failed':
|
||||||
print(f"video upload for post {post.id} failed")
|
# print(f"video upload for post {post.id} failed")
|
||||||
break
|
# break
|
||||||
except Exception as e:
|
# except Exception as e:
|
||||||
traceback.print_exc()
|
# traceback.print_exc()
|
||||||
print("retard. aborting thread")
|
# print("retard. aborting thread")
|
||||||
break
|
# break
|
||||||
|
|
||||||
|
|
||||||
@app.post("/submit")
|
@app.post("/submit")
|
||||||
|
@ -894,53 +894,53 @@ def submit_post(v):
|
||||||
if 'pcm' in request.host:
|
if 'pcm' in request.host:
|
||||||
if file.content_type.startswith('image/'):
|
if file.content_type.startswith('image/'):
|
||||||
new_post.url = upload_ibb(file)
|
new_post.url = upload_ibb(file)
|
||||||
else:
|
# else:
|
||||||
try:
|
# try:
|
||||||
post_url = upload_video(file)
|
# post_url = upload_video(file)
|
||||||
if not post_url.endswith('.mp4'):
|
# if not post_url.endswith('.mp4'):
|
||||||
post_url += 'mp4'
|
# post_url += 'mp4'
|
||||||
new_post.url = post_url
|
# new_post.url = post_url
|
||||||
new_post.processing = True
|
# new_post.processing = True
|
||||||
gevent.spawn(check_processing_thread, v.id, new_post, post_url, g.db)
|
# gevent.spawn(check_processing_thread, v.id, new_post, post_url, g.db)
|
||||||
except UploadException as e:
|
# except UploadException as e:
|
||||||
if request.headers.get("Authorization"):
|
# if request.headers.get("Authorization"):
|
||||||
return {
|
# return {
|
||||||
"error": str(e),
|
# "error": str(e),
|
||||||
}, 400
|
# }, 400
|
||||||
else:
|
# else:
|
||||||
return render_template(
|
# return render_template(
|
||||||
"submit.html",
|
# "submit.html",
|
||||||
v=v,
|
# v=v,
|
||||||
error=str(e),
|
# error=str(e),
|
||||||
title=title,
|
# title=title,
|
||||||
body=request.form.get("body", "")
|
# body=request.form.get("body", "")
|
||||||
), 400
|
# ), 400
|
||||||
else:
|
else:
|
||||||
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:
|
# try:
|
||||||
post_url = upload_video(file)
|
# post_url = upload_video(file)
|
||||||
# shit to make webm work
|
# # shit to make webm work
|
||||||
if not post_url.endswith('.mp4'):
|
# if not post_url.endswith('.mp4'):
|
||||||
post_url += 'mp4'
|
# post_url += 'mp4'
|
||||||
# print(post_url)
|
# # print(post_url)
|
||||||
new_post.url = post_url
|
# new_post.url = post_url
|
||||||
new_post.processing = True
|
# new_post.processing = True
|
||||||
gevent.spawn(check_processing_thread, v.id, new_post, post_url, g.db)
|
# gevent.spawn(check_processing_thread, v.id, new_post, post_url, g.db)
|
||||||
except UploadException as e:
|
# except UploadException as e:
|
||||||
if request.headers.get("Authorization"):
|
# if request.headers.get("Authorization"):
|
||||||
return {
|
# return {
|
||||||
"error": str(e),
|
# "error": str(e),
|
||||||
}, 400
|
# }, 400
|
||||||
else:
|
# else:
|
||||||
return render_template(
|
# return render_template(
|
||||||
"submit.html",
|
# "submit.html",
|
||||||
v=v,
|
# v=v,
|
||||||
error=str(e),
|
# error=str(e),
|
||||||
title=title,
|
# title=title,
|
||||||
body=request.form.get("body", "")
|
# body=request.form.get("body", "")
|
||||||
), 400
|
# ), 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…
Add table
Add a link
Reference in a new issue