remotes/1693045480750635534/spooky-22
Aevann1 2021-12-26 07:44:09 +02:00
parent cf93786498
commit f1b1d7ff50
1 changed files with 27 additions and 0 deletions

View File

@ -1021,6 +1021,33 @@ def submit_post(v):
)
g.db.add(vote)
if request.files.get('file') and request.headers.get("cf-ipcountry") != "T1":
file = request.files['file']
if not file.content_type.startswith(('image/', 'video/')):
if request.headers.get("Authorization"): return {"error": f"File type not allowed"}, 400
if not v or v.oldsite: template = ''
else: template = 'CHRISTMAS/'
return render_template(f"{template}submit.html", v=v, error=f"File type not allowed.", title=title, body=request.values.get("body", "")), 400
if file.content_type.startswith('image/'):
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
file.save(name)
new_post.url = process_image(name)
name2 = name.replace('.webp', 'r.webp')
copyfile(name, name2)
new_post.thumburl = process_image(name2, True)
elif file.content_type.startswith('video/'):
file.save("video.mp4")
with open("video.mp4", 'rb') as f:
url = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {CATBOX_KEY}'}, files=[('video', f)]).json()['data']['link']
new_post.url = url
g.db.add(new_post)
if not new_post.thumburl and new_post.url and request.headers.get('cf-ipcountry')!="T1": gevent.spawn( thumbnail_thread, new_post.id)
if not new_post.private: