put name change first so file change can work correctly if they're both changed

pull/216/head
Aevann 2023-10-17 20:11:16 +03:00
parent 29bbe8ced0
commit 68c610dd3e
1 changed files with 10 additions and 9 deletions

View File

@ -466,6 +466,16 @@ def update_emoji(v):
updated = False
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
name = existing.name
if file:
if g.is_tor:
abort(400, "Image uploads are not allowed through TOR!")
@ -496,15 +506,6 @@ def update_emoji(v):
existing.kind = kind
updated = True
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):
abort(400, "Invalid tags!")