forked from rDrama/rDrama
add form to update hats
parent
9cb5067966
commit
3f5ab7315f
|
@ -347,7 +347,7 @@ def remove_hat(v, name):
|
||||||
@app.get("/admin/update/marseys")
|
@app.get("/admin/update/marseys")
|
||||||
@admin_level_required(3)
|
@admin_level_required(3)
|
||||||
def update_marseys(v):
|
def update_marseys(v):
|
||||||
return render_template("update_marseys.html", v=v)
|
return render_template("update_assets.html", v=v, type="Marsey")
|
||||||
|
|
||||||
|
|
||||||
@app.post("/admin/update/marseys")
|
@app.post("/admin/update/marseys")
|
||||||
|
@ -358,7 +358,7 @@ def update_marsey(v):
|
||||||
name = request.values.get('name').lower().strip()
|
name = request.values.get('name').lower().strip()
|
||||||
|
|
||||||
def error(error):
|
def error(error):
|
||||||
return render_template("update_marseys.html", v=v, error=error)
|
return render_template("update_assets.html", v=v, error=error, type="Marsey")
|
||||||
|
|
||||||
if request.headers.get("cf-ipcountry") == "T1":
|
if request.headers.get("cf-ipcountry") == "T1":
|
||||||
return error("Image uploads are not allowed through TOR.")
|
return error("Image uploads are not allowed through TOR.")
|
||||||
|
@ -388,4 +388,56 @@ def update_marsey(v):
|
||||||
requests.post(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/purge_cache', headers=CF_HEADERS,
|
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)
|
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)
|
||||||
|
|
||||||
return render_template("update_marseys.html", v=v, msg=f"'{name}' updated successfully!")
|
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):
|
||||||
|
return render_template("update_assets.html", v=v, type="Hat")
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/admin/update/hats")
|
||||||
|
@admin_level_required(3)
|
||||||
|
def update_hat(v):
|
||||||
|
|
||||||
|
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()
|
||||||
|
new_path = f'/asset_submissions/hats/original/{name}.{format}'
|
||||||
|
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)
|
||||||
|
|
||||||
|
return render_template("update_assets.html", v=v, msg=f"'{name}' updated successfully!", type="Hat")
|
|
@ -27,6 +27,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if SITE_NAME == 'rDrama' %}
|
{% if SITE_NAME == 'rDrama' %}
|
||||||
<li><a href="/admin/update/marseys">Update Marseys</a></li>
|
<li><a href="/admin/update/marseys">Update Marseys</a></li>
|
||||||
|
<li><a href="/admin/update/hats">Update Hats</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{% extends "default.html" %}
|
{% extends "default.html" %}
|
||||||
|
|
||||||
{% block title %}
|
{% block title %}
|
||||||
<title>Update Marseys</title>
|
<title>Update {{type}}</title>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block pagetype %}message{% endblock %}
|
{% block pagetype %}message{% endblock %}
|
||||||
|
@ -31,11 +31,11 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<div class="mx-4">
|
<div class="mx-4">
|
||||||
<h2 class="mt-5">Update Marsey</h2>
|
<h2 class="mt-5">Update {{type}}</h2>
|
||||||
<div class="settings-section rounded">
|
<div class="settings-section rounded">
|
||||||
<div class="d-lg-flex">
|
<div class="d-lg-flex">
|
||||||
<div class="body w-lg-100">
|
<div class="body w-lg-100">
|
||||||
<form action="/admin/update/marseys" method="post" enctype="multipart/form-data">
|
<form action="{{request.path}}" method="post" enctype="multipart/form-data">
|
||||||
<input type="hidden" name="formkey" value="{{v.formkey}}">
|
<input type="hidden" name="formkey" value="{{v.formkey}}">
|
||||||
|
|
||||||
<div id="image-upload-block">
|
<div id="image-upload-block">
|
||||||
|
@ -49,11 +49,11 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<label class="mt-3" for="name">Name</label>
|
<label class="mt-3" for="name">Name</label>
|
||||||
<input autocomplete="off" type="text" id="name" class="form-control" name="name" maxlength="30" pattern='[Mm][Aa][Rr][Ss][Ee][Yy][a-zA-Z0-9]{1,24}' placeholder="Required" value="{{name}}" required>
|
<input autocomplete="off" type="text" id="name" class="form-control" name="name" maxlength="30" placeholder="Required" value="{{name}}" required>
|
||||||
|
|
||||||
<div class="footer mt-4">
|
<div class="footer mt-4">
|
||||||
<div class="d-flex">
|
<div class="d-flex">
|
||||||
<input id="update-marsey" type="submit" onclick="disable(this)" class="btn btn-primary ml-auto" value="Update Marsey">
|
<input id="update-asset" type="submit" onclick="disable(this)" class="btn btn-primary ml-auto" value="Update {{type}}">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
@ -99,7 +99,7 @@
|
||||||
document.getElementById('image-preview').setAttribute('src', this.result);
|
document.getElementById('image-preview').setAttribute('src', this.result);
|
||||||
document.getElementById('image-preview').classList.remove('d-none');
|
document.getElementById('image-preview').classList.remove('d-none');
|
||||||
});
|
});
|
||||||
document.getElementById('submit-marsey').disabled = false;
|
document.getElementById('submit-asset').disabled = false;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
Loading…
Reference in New Issue