From f1b1d7ff5099e1e1b0cb2692fcbced179780b6f0 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 26 Dec 2021 07:44:09 +0200 Subject: [PATCH] fsd --- files/routes/posts.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/files/routes/posts.py b/files/routes/posts.py index 15a0cfe3c..bd2944bf7 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -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: