Handle empty shortcode/filename/new_shortcode/new_filename
This commit is contained in:
parent
9afe7258dd
commit
16edfef12e
|
@ -298,6 +298,8 @@ def update_file(
|
||||||
filename
|
filename
|
||||||
end
|
end
|
||||||
|
|
||||||
|
unless String.trim(shortcode) |> String.length() == 0 or
|
||||||
|
String.trim(filename) |> String.length() == 0 do
|
||||||
file_path = Path.join(pack_dir, filename)
|
file_path = Path.join(pack_dir, filename)
|
||||||
|
|
||||||
# If the name contains directories, create them
|
# If the name contains directories, create them
|
||||||
|
@ -311,6 +313,12 @@ def update_file(
|
||||||
updated_full_pack = put_in(full_pack, ["files", shortcode], filename)
|
updated_full_pack = put_in(full_pack, ["files", shortcode], filename)
|
||||||
|
|
||||||
{:ok, updated_full_pack}
|
{:ok, updated_full_pack}
|
||||||
|
else
|
||||||
|
{:error,
|
||||||
|
conn
|
||||||
|
|> put_status(:bad_request)
|
||||||
|
|> text("shortcode or filename cannot be empty")}
|
||||||
|
end
|
||||||
else
|
else
|
||||||
_ -> {:error, conn |> put_status(:bad_request) |> text("\"file\" not provided")}
|
_ -> {:error, conn |> put_status(:bad_request) |> text("\"file\" not provided")}
|
||||||
end
|
end
|
||||||
|
@ -348,6 +356,8 @@ def update_file(
|
||||||
"update" ->
|
"update" ->
|
||||||
if Map.has_key?(full_pack["files"], shortcode) do
|
if Map.has_key?(full_pack["files"], shortcode) do
|
||||||
with %{"new_shortcode" => new_shortcode, "new_filename" => new_filename} <- params do
|
with %{"new_shortcode" => new_shortcode, "new_filename" => new_filename} <- params do
|
||||||
|
unless String.trim(new_shortcode) |> String.length() == 0 or
|
||||||
|
String.trim(new_filename) |> String.length() == 0 do
|
||||||
# First, remove the old shortcode, saving the old path
|
# First, remove the old shortcode, saving the old path
|
||||||
{old_emoji_file_path, updated_full_pack} = pop_in(full_pack, ["files", shortcode])
|
{old_emoji_file_path, updated_full_pack} = pop_in(full_pack, ["files", shortcode])
|
||||||
old_emoji_file_path = Path.join(pack_dir, old_emoji_file_path)
|
old_emoji_file_path = Path.join(pack_dir, old_emoji_file_path)
|
||||||
|
@ -376,6 +386,12 @@ def update_file(
|
||||||
put_in(updated_full_pack, ["files", new_shortcode], new_filename)
|
put_in(updated_full_pack, ["files", new_shortcode], new_filename)
|
||||||
|
|
||||||
{:ok, updated_full_pack}
|
{:ok, updated_full_pack}
|
||||||
|
else
|
||||||
|
{:error,
|
||||||
|
conn
|
||||||
|
|> put_status(:bad_request)
|
||||||
|
|> text("new_shortcode or new_filename cannot be empty")}
|
||||||
|
end
|
||||||
else
|
else
|
||||||
_ ->
|
_ ->
|
||||||
{:error,
|
{:error,
|
||||||
|
|
Loading…
Reference in New Issue