forked from rDrama/rDrama
1
0
Fork 0
master
Aevann1 2021-09-10 05:03:37 +02:00
parent a0d8860b68
commit e7f9d1d32b
5 changed files with 39 additions and 76 deletions

View File

@ -1250,5 +1250,5 @@ def multiple_plots(**kwargs):
plt.savefig("image.png")
plt.clf()
if "pcmemes.net" in request.host: return upload_ibb("image.png")
else: return upload_imgur("image.png")
if "pcmemes.net" in request.host: return upload_ibb(filepath="image.png")
else: return upload_imgur(filepath="image.png")

View File

@ -278,9 +278,8 @@ def api_comment(v):
file=request.files["file"]
if not file.content_type.startswith('image/'): return {"error": "That wasn't an image!"}, 400
file.save(f"image.{file.filename.split('.')[-1]}")
if 'pcmemes.net' in request.host: url = upload_ibb(f"image.{file.filename.split('.')[-1]}")
else: url = upload_imgur(f"image.{file.filename.split('.')[-1]}")
if 'pcmemes.net' in request.host: url = upload_ibb(file=file)
else: url = upload_imgur(file=file)
body = request.form.get("body") + f"\n![]({url})"
body = body.replace("\n", "\n\n").replace("\n\n\n\n\n\n", "\n\n").replace("\n\n\n\n", "\n\n").replace("\n\n\n", "\n\n")
@ -694,9 +693,8 @@ def edit_comment(cid, v):
file=request.files["file"]
if not file.content_type.startswith('image/'): return {"error": "That wasn't an image!"}, 400
file.save(f"image.{file.format}", optimize=True, quality=30)
if 'pcmemes.net' in request.host: url = upload_ibb(f"image.{file.format}")
else: url = upload_imgur(f"image.{file.format}")
if 'pcmemes.net' in request.host: url = upload_ibb(file=file)
else: url = upload_imgur(file=file)
body += f"\n![]({url})"
with CustomRenderer(post_id=c.parent_submission) as renderer:

View File

@ -506,7 +506,7 @@ def thumbs(new_post):
file.write(chunk)
if 'pcmemes.net' in request.host: post.thumburl = upload_ibb(f"image.png", True)
else: post.thumburl = upload_imgur(f"image.png", True)
else: post.thumburl = upload_imgur(filepath="image.png", resize=True)
g.db.add(post)
@ -891,58 +891,30 @@ def submit_post(v):
body=request.form.get("body", "")
), 403
if 'pcmemes.net' in request.host:
if file.content_type.startswith('image/'):
file.save(f"image.{file.format}", optimize=True, quality=30)
new_post.url = upload_ibb(f"image.{file.format}")
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
if file.content_type.startswith('image/'):
if 'pcmemes.net' in request.host: new_post.url = upload_ibb(file=file)
else: new_post.url = upload_imgur(file=file)
else:
if file.content_type.startswith('image/'):
file.save(f"image.{file.filename.split('.')[-1]}")
new_post.url = upload_imgur(f"image.{file.filename.split('.')[-1]}")
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
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
g.db.add(new_post)
g.db.add(new_post.submission_aux)

View File

@ -113,9 +113,8 @@ def settings_profile_post(v):
if request.headers.get("Authorization"): return {"error": f"Image files only"}, 400
else: return render_template("settings_profile.html", v=v, error=f"Image files only."), 400
file.save(f"image.{file.format}", optimize=True, quality=30)
if 'pcmemes.net' in request.host: url = upload_ibb(f"image.{file.format}")
else: url = upload_imgur(f"image.{file.format}")
if 'pcmemes.net' in request.host: url = upload_ibb(file=file)
else: url = upload_imgur(file=file)
bio += f"\n\n![]({url})"
@ -498,17 +497,13 @@ def settings_images_profile(v):
if request.headers.get("cf-ipcountry") == "T1": return "Image uploads are not allowed through TOR.", 403
file = request.files["profile"]
print(file.filename)
print(file.filename.split('.')[-1])
file.save(f"image.{file.filename.split('.')[-1]}")
if 'pcmemes.net' in request.host: highres = upload_ibb(f"image.{file.filename.split('.')[-1]}")
else: highres = upload_imgur(f"image.{file.filename.split('.')[-1]}")
if 'pcmemes.net' in request.host: highres = upload_ibb(file=file)
else: highres = upload_imgur(file=file)
if not highres: abort(400)
if 'pcmemes.net' in request.host: imageurl = upload_ibb(f"image.{file.filename.split('.')[-1]}", True)
else: imageurl = upload_imgur(f"image.{file.filename.split('.')[-1]}", True)
if 'pcmemes.net' in request.host: imageurl = upload_ibb(file=file, resize=True)
else: imageurl = upload_imgur(file=file, resize=True)
if not imageurl: abort(400)
v.highres = highres
@ -529,10 +524,8 @@ def settings_images_banner(v):
if request.headers.get("cf-ipcountry") == "T1": return "Image uploads are not allowed through TOR.", 403
file = request.files["banner"]
file.save(f"image.{file.filename.split('.')[-1]}")
if 'pcmemes.net' in request.host: imageurl = upload_ibb(f"image.{file.filename.split('.')[-1]}")
else: imageurl = upload_imgur(f"image.{file.filename.split('.')[-1]}")
if 'pcmemes.net' in request.host: imageurl = upload_ibb(file=file)
else: imageurl = upload_imgur(file=file)
if imageurl:
v.bannerurl = imageurl

View File

@ -291,7 +291,7 @@ def mfa_qr(secret, v):
mem = io.BytesIO()
img.save(mem, format="PNG", optimize=True, quality=30)
img.save(mem, format="PNG")
mem.seek(0, 0)
return send_file(mem, mimetype="image/png", as_attachment=False)