forked from rDrama/rDrama
allow updating emoji name
parent
b24c25d30c
commit
29bbe8ced0
|
@ -7559,3 +7559,16 @@ ul {
|
||||||
display: none !important;
|
display: none !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.section-title {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
text-transform: uppercase;
|
||||||
|
opacity: 0.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-title hr {
|
||||||
|
flex: 1;
|
||||||
|
margin-left: 0.5rem;
|
||||||
|
}
|
||||||
|
|
|
@ -452,10 +452,13 @@ def update_emojis(v):
|
||||||
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
||||||
@admin_level_required(PERMS['UPDATE_ASSETS'])
|
@admin_level_required(PERMS['UPDATE_ASSETS'])
|
||||||
def update_emoji(v):
|
def update_emoji(v):
|
||||||
file = request.files["image"]
|
|
||||||
name = request.values.get('name', '').lower().strip()
|
name = request.values.get('name', '').lower().strip()
|
||||||
tags = request.values.get('tags', '').lower().strip()
|
|
||||||
|
file = request.files["image"]
|
||||||
kind = request.values.get('kind', '').strip()
|
kind = request.values.get('kind', '').strip()
|
||||||
|
new_name = request.values.get('new_name', '').strip()
|
||||||
|
tags = request.values.get('tags', '').lower().strip()
|
||||||
|
nsfw = request.values.get('nsfw', '').strip()
|
||||||
|
|
||||||
existing = g.db.get(Emoji, name)
|
existing = g.db.get(Emoji, name)
|
||||||
if not existing:
|
if not existing:
|
||||||
|
@ -487,18 +490,32 @@ def update_emoji(v):
|
||||||
purge_files_in_cloudflare_cache([f"{SITE_FULL_IMAGES}/e/{name}.webp", f"{SITE_FULL_IMAGES}/asset_submissions/emojis/original/{name}.{format}"])
|
purge_files_in_cloudflare_cache([f"{SITE_FULL_IMAGES}/e/{name}.webp", f"{SITE_FULL_IMAGES}/asset_submissions/emojis/original/{name}.{format}"])
|
||||||
updated = True
|
updated = True
|
||||||
|
|
||||||
|
if kind and existing.kind != kind:
|
||||||
|
if kind not in EMOJI_KINDS:
|
||||||
|
abort(400, "Invalid kind!")
|
||||||
|
existing.kind = kind
|
||||||
|
updated = True
|
||||||
|
|
||||||
if tags and existing.tags != tags and tags != "none":
|
if new_name and existing.name != new_name:
|
||||||
|
if not emoji_name_regex.fullmatch(new_name):
|
||||||
|
abort(400, "Invalid new name!")
|
||||||
|
old_path = f"files/assets/images/emojis/{existing.name}.webp"
|
||||||
|
new_path = f"files/assets/images/emojis/{new_name}.webp"
|
||||||
|
copyfile(old_path, new_path)
|
||||||
|
existing.name = new_name
|
||||||
|
updated = True
|
||||||
|
|
||||||
|
if tags and existing.tags != tags:
|
||||||
if not tags_regex.fullmatch(tags):
|
if not tags_regex.fullmatch(tags):
|
||||||
abort(400, "Invalid tags!")
|
abort(400, "Invalid tags!")
|
||||||
existing.tags += f" {tags}"
|
existing.tags += f" {tags}"
|
||||||
updated = True
|
updated = True
|
||||||
|
|
||||||
if kind and existing.kind != kind and kind != "none":
|
if nsfw:
|
||||||
if kind not in EMOJI_KINDS:
|
nsfw = (nsfw == 'NSFW')
|
||||||
abort(400, "Invalid kind!")
|
if existing.nsfw != nsfw:
|
||||||
existing.kind = kind
|
existing.nsfw = nsfw
|
||||||
updated = True
|
updated = True
|
||||||
|
|
||||||
if not updated:
|
if not updated:
|
||||||
abort(400, "You need to actually update something!")
|
abort(400, "You need to actually update something!")
|
||||||
|
|
|
@ -10,37 +10,63 @@
|
||||||
<form action="{{request.path}}" method="post" enctype="multipart/form-data" data-nonce="{{g.nonce}}" data-onsubmit="sendFormXHR(this)">
|
<form action="{{request.path}}" method="post" enctype="multipart/form-data" data-nonce="{{g.nonce}}" data-onsubmit="sendFormXHR(this)">
|
||||||
<input hidden name="formkey" value="{{v|formkey}}">
|
<input hidden name="formkey" value="{{v|formkey}}">
|
||||||
|
|
||||||
<label class="mt-3" for="name">{{type}} Name (Required)</label>
|
<div class="section-title mt-3">
|
||||||
<input autocomplete="off" type="text" id="name" class="form-control" name="name" maxlength="30" placeholder="Required" {% if name %}value="{{name}}"{% endif %} required>
|
<hr>
|
||||||
|
<h5>Name of {{type}} you wanna alter</h5>
|
||||||
|
<hr>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<input autocomplete="off" type="text" id="name" class="form-control" name="name" maxlength="30" required>
|
||||||
|
|
||||||
|
<div class="section-title mt-4">
|
||||||
|
<hr>
|
||||||
|
<h5>Change at least one of these values</h5>
|
||||||
|
<hr>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div id="image-upload-block">
|
<div id="image-upload-block">
|
||||||
<div><label class="mt-3">New Image {% if type == "Emoji" %}(Optional){% else %}(Required){% endif %}</label></div>
|
<div><label>New Image</label></div>
|
||||||
|
|
||||||
<img loading="lazy" id="image-preview" class="d-none" style="max-width:50%;border:5px white solid">
|
<img loading="lazy" id="image-preview" class="d-none" style="max-width:50%;border:5px white solid">
|
||||||
<label class="btn btn-secondary m-0" for="file-upload">
|
<label class="btn btn-secondary m-0" for="file-upload">
|
||||||
<div>Select Image</div>
|
<div>Select Image<br>(optional)</div>
|
||||||
<input autocomplete="off" id="file-upload" accept="image/*" type="file" name="image" {% if g.is_tor %}disabled{% endif %} hidden>
|
<input autocomplete="off" id="file-upload" accept="image/*" type="file" name="image" {% if g.is_tor %}disabled{% endif %} hidden>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if type == "Emoji" %}
|
{% if type == "Emoji" %}
|
||||||
<label class="mt-3" for="kind">New Kind (Optional)</label>
|
<label class="mt-3" for="kind">New Kind</label>
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<select autocomplete="off" id='kind' class="form-control" name="kind">
|
<select autocomplete="off" id='kind' class="form-control" name="kind">
|
||||||
{% if not kind %}
|
{% if not kind %}
|
||||||
<option hidden disabled selected value>-- select an option --</option>
|
<option hidden disabled selected value>-- select an option -- (optional)</option>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% for entry in EMOJI_KINDS %}
|
{% for entry in EMOJI_KINDS %}
|
||||||
<option value="{{entry}}" {% if entry == kind %}selected{% endif %}>
|
<option value="{{entry}}">
|
||||||
{{entry}}
|
{{entry}}
|
||||||
</option>
|
</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<label class="mt-3" for="tags">Additional Tags (Optional)</label>
|
<label class="mt-3" for="new_name">New Name</label>
|
||||||
<input autocomplete="off" type="text" id="name" class="form-control" name="tags" maxlength="200" placeholder="Enter additional tags" {% if tags %}value="{{tags}}"{% endif %}>
|
<input autocomplete="off" type="text" id="new_name" class="form-control" name="new_name" maxlength="30" placeholder="Optional">
|
||||||
|
|
||||||
|
<label class="mt-3" for="tags">Additional Tags</label>
|
||||||
|
<input autocomplete="off" type="text" id="name" class="form-control" name="tags" maxlength="200" placeholder="Optional">
|
||||||
|
|
||||||
|
<label class="mt-3" for="nsfw">New NSFW Value</label>
|
||||||
|
<div class="input-group">
|
||||||
|
<select autocomplete="off" id='nsfw' class="form-control" name="nsfw">
|
||||||
|
<option hidden disabled selected value>-- select an option -- (optional)</option>
|
||||||
|
<option value="NSFW">
|
||||||
|
NSFW
|
||||||
|
</option>
|
||||||
|
<option value="not_NSFW">
|
||||||
|
Not NSFW
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<div class="footer mt-4">
|
<div class="footer mt-4">
|
||||||
|
|
Loading…
Reference in New Issue