forked from AkkomaGang/akkoma
When listing emoji packs, be sure to create the directory
This commit is contained in:
parent
a150664a0a
commit
cdbe7cd37a
1 changed files with 17 additions and 1 deletions
|
@ -17,7 +17,10 @@ defmodule Pleroma.Web.PleromaAPI.EmojiAPIController do
|
||||||
a map of "pack directory name" to pack.json contents.
|
a map of "pack directory name" to pack.json contents.
|
||||||
"""
|
"""
|
||||||
def list_packs(conn, _params) do
|
def list_packs(conn, _params) do
|
||||||
with {:ok, results} <- File.ls(@emoji_dir_path) do
|
# Create the directory first if it does not exist. This is probably the first request made
|
||||||
|
# with the API so it should be sufficient
|
||||||
|
with {:create_dir, :ok} <- {:create_dir, File.mkdir_p(@emoji_dir_path)},
|
||||||
|
{:ls, {:ok, results}} <- {:ls, File.ls(@emoji_dir_path)} do
|
||||||
pack_infos =
|
pack_infos =
|
||||||
results
|
results
|
||||||
|> Enum.filter(&has_pack_json?/1)
|
|> Enum.filter(&has_pack_json?/1)
|
||||||
|
@ -28,6 +31,19 @@ def list_packs(conn, _params) do
|
||||||
|> Enum.into(%{})
|
|> Enum.into(%{})
|
||||||
|
|
||||||
json(conn, pack_infos)
|
json(conn, pack_infos)
|
||||||
|
else
|
||||||
|
{:create_dir, {:error, e}} ->
|
||||||
|
conn
|
||||||
|
|> put_status(:internal_server_error)
|
||||||
|
|> json(%{error: "Failed to create the emoji pack directory at #{@emoji_dir_path}: #{e}"})
|
||||||
|
|
||||||
|
{:ls, {:error, e}} ->
|
||||||
|
conn
|
||||||
|
|> put_status(:internal_server_error)
|
||||||
|
|> json(%{
|
||||||
|
error:
|
||||||
|
"Failed to get the contents of the emoji pack directory at #{@emoji_dir_path}: #{e}"
|
||||||
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue