diff --git a/files/helpers/images.py b/files/helpers/images.py index d79e5b809..6cd522f97 100644 --- a/files/helpers/images.py +++ b/files/helpers/images.py @@ -115,4 +115,8 @@ def upload_video(file): finally: remove(file_path) - return resp['link'] + link = resp['link'] + img = Image(text=link, deletehash=resp['deletehash']) + g.db.add(img) + + return link diff --git a/files/routes/posts.py b/files/routes/posts.py index 92d3a94f8..91e8fec69 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -538,23 +538,27 @@ def check_processing_thread(v, post, link, db): headers = {"Authorization": f"Client-ID {IMGUR_KEY}"} while True: - time.sleep(15) + # 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) + 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 - db.add(post) + status = req.json()['data']['processing']['status'] + if status == 'completed': + post.processing = False + db.add(post) - send_notification( - NOTIFICATIONS_ACCOUNT, - v, - f"Your video has finished processing and your [post](/post/{post.id}) is now live.", - db=db - ) + send_notification( + NOTIFICATIONS_ACCOUNT, + v, + f"Your video has finished processing and your [post](/post/{post.id}) is now live.", + db=db + ) - db.commit() + db.commit() + break + except Exception: break