projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge remote-tracking branch 'remotes/origin/develop' into automatic-authentication...
[akkoma]
/
lib
/
pleroma
/
web
/
pleroma_api
/
controllers
/
emoji_api_controller.ex
diff --git
a/lib/pleroma/web/pleroma_api/controllers/emoji_api_controller.ex
b/lib/pleroma/web/pleroma_api/controllers/emoji_api_controller.ex
index 69dfa92e3c87e617390ad73a827854ed48ad0d26..e01825b48b28b9374f8d949c749a5f7bb3621b57 100644
(file)
--- a/
lib/pleroma/web/pleroma_api/controllers/emoji_api_controller.ex
+++ b/
lib/pleroma/web/pleroma_api/controllers/emoji_api_controller.ex
@@
-1,6
+1,7
@@
defmodule Pleroma.Web.PleromaAPI.EmojiAPIController do
use Pleroma.Web, :controller
defmodule Pleroma.Web.PleromaAPI.EmojiAPIController do
use Pleroma.Web, :controller
+ alias Pleroma.Plugs.ExpectPublicOrAuthenticatedCheckPlug
alias Pleroma.Plugs.OAuthScopesPlug
require Logger
alias Pleroma.Plugs.OAuthScopesPlug
require Logger
@@
-11,17
+12,20
@@
defmodule Pleroma.Web.PleromaAPI.EmojiAPIController do
when action in [
:create,
:delete,
when action in [
:create,
:delete,
- :download_from,
- :list_from,
+ :save_from,
:import_from_fs,
:update_file,
:update_metadata
]
)
:import_from_fs,
:update_file,
:update_metadata
]
)
- plug(Pleroma.Plugs.EnsurePublicOrAuthenticatedPlug)
+ plug(
+ :skip_plug,
+ [OAuthScopesPlug, ExpectPublicOrAuthenticatedCheckPlug]
+ when action in [:download_shared, :list_packs, :list_from]
+ )
- def emoji_dir_path do
+ def
p
emoji_dir_path do
Path.join(
Pleroma.Config.get!([:instance, :static_dir]),
"emoji"
Path.join(
Pleroma.Config.get!([:instance, :static_dir]),
"emoji"
@@
-52,7
+56,7
@@
defmodule Pleroma.Web.PleromaAPI.EmojiAPIController do
@doc """
Lists the packs available on the instance as JSON.
@doc """
Lists the packs available on the instance as JSON.
- The information is public and does not require authenti
fi
cation. The format is
+ The information is public and does not require authentication. The format is
a map of "pack directory name" to pack.json contents.
"""
def list_packs(conn, _params) do
a map of "pack directory name" to pack.json contents.
"""
def list_packs(conn, _params) do
@@
-212,13
+216,13
@@
keeping it in cache for #{div(cache_ms, 1000)}s")
end
@doc """
end
@doc """
- An admin endpoint to request downloading a pack named `pack_name` from the instance
+ An admin endpoint to request downloading a
nd storing a
pack named `pack_name` from the instance
`instance_address`.
If the requested instance's admin chose to share the pack, it will be downloaded
from that instance, otherwise it will be downloaded from the fallback source, if there is one.
"""
`instance_address`.
If the requested instance's admin chose to share the pack, it will be downloaded
from that instance, otherwise it will be downloaded from the fallback source, if there is one.
"""
- def
download
_from(conn, %{"instance_address" => address, "pack_name" => name} = data) do
+ def
save
_from(conn, %{"instance_address" => address, "pack_name" => name} = data) do
address = String.trim(address)
if shareable_packs_available(address) do
address = String.trim(address)
if shareable_packs_available(address) do
@@
-323,7
+327,7
@@
keeping it in cache for #{div(cache_ms, 1000)}s")
{:ok, _} ->
conn |> json("ok")
{:ok, _} ->
conn |> json("ok")
- {:error, _} ->
+ {:error, _
, _
} ->
conn
|> put_status(:internal_server_error)
|> json(%{error: "Couldn't delete the pack #{name}"})
conn
|> put_status(:internal_server_error)
|> json(%{error: "Couldn't delete the pack #{name}"})
@@
-573,11
+577,14
@@
keeping it in cache for #{div(cache_ms, 1000)}s")
assumed to be emojis and stored in the new `pack.json` file.
"""
def import_from_fs(conn, _params) do
assumed to be emojis and stored in the new `pack.json` file.
"""
def import_from_fs(conn, _params) do
- with {:ok, results} <- File.ls(emoji_dir_path()) do
+ emoji_path = emoji_dir_path()
+
+ with {:ok, %{access: :read_write}} <- File.stat(emoji_path),
+ {:ok, results} <- File.ls(emoji_path) do
imported_pack_names =
results
|> Enum.filter(fn file ->
imported_pack_names =
results
|> Enum.filter(fn file ->
- dir_path = Path.join(emoji_
dir_path()
, file)
+ dir_path = Path.join(emoji_
path
, file)
# Find the directories that do NOT have pack.json
File.dir?(dir_path) and not File.exists?(Path.join(dir_path, "pack.json"))
end)
# Find the directories that do NOT have pack.json
File.dir?(dir_path) and not File.exists?(Path.join(dir_path, "pack.json"))
end)
@@
-585,6
+592,11
@@
keeping it in cache for #{div(cache_ms, 1000)}s")
json(conn, imported_pack_names)
else
json(conn, imported_pack_names)
else
+ {:ok, %{access: _}} ->
+ conn
+ |> put_status(:internal_server_error)
+ |> json(%{error: "Error: emoji pack directory must be writable"})
+
{:error, _} ->
conn
|> put_status(:internal_server_error)
{:error, _} ->
conn
|> put_status(:internal_server_error)