sfdsfdfsd
This commit is contained in:
parent
e97221c914
commit
7a85624ec3
13 changed files with 73 additions and 106 deletions
|
@ -18,6 +18,7 @@ from PIL import Image as PILimage
|
|||
from .front import frontlist, changeloglist
|
||||
from urllib.parse import ParseResult, urlunparse, urlparse, quote
|
||||
from os import path
|
||||
import requests
|
||||
|
||||
site = environ.get("DOMAIN").strip()
|
||||
site_name = environ.get("SITE_NAME").strip()
|
||||
|
@ -420,13 +421,17 @@ def edit_post(pid, v):
|
|||
|
||||
if request.files.get("file") and request.headers.get("cf-ipcountry") != "T1":
|
||||
file=request.files["file"]
|
||||
if not file.content_type.startswith('image/'): return {"error": "That wasn't an image!"}, 400
|
||||
if file.content_type.startswith('image/'):
|
||||
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
|
||||
file.save(name)
|
||||
url = process_image(name)
|
||||
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']
|
||||
else: return {"error": f"Image/Video files only"}, 400
|
||||
|
||||
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
|
||||
file.save(name)
|
||||
url = process_image(name)
|
||||
|
||||
body += f"\n\n"
|
||||
body += f"\n\n{url}"
|
||||
|
||||
if body != p.body:
|
||||
for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999))', body, re.MULTILINE):
|
||||
|
@ -916,13 +921,19 @@ def submit_post(v):
|
|||
|
||||
if request.files.get("file2") and request.headers.get("cf-ipcountry") != "T1":
|
||||
file=request.files["file2"]
|
||||
if not file.content_type.startswith('image/'): return {"error": "That wasn't an image!"}, 400
|
||||
if file.content_type.startswith('image/'):
|
||||
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
|
||||
file.save(name)
|
||||
url = process_image(name)
|
||||
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']
|
||||
else:
|
||||
if request.headers.get("Authorization"): return {"error": f"Image/Video files only"}, 400
|
||||
else: return render_template("submit.html", v=v, error=f"Image/Video files only."), 400
|
||||
|
||||
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
|
||||
file.save(name)
|
||||
url = process_image(name)
|
||||
|
||||
body += f"\n\n"
|
||||
body += f"\n\n{url}"
|
||||
|
||||
body_html = sanitize(CustomRenderer().render(mistletoe.Document(body)))
|
||||
|
||||
|
@ -1003,20 +1014,6 @@ def submit_post(v):
|
|||
if request.headers.get("Authorization"): return {"error": f"File type not allowed"}, 400
|
||||
else: return render_template("submit.html", v=v, error=f"File type not allowed.", title=title, body=request.values.get("body", "")), 400
|
||||
|
||||
if file.content_type.startswith('video/') and v.truecoins < app.config["VIDEO_COIN_REQUIREMENT"] and v.admin_level < 1:
|
||||
if request.headers.get("Authorization"):
|
||||
return {
|
||||
"error": f"You need at least {app.config['VIDEO_COIN_REQUIREMENT']} coins to upload videos"
|
||||
}, 403
|
||||
else:
|
||||
return render_template(
|
||||
"submit.html",
|
||||
v=v,
|
||||
error=f"You need at least {app.config['VIDEO_COIN_REQUIREMENT']} coins to upload videos.",
|
||||
title=title,
|
||||
body=request.values.get("body", "")
|
||||
), 403
|
||||
|
||||
if file.content_type.startswith('image/'):
|
||||
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
|
||||
file.save(name)
|
||||
|
@ -1025,7 +1022,7 @@ def submit_post(v):
|
|||
elif file.content_type.startswith('video/'):
|
||||
file.save("video.mp4")
|
||||
with open("video.mp4", 'rb') as f:
|
||||
new_post.url = requests.post('https://catbox.moe/user/api.php', timeout=5, data={'userhash':CATBOX_KEY, 'reqtype':'fileupload'}, files={'fileToUpload':f}).text
|
||||
url = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {CATBOX_KEY}'}, files=[('video', f)]).json()['data']['link']
|
||||
|
||||
g.db.add(new_post)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue