This commit is contained in:
Aevann1 2021-10-01 08:26:59 +02:00
parent 43e04814c7
commit 5884d71a5c
9 changed files with 8 additions and 96 deletions

View file

@ -384,43 +384,6 @@ def filter_title(title):
return title
IMGUR_KEY = environ.get("IMGUR_KEY", "").strip()
def check_processing_thread(v, post, link):
image_id = link.split('/')[-1].rstrip('.mp4')
headers = {"Authorization": f"Client-ID {IMGUR_KEY}"}
while True:
# break on error to prevent zombie threads
try:
time.sleep(15)
req = requests.get(f"https://api.imgur.com/3/image/{image_id}", headers=headers)
status = req.json()['data']['processing']['status']
if status == 'completed':
post.processing = False
g.db.add(post)
send_notification(
NOTIFICATIONS_ACCOUNT,
v,
f"Your video has finished processing and your [post](/post/{post.id}) is now live."
)
g.db.commit()
break
# just in case
elif status == 'failed':
print(f"video upload for post {post.id} failed")
break
except Exception as e:
traceback.print_exc()
print("retard. aborting thread")
break
def thumbnail_thread(pid):
@ -870,29 +833,8 @@ def submit_post(v):
body=request.values.get("body", "")
), 403
if file.content_type.startswith('image/'):
new_post.url = upload_ibb(file=file)
else:
try:
post_url = upload_video(file)
if not post_url.endswith('.mp4'):
post_url += 'mp4'
new_post.url = post_url
new_post.processing = True
gevent.spawn(check_processing_thread, v.id, new_post, post_url)
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.values.get("body", "")
), 400
if file.content_type.startswith('image/'): new_post.url = upload_ibb(file=file)
elif file.content_type.startswith('video/'): new_post.post_url = upload_video(file)
g.db.add(new_post)