Add an endpoint for deleting emoji packs

This commit is contained in:
Ekaterina Vaartis 2019-08-12 18:03:59 +03:00
parent 3a8669b487
commit 2d4b8f3d20
3 changed files with 21 additions and 1 deletions

View file

@ -210,4 +210,16 @@ def download_from(conn, %{"instance_address" => address, "pack_name" => name} =
conn |> put_status(:internal_server_error) |> text(e)
end
end
def delete(conn, %{"name" => name}) do
pack_dir = Path.join(@emoji_dir_path, name)
case File.rm_rf(pack_dir) do
{:ok, _} ->
conn |> text("ok")
{:error, _} ->
conn |> put_status(:internal_server_error) |> text("Couldn't delete the pack #{name}")
end
end
end

View file

@ -218,6 +218,7 @@ defmodule Pleroma.Web.Router do
# Modifying packs
pipe_through([:admin_api, :oauth_write])
delete("/delete/:name", EmojiAPIController, :delete)
post("/download_from", EmojiAPIController, :download_from)
end

View file

@ -42,7 +42,7 @@ test "downloading a shared pack from download_shared" do
assert Enum.find(arch, fn {n, _} -> n == 'blank.png' end)
end
test "downloading a shared pack from another instance via download_from" do
test "downloading a shared pack from another instance via download_from, deleting it" do
on_exit(fn ->
File.rm_rf!("test/instance_static/emoji/test_pack2")
end)
@ -94,5 +94,12 @@ test "downloading a shared pack from another instance via download_from" do
assert File.exists?("test/instance_static/emoji/test_pack2/pack.yml")
assert File.exists?("test/instance_static/emoji/test_pack2/blank.png")
assert conn
|> assign(:user, admin)
|> delete(emoji_api_path(conn, :delete, "test_pack2"))
|> response(200) == "ok"
refute File.exists?("test/instance_static/emoji/test_pack2")
end
end