From c171f9790bc2d6a1b215792ade1b1cfc7e458ac4 Mon Sep 17 00:00:00 2001 From: Jorty Date: Sat, 30 Jun 2018 17:20:08 -0400 Subject: [PATCH] Move emoji glob setting to config.exs Also, a bit of formatting, and the glob includes an "/emoji/" prefix to make it more intuitive to users --- config/config.exs | 2 + .../controllers/util_controller.ex | 37 +++++++++++-------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/config/config.exs b/config/config.exs index cf6cbaa9d..96350d064 100644 --- a/config/config.exs +++ b/config/config.exs @@ -12,6 +12,8 @@ config :pleroma, Pleroma.Repo, types: Pleroma.PostgresTypes config :pleroma, Pleroma.Upload, uploads: "uploads" +config :pleroma, :emoji, shortcode_glob: "/emoji/by-shortcode/**/*.png" + # Configures the endpoint config :pleroma, Pleroma.Web.Endpoint, url: [host: "localhost"], diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index db6142dc8..73a46bb5e 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -173,23 +173,30 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do end def emoji(conn, _params) do - emoji_dir = Path.join(:code.priv_dir(:pleroma), "static/emoji") - - shortcode_emoji_glob = - Path.join( - emoji_dir, - Application.get_env(:pleroma, :emoji, []) |> - Keyword.get(:glob, "by-shortcode/**/*.png") - ) + static_dir = Path.join(:code.priv_dir(:pleroma), "static") + + emoji_shortcode_glob = + Application.get_env(:pleroma, :emoji, []) + |> Keyword.get(:shortcode_glob) + shortcode_emoji = - Path.wildcard(shortcode_emoji_glob) |> - Enum.map(fn path -> - shortcode = Path.basename(path, ".png") - serve_path = Path.join("/emoji", Path.relative_to(path, emoji_dir)) - {shortcode, serve_path} - end) + case emoji_shortcode_glob do + nil -> + [] + + glob -> + Path.join(static_dir, glob) + |> Path.wildcard() + |> Enum.map(fn path -> + shortcode = Path.basename(path, ".png") + serve_path = Path.join("/", Path.relative_to(path, static_dir)) + {shortcode, serve_path} + end) + end - emoji = Enum.into(Formatter.get_custom_emoji(), shortcode_emoji) |> Enum.into(%{}) + emoji = + Enum.into(Formatter.get_custom_emoji(), shortcode_emoji) + |> Enum.into(%{}) json(conn, emoji) end -- 2.45.2