2022-09-10 07:38:23 +00:00
|
|
|
from shutil import move, copyfile
|
2022-09-27 00:47:52 +00:00
|
|
|
from os import rename, path
|
2022-09-10 07:38:23 +00:00
|
|
|
|
|
|
|
from files.__main__ import app, limiter
|
|
|
|
from files.helpers.const import *
|
|
|
|
from files.helpers.actions import *
|
|
|
|
from files.helpers.media import *
|
2022-09-13 18:00:11 +00:00
|
|
|
from files.helpers.get import *
|
2022-09-10 07:38:23 +00:00
|
|
|
from files.helpers.wrappers import *
|
|
|
|
from files.routes.static import marsey_list
|
|
|
|
|
2022-09-10 11:07:58 +00:00
|
|
|
@app.get('/asset_submissions/<path:path>')
|
2022-09-10 07:38:23 +00:00
|
|
|
@limiter.exempt
|
2022-09-10 11:07:58 +00:00
|
|
|
def asset_submissions(path):
|
|
|
|
resp = make_response(send_from_directory('/asset_submissions', path))
|
2022-09-10 07:38:23 +00:00
|
|
|
resp.headers.remove("Cache-Control")
|
|
|
|
resp.headers.add("Cache-Control", "public, max-age=3153600")
|
|
|
|
resp.headers.remove("Content-Type")
|
|
|
|
resp.headers.add("Content-Type", "image/webp")
|
|
|
|
return resp
|
|
|
|
|
|
|
|
@app.get("/submit/marseys")
|
|
|
|
@auth_required
|
|
|
|
def submit_marseys(v):
|
|
|
|
if v.admin_level > 2:
|
|
|
|
marseys = g.db.query(Marsey).filter(Marsey.submitter_id != None).all()
|
|
|
|
else:
|
|
|
|
marseys = g.db.query(Marsey).filter(Marsey.submitter_id == v.id).all()
|
|
|
|
|
|
|
|
for marsey in marseys:
|
|
|
|
marsey.author = g.db.query(User.username).filter_by(id=marsey.author_id).one()[0]
|
|
|
|
marsey.submitter = g.db.query(User.username).filter_by(id=marsey.submitter_id).one()[0]
|
|
|
|
|
|
|
|
return render_template("submit_marseys.html", v=v, marseys=marseys)
|
|
|
|
|
|
|
|
|
|
|
|
@app.post("/submit/marseys")
|
|
|
|
@auth_required
|
|
|
|
def submit_marsey(v):
|
|
|
|
|
2022-09-13 11:00:47 +00:00
|
|
|
file = request.files["image"]
|
|
|
|
name = request.values.get('name').lower().strip()
|
|
|
|
tags = request.values.get('tags').lower().strip()
|
|
|
|
username = request.values.get('author').lower().strip()
|
|
|
|
|
2022-09-10 07:38:23 +00:00
|
|
|
def error(error):
|
|
|
|
if v.admin_level > 2: marseys = g.db.query(Marsey).filter(Marsey.submitter_id != None).all()
|
|
|
|
else: marseys = g.db.query(Marsey).filter(Marsey.submitter_id == v.id).all()
|
|
|
|
for marsey in marseys:
|
|
|
|
marsey.author = g.db.query(User.username).filter_by(id=marsey.author_id).one()[0]
|
|
|
|
marsey.submitter = g.db.query(User.username).filter_by(id=marsey.submitter_id).one()[0]
|
2022-09-13 11:00:47 +00:00
|
|
|
return render_template("submit_marseys.html", v=v, marseys=marseys, error=error, name=name, tags=tags, username=username, file=file), 400
|
2022-09-10 07:38:23 +00:00
|
|
|
|
|
|
|
if request.headers.get("cf-ipcountry") == "T1":
|
|
|
|
return error("Image uploads are not allowed through TOR.")
|
|
|
|
|
|
|
|
if not file or not file.content_type.startswith('image/'):
|
|
|
|
return error("You need to submit an image!")
|
|
|
|
|
|
|
|
if not marsey_regex.fullmatch(name):
|
|
|
|
return error("Invalid name!")
|
|
|
|
|
|
|
|
existing = g.db.query(Marsey.name).filter_by(name=name).one_or_none()
|
|
|
|
if existing:
|
|
|
|
return error("A marsey with this name already exists!")
|
|
|
|
|
|
|
|
if not tags_regex.fullmatch(tags):
|
|
|
|
return error("Invalid tags!")
|
|
|
|
|
2022-09-30 21:00:58 +00:00
|
|
|
author = get_user(username, v=v, graceful=True, include_shadowbanned=False)
|
2022-09-12 07:17:57 +00:00
|
|
|
if not author:
|
|
|
|
return error(f"A user with the name '{username}' was not found!")
|
2022-09-10 07:38:23 +00:00
|
|
|
|
2022-09-12 07:06:50 +00:00
|
|
|
highquality = f'/asset_submissions/marseys/{name}'
|
2022-09-10 07:38:23 +00:00
|
|
|
file.save(highquality)
|
|
|
|
|
2022-09-10 11:07:58 +00:00
|
|
|
filename = f'/asset_submissions/marseys/{name}.webp'
|
2022-09-10 07:38:23 +00:00
|
|
|
copyfile(highquality, filename)
|
2022-09-26 01:15:36 +00:00
|
|
|
process_image(filename, resize=200, trim=True)
|
2022-09-10 07:38:23 +00:00
|
|
|
|
|
|
|
marsey = Marsey(name=name, author_id=author.id, tags=tags, count=0, submitter_id=v.id)
|
|
|
|
g.db.add(marsey)
|
|
|
|
|
|
|
|
g.db.flush()
|
|
|
|
if v.admin_level > 2: marseys = g.db.query(Marsey).filter(Marsey.submitter_id != None).all()
|
|
|
|
else: marseys = g.db.query(Marsey).filter(Marsey.submitter_id == v.id).all()
|
|
|
|
for marsey in marseys:
|
|
|
|
marsey.author = g.db.query(User.username).filter_by(id=marsey.author_id).one()[0]
|
|
|
|
marsey.submitter = g.db.query(User.username).filter_by(id=marsey.submitter_id).one()[0]
|
|
|
|
|
|
|
|
return render_template("submit_marseys.html", v=v, marseys=marseys, msg=f"'{name}' submitted successfully!")
|
|
|
|
|
|
|
|
|
|
|
|
@app.post("/admin/approve/marsey/<name>")
|
|
|
|
@admin_level_required(3)
|
|
|
|
def approve_marsey(v, name):
|
2022-09-23 12:51:57 +00:00
|
|
|
if AEVANN_ID and v.id not in (AEVANN_ID, CARP_ID, SNAKES_ID):
|
2022-09-10 07:38:23 +00:00
|
|
|
return {"error": "Only Carp can approve marseys!"}, 403
|
|
|
|
|
|
|
|
name = name.lower().strip()
|
|
|
|
|
|
|
|
marsey = g.db.query(Marsey).filter_by(name=name).one_or_none()
|
|
|
|
if not marsey:
|
|
|
|
return {"error": f"This marsey '{name}' doesn't exist!"}, 404
|
|
|
|
|
|
|
|
tags = request.values.get('tags').lower().strip()
|
|
|
|
if not tags:
|
|
|
|
return {"error": "You need to include tags!"}, 400
|
|
|
|
|
|
|
|
new_name = request.values.get('name').lower().strip()
|
|
|
|
if not new_name:
|
|
|
|
return {"error": "You need to include name!"}, 400
|
|
|
|
|
|
|
|
|
|
|
|
if not marsey_regex.fullmatch(new_name):
|
|
|
|
return {"error": "Invalid name!"}, 400
|
|
|
|
if not tags_regex.fullmatch(tags):
|
|
|
|
return {"error": "Invalid tags!"}, 400
|
|
|
|
|
|
|
|
|
|
|
|
marsey.name = new_name
|
|
|
|
marsey.tags = tags
|
|
|
|
g.db.add(marsey)
|
|
|
|
|
|
|
|
author = get_account(marsey.author_id)
|
|
|
|
all_by_author = g.db.query(Marsey).filter_by(author_id=author.id).count()
|
|
|
|
|
|
|
|
if all_by_author >= 99:
|
|
|
|
badge_grant(badge_id=143, user=author)
|
|
|
|
elif all_by_author >= 9:
|
|
|
|
badge_grant(badge_id=16, user=author)
|
|
|
|
else:
|
|
|
|
badge_grant(badge_id=17, user=author)
|
|
|
|
|
|
|
|
requests.post(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/purge_cache', headers=CF_HEADERS,
|
|
|
|
data=f'{{"files": ["https://{SITE}/e/{marsey.name}.webp"]}}', timeout=5)
|
|
|
|
cache.delete_memoized(marsey_list)
|
|
|
|
|
|
|
|
|
2022-09-12 07:06:50 +00:00
|
|
|
move(f"/asset_submissions/marseys/{name}.webp", f"files/assets/images/emojis/{marsey.name}.webp")
|
|
|
|
|
|
|
|
highquality = f"/asset_submissions/marseys/{name}"
|
|
|
|
with Image.open(highquality) as i:
|
|
|
|
new_path = f'/asset_submissions/marseys/original/{name}.{i.format.lower()}'
|
|
|
|
rename(highquality, new_path)
|
|
|
|
|
2022-09-15 03:00:02 +00:00
|
|
|
author.coins += 250
|
|
|
|
g.db.add(author)
|
|
|
|
msg = f"@{v.username} has approved a marsey you made: :{marsey.name}:\nYou have received 250 coins as a reward!"
|
|
|
|
send_repeatable_notification(author.id, msg)
|
2022-09-13 18:00:11 +00:00
|
|
|
|
|
|
|
if v.id not in (author.id, marsey.submitter_id):
|
|
|
|
msg = f"@{v.username} has approved a marsey you submitted: :{marsey.name}:"
|
|
|
|
send_repeatable_notification(marsey.submitter_id, msg)
|
|
|
|
|
|
|
|
marsey.submitter_id = None
|
|
|
|
|
2022-09-10 07:38:23 +00:00
|
|
|
return {"message": f"'{marsey.name}' approved!"}
|
|
|
|
|
|
|
|
|
2022-09-11 07:03:34 +00:00
|
|
|
@app.post("/remove/marsey/<name>")
|
|
|
|
@auth_required
|
|
|
|
def remove_marsey(v, name):
|
2022-09-10 07:38:23 +00:00
|
|
|
name = name.lower().strip()
|
|
|
|
|
|
|
|
marsey = g.db.query(Marsey).filter_by(name=name).one_or_none()
|
|
|
|
if not marsey:
|
|
|
|
return {"error": f"This marsey '{name}' doesn't exist!"}, 404
|
|
|
|
|
2022-09-17 18:43:50 +00:00
|
|
|
if v.id not in (marsey.submitter_id, AEVANN_ID, CARP_ID):
|
2022-09-11 07:03:34 +00:00
|
|
|
return {"error": "Only Carp can remove marseys!"}, 403
|
|
|
|
|
2022-09-10 07:38:23 +00:00
|
|
|
if v.id != marsey.submitter_id:
|
|
|
|
msg = f"@{v.username} has rejected a marsey you submitted: `'{marsey.name}'`"
|
|
|
|
send_repeatable_notification(marsey.submitter_id, msg)
|
|
|
|
|
|
|
|
g.db.delete(marsey)
|
2022-09-10 11:07:58 +00:00
|
|
|
os.remove(f"/asset_submissions/marseys/{marsey.name}.webp")
|
2022-09-12 07:06:50 +00:00
|
|
|
os.remove(f"/asset_submissions/marseys/{marsey.name}")
|
2022-09-10 07:38:23 +00:00
|
|
|
|
2022-09-11 07:03:34 +00:00
|
|
|
return {"message": f"'{marsey.name}' removed!"}
|
2022-09-10 07:38:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.get("/submit/hats")
|
|
|
|
@auth_required
|
|
|
|
def submit_hats(v):
|
|
|
|
if v.admin_level > 2: hats = g.db.query(HatDef).filter(HatDef.submitter_id != None).all()
|
|
|
|
else: hats = g.db.query(HatDef).filter(HatDef.submitter_id == v.id).all()
|
|
|
|
return render_template("submit_hats.html", v=v, hats=hats)
|
|
|
|
|
|
|
|
|
|
|
|
@app.post("/submit/hats")
|
|
|
|
@auth_required
|
|
|
|
def submit_hat(v):
|
|
|
|
|
2022-09-13 11:00:47 +00:00
|
|
|
name = request.values.get('name').strip()
|
|
|
|
description = request.values.get('description').strip()
|
|
|
|
username = request.values.get('author').strip()
|
|
|
|
|
2022-09-10 07:38:23 +00:00
|
|
|
def error(error):
|
|
|
|
if v.admin_level > 2: hats = g.db.query(HatDef).filter(HatDef.submitter_id != None).all()
|
|
|
|
else: hats = g.db.query(HatDef).filter(HatDef.submitter_id == v.id).all()
|
2022-09-13 11:00:47 +00:00
|
|
|
return render_template("submit_hats.html", v=v, hats=hats, error=error, name=name, description=description, username=username), 400
|
2022-09-10 07:38:23 +00:00
|
|
|
|
|
|
|
if request.headers.get("cf-ipcountry") == "T1":
|
|
|
|
return error("Image uploads are not allowed through TOR.")
|
|
|
|
|
|
|
|
file = request.files["image"]
|
|
|
|
if not file or not file.content_type.startswith('image/'):
|
|
|
|
return error("You need to submit an image!")
|
|
|
|
|
|
|
|
if not hat_regex.fullmatch(name):
|
|
|
|
return error("Invalid name!")
|
|
|
|
|
|
|
|
existing = g.db.query(HatDef.name).filter_by(name=name).one_or_none()
|
|
|
|
if existing:
|
|
|
|
return error("A hat with this name already exists!")
|
|
|
|
|
|
|
|
if not description_regex.fullmatch(description):
|
|
|
|
return error("Invalid description!")
|
|
|
|
|
2022-09-30 21:00:58 +00:00
|
|
|
author = get_user(username, v=v, graceful=True, include_shadowbanned=False)
|
2022-09-12 07:17:57 +00:00
|
|
|
if not author:
|
|
|
|
return error(f"A user with the name '{username}' was not found!")
|
2022-09-10 07:38:23 +00:00
|
|
|
|
2022-09-12 07:06:50 +00:00
|
|
|
highquality = f'/asset_submissions/hats/{name}'
|
2022-09-10 07:38:23 +00:00
|
|
|
file.save(highquality)
|
|
|
|
|
|
|
|
i = Image.open(highquality)
|
|
|
|
if i.width > 100 or i.height > 130:
|
2022-09-11 01:28:26 +00:00
|
|
|
os.remove(highquality)
|
2022-09-10 07:38:23 +00:00
|
|
|
return error("Images must be 100x130")
|
|
|
|
|
2022-09-11 14:35:34 +00:00
|
|
|
if len(list(Iterator(i))) > 1: price = 1000
|
|
|
|
else: price = 500
|
|
|
|
|
2022-09-10 11:07:58 +00:00
|
|
|
filename = f'/asset_submissions/hats/{name}.webp'
|
2022-09-10 07:38:23 +00:00
|
|
|
copyfile(highquality, filename)
|
|
|
|
process_image(filename)
|
|
|
|
|
2022-09-11 14:35:34 +00:00
|
|
|
hat = HatDef(name=name, author_id=author.id, description=description, price=price, submitter_id=v.id)
|
2022-09-10 07:38:23 +00:00
|
|
|
g.db.add(hat)
|
|
|
|
|
|
|
|
g.db.commit()
|
|
|
|
|
|
|
|
if v.admin_level > 2: hats = g.db.query(HatDef).filter(HatDef.submitter_id != None).all()
|
|
|
|
else: hats = g.db.query(HatDef).filter(HatDef.submitter_id == v.id).all()
|
|
|
|
return render_template("submit_hats.html", v=v, hats=hats, msg=f"'{name}' submitted successfully!")
|
|
|
|
|
|
|
|
|
|
|
|
@app.post("/admin/approve/hat/<name>")
|
|
|
|
@admin_level_required(3)
|
|
|
|
def approve_hat(v, name):
|
2022-09-23 12:51:57 +00:00
|
|
|
if AEVANN_ID and v.id not in (AEVANN_ID, CARP_ID, SNAKES_ID):
|
2022-09-10 07:38:23 +00:00
|
|
|
return {"error": "Only Carp can approve hats!"}, 403
|
|
|
|
|
2022-09-10 07:42:09 +00:00
|
|
|
name = name.strip()
|
2022-09-10 07:38:23 +00:00
|
|
|
|
|
|
|
hat = g.db.query(HatDef).filter_by(name=name).one_or_none()
|
|
|
|
if not hat:
|
|
|
|
return {"error": f"This hat '{name}' doesn't exist!"}, 404
|
|
|
|
|
2022-09-10 07:42:09 +00:00
|
|
|
description = request.values.get('description').strip()
|
2022-09-10 07:38:23 +00:00
|
|
|
if not description:
|
|
|
|
return {"error": "You need to include description!"}, 400
|
|
|
|
|
2022-09-10 07:42:09 +00:00
|
|
|
new_name = request.values.get('name').strip()
|
2022-09-10 07:38:23 +00:00
|
|
|
if not new_name:
|
|
|
|
return {"error": "You need to include name!"}, 400
|
|
|
|
|
|
|
|
if not hat_regex.fullmatch(new_name):
|
|
|
|
return {"error": "Invalid name!"}, 400
|
|
|
|
|
|
|
|
if not description_regex.fullmatch(description):
|
|
|
|
return {"error": "Invalid description!"}, 400
|
|
|
|
|
2022-09-10 13:46:56 +00:00
|
|
|
hat.price = int(request.values.get('price'))
|
2022-09-10 07:38:23 +00:00
|
|
|
hat.name = new_name
|
|
|
|
hat.description = description
|
|
|
|
g.db.add(hat)
|
|
|
|
|
|
|
|
|
|
|
|
g.db.flush()
|
|
|
|
author = hat.author
|
|
|
|
|
|
|
|
all_by_author = g.db.query(HatDef).filter_by(author_id=author.id).count()
|
|
|
|
|
|
|
|
if all_by_author >= 250:
|
|
|
|
badge_grant(badge_id=166, user=author)
|
|
|
|
elif all_by_author >= 100:
|
|
|
|
badge_grant(badge_id=165, user=author)
|
|
|
|
elif all_by_author >= 50:
|
|
|
|
badge_grant(badge_id=164, user=author)
|
|
|
|
elif all_by_author >= 10:
|
|
|
|
badge_grant(badge_id=163, user=author)
|
|
|
|
|
|
|
|
hat_copy = Hat(
|
|
|
|
user_id=author.id,
|
|
|
|
hat_id=hat.id
|
|
|
|
)
|
|
|
|
g.db.add(hat_copy)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if v.id != hat.submitter_id:
|
|
|
|
msg = f"@{v.username} has approved a hat you submitted: '{hat.name}'"
|
|
|
|
send_repeatable_notification(hat.submitter_id, msg)
|
|
|
|
|
|
|
|
hat.submitter_id = None
|
|
|
|
|
2022-09-12 07:06:50 +00:00
|
|
|
move(f"/asset_submissions/hats/{name}.webp", f"files/assets/images/hats/{hat.name}.webp")
|
|
|
|
|
|
|
|
highquality = f"/asset_submissions/hats/{name}"
|
|
|
|
with Image.open(highquality) as i:
|
|
|
|
new_path = f'/asset_submissions/hats/original/{name}.{i.format.lower()}'
|
|
|
|
rename(highquality, new_path)
|
|
|
|
|
2022-09-10 07:38:23 +00:00
|
|
|
return {"message": f"'{hat.name}' approved!"}
|
|
|
|
|
|
|
|
|
2022-09-11 07:03:34 +00:00
|
|
|
@app.post("/remove/hat/<name>")
|
|
|
|
@auth_required
|
|
|
|
def remove_hat(v, name):
|
2022-09-10 07:42:09 +00:00
|
|
|
name = name.strip()
|
2022-09-10 07:38:23 +00:00
|
|
|
|
|
|
|
hat = g.db.query(HatDef).filter_by(name=name).one_or_none()
|
|
|
|
if not hat:
|
|
|
|
return {"error": f"This hat '{name}' doesn't exist!"}, 404
|
|
|
|
|
2022-09-17 18:43:50 +00:00
|
|
|
if v.id not in (hat.submitter_id, AEVANN_ID, CARP_ID):
|
2022-09-11 07:03:34 +00:00
|
|
|
return {"error": "Only Carp can remove hats!"}, 403
|
|
|
|
|
2022-09-10 07:38:23 +00:00
|
|
|
if v.id != hat.submitter_id:
|
|
|
|
msg = f"@{v.username} has rejected a hat you submitted: `'{hat.name}'`"
|
|
|
|
send_repeatable_notification(hat.submitter_id, msg)
|
|
|
|
|
|
|
|
g.db.delete(hat)
|
2022-09-10 11:07:58 +00:00
|
|
|
os.remove(f"/asset_submissions/hats/{hat.name}.webp")
|
2022-09-12 07:06:50 +00:00
|
|
|
os.remove(f"/asset_submissions/hats/{hat.name}")
|
2022-09-10 07:38:23 +00:00
|
|
|
|
2022-09-15 03:00:02 +00:00
|
|
|
return {"message": f"'{hat.name}' removed!"}
|
2022-09-17 15:08:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.get("/admin/update/marseys")
|
|
|
|
@admin_level_required(3)
|
|
|
|
def update_marseys(v):
|
2022-09-23 12:51:57 +00:00
|
|
|
if AEVANN_ID and v.id not in (AEVANN_ID, CARP_ID, GEESE_ID, SNAKES_ID):
|
|
|
|
abort(403)
|
|
|
|
|
2022-09-18 17:38:53 +00:00
|
|
|
return render_template("update_assets.html", v=v, type="Marsey")
|
2022-09-17 15:08:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
@app.post("/admin/update/marseys")
|
|
|
|
@admin_level_required(3)
|
|
|
|
def update_marsey(v):
|
2022-09-23 12:51:57 +00:00
|
|
|
if AEVANN_ID and v.id not in (AEVANN_ID, CARP_ID, GEESE_ID, SNAKES_ID):
|
|
|
|
abort(403)
|
2022-09-17 15:08:24 +00:00
|
|
|
|
|
|
|
file = request.files["image"]
|
|
|
|
name = request.values.get('name').lower().strip()
|
|
|
|
|
|
|
|
def error(error):
|
2022-09-18 17:38:53 +00:00
|
|
|
return render_template("update_assets.html", v=v, error=error, type="Marsey")
|
2022-09-17 15:08:24 +00:00
|
|
|
|
|
|
|
if request.headers.get("cf-ipcountry") == "T1":
|
|
|
|
return error("Image uploads are not allowed through TOR.")
|
|
|
|
|
|
|
|
if not file or not file.content_type.startswith('image/'):
|
|
|
|
return error("You need to submit an image!")
|
|
|
|
|
|
|
|
if not marsey_regex.fullmatch(name):
|
|
|
|
return error("Invalid name!")
|
|
|
|
|
|
|
|
existing = g.db.query(Marsey.name).filter_by(name=name).one_or_none()
|
|
|
|
if not existing:
|
|
|
|
return error("A marsey with this name doesn't exist!")
|
|
|
|
|
2022-09-18 23:36:48 +00:00
|
|
|
for x in ('png','jpeg','webp','gif'):
|
2022-09-18 23:34:23 +00:00
|
|
|
if path.isfile(f'/asset_submissions/marseys/original/{name}.{x}'):
|
|
|
|
os.remove(f'/asset_submissions/marseys/original/{name}.{x}')
|
2022-09-17 15:08:24 +00:00
|
|
|
|
|
|
|
highquality = f"/asset_submissions/marseys/{name}"
|
|
|
|
file.save(highquality)
|
|
|
|
with Image.open(highquality) as i:
|
2022-09-17 20:13:30 +00:00
|
|
|
format = i.format.lower()
|
2022-09-18 23:34:23 +00:00
|
|
|
new_path = f'/asset_submissions/marseys/original/{name}.{format}'
|
2022-09-17 15:08:24 +00:00
|
|
|
rename(highquality, new_path)
|
|
|
|
|
|
|
|
filename = f"files/assets/images/emojis/{name}.webp"
|
|
|
|
copyfile(new_path, filename)
|
2022-09-26 01:15:36 +00:00
|
|
|
process_image(filename, resize=200, trim=True)
|
2022-09-17 15:08:24 +00:00
|
|
|
|
2022-09-17 20:25:15 +00:00
|
|
|
requests.post(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/purge_cache', headers=CF_HEADERS,
|
|
|
|
data=f'{{"files": ["https://{SITE}/e/{name}.webp", "https://{SITE}/assets/images/emojis/{name}.webp", "https://{SITE}/asset_submissions/marseys/original/{name}.{format}"]}}', timeout=5)
|
2022-09-17 20:13:30 +00:00
|
|
|
|
2022-09-23 12:51:57 +00:00
|
|
|
ma = ModAction(
|
|
|
|
kind="update_marsey",
|
|
|
|
user_id=v.id,
|
|
|
|
_note=name
|
|
|
|
)
|
|
|
|
g.db.add(ma)
|
|
|
|
|
2022-09-18 17:38:53 +00:00
|
|
|
return render_template("update_assets.html", v=v, msg=f"'{name}' updated successfully!", type="Marsey")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.get("/admin/update/hats")
|
|
|
|
@admin_level_required(3)
|
|
|
|
def update_hats(v):
|
2022-09-23 12:51:57 +00:00
|
|
|
if AEVANN_ID and v.id not in (AEVANN_ID, CARP_ID, GEESE_ID, SNAKES_ID):
|
|
|
|
abort(403)
|
|
|
|
|
2022-09-18 17:38:53 +00:00
|
|
|
return render_template("update_assets.html", v=v, type="Hat")
|
|
|
|
|
|
|
|
|
|
|
|
@app.post("/admin/update/hats")
|
|
|
|
@admin_level_required(3)
|
|
|
|
def update_hat(v):
|
2022-09-23 12:51:57 +00:00
|
|
|
if AEVANN_ID and v.id not in (AEVANN_ID, CARP_ID, GEESE_ID, SNAKES_ID):
|
|
|
|
abort(403)
|
2022-09-18 17:38:53 +00:00
|
|
|
|
|
|
|
file = request.files["image"]
|
|
|
|
name = request.values.get('name').strip()
|
|
|
|
|
|
|
|
def error(error):
|
|
|
|
return render_template("update_assets.html", v=v, error=error, type="Hat")
|
|
|
|
|
|
|
|
if request.headers.get("cf-ipcountry") == "T1":
|
|
|
|
return error("Image uploads are not allowed through TOR.")
|
|
|
|
|
|
|
|
if not file or not file.content_type.startswith('image/'):
|
|
|
|
return error("You need to submit an image!")
|
|
|
|
|
|
|
|
if not hat_regex.fullmatch(name):
|
|
|
|
return error("Invalid name!")
|
|
|
|
|
|
|
|
existing = g.db.query(HatDef.name).filter_by(name=name).one_or_none()
|
|
|
|
if not existing:
|
|
|
|
return error("A hat with this name doesn't exist!")
|
|
|
|
|
|
|
|
highquality = f"/asset_submissions/hats/{name}"
|
|
|
|
file.save(highquality)
|
|
|
|
|
|
|
|
with Image.open(highquality) as i:
|
|
|
|
if i.width > 100 or i.height > 130:
|
|
|
|
os.remove(highquality)
|
|
|
|
return error("Images must be 100x130")
|
|
|
|
|
|
|
|
format = i.format.lower()
|
2022-09-18 23:34:23 +00:00
|
|
|
new_path = f'/asset_submissions/hats/original/{name}.{format}'
|
|
|
|
|
2022-09-18 23:36:48 +00:00
|
|
|
for x in ('png','jpeg','webp','gif'):
|
2022-09-18 23:34:23 +00:00
|
|
|
if path.isfile(f'/asset_submissions/hats/original/{name}.{x}'):
|
|
|
|
os.remove(f'/asset_submissions/hats/original/{name}.{x}')
|
|
|
|
|
2022-09-18 17:38:53 +00:00
|
|
|
rename(highquality, new_path)
|
|
|
|
|
|
|
|
filename = f"files/assets/images/hats/{name}.webp"
|
|
|
|
copyfile(new_path, filename)
|
|
|
|
process_image(filename)
|
|
|
|
|
|
|
|
requests.post(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/purge_cache', headers=CF_HEADERS,
|
|
|
|
data=f'{{"files": ["https://{SITE}/i/hats/{name}.webp", "https://{SITE}/assets/images/hats/{name}.webp", "https://{SITE}/asset_submissions/hats/original/{name}.{format}"]}}', timeout=5)
|
|
|
|
|
2022-09-23 12:51:57 +00:00
|
|
|
ma = ModAction(
|
|
|
|
kind="update_hat",
|
|
|
|
user_id=v.id,
|
|
|
|
_note=name
|
|
|
|
)
|
|
|
|
g.db.add(ma)
|
|
|
|
|
2022-09-29 05:43:29 +00:00
|
|
|
return render_template("update_assets.html", v=v, msg=f"'{name}' updated successfully!", type="Hat")
|