remotes/1693045480750635534/spooky-22
parent
df8a0e1715
commit
8ecf09dd1a
|
@ -533,40 +533,40 @@ def filter_title(title):
|
|||
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')
|
||||
headers = {"Authorization": f"Client-ID {IMGUR_KEY}"}
|
||||
# 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)
|
||||
# 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)
|
||||
# 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()
|
||||
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
|
||||
# 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
|
||||
|
||||
|
||||
@app.post("/submit")
|
||||
|
@ -894,53 +894,53 @@ def submit_post(v):
|
|||
if 'pcm' in request.host:
|
||||
if file.content_type.startswith('image/'):
|
||||
new_post.url = upload_ibb(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, g.db)
|
||||
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
|
||||
# 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, g.db)
|
||||
# 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
|
||||
else:
|
||||
if file.content_type.startswith('image/'):
|
||||
new_post.url = upload_imgur(file)
|
||||
else:
|
||||
try:
|
||||
post_url = upload_video(file)
|
||||
# shit to make webm work
|
||||
if not post_url.endswith('.mp4'):
|
||||
post_url += 'mp4'
|
||||
# print(post_url)
|
||||
new_post.url = post_url
|
||||
new_post.processing = True
|
||||
gevent.spawn(check_processing_thread, v.id, new_post, post_url, g.db)
|
||||
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
|
||||
# else:
|
||||
# try:
|
||||
# post_url = upload_video(file)
|
||||
# # shit to make webm work
|
||||
# if not post_url.endswith('.mp4'):
|
||||
# post_url += 'mp4'
|
||||
# # print(post_url)
|
||||
# new_post.url = post_url
|
||||
# new_post.processing = True
|
||||
# gevent.spawn(check_processing_thread, v.id, new_post, post_url, g.db)
|
||||
# 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.submission_aux)
|
||||
|
|
Loading…
Reference in New Issue