config: allow for accepted post formats to be configured
authorWilliam Pitcock <nenolod@dereferenced.org>
Fri, 5 Oct 2018 21:02:17 +0000 (21:02 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Fri, 5 Oct 2018 21:02:17 +0000 (21:02 +0000)
config/config.exs
lib/pleroma/web/common_api/common_api.ex

index c3094eb2b16796b17ebbe574f54071e3e02a37cd..608c035b00b9ae2af84fdde1ca8fc67d2e3c5337 100644 (file)
@@ -74,7 +74,12 @@ config :pleroma, :instance,
   rewrite_policy: Pleroma.Web.ActivityPub.MRF.NoOpPolicy,
   public: true,
   quarantined_instances: [],
-  managed_config: true
+  managed_config: true,
+  allowed_post_formats: [
+    "text/plain",
+    "text/html",
+    "text/markdown"
+  ]
 
 config :pleroma, :markup,
   # XXX - unfortunately, inline images must be enabled by default right now, because
index 2ab50c9682be485489ac21d94bdde4133da04c5d..d4a973e360446276fa396517679a9c392ccaaaee 100644 (file)
@@ -73,6 +73,11 @@ defmodule Pleroma.Web.CommonAPI do
   def get_visibility(_), do: "public"
 
   @instance Application.get_env(:pleroma, :instance)
+  @allowed_post_formats Keyword.get(@instance, :allowed_post_formats)
+
+  defp get_content_type(content_type) when content_type in @allowed_post_formats, do: content_type
+  defp get_content_type(_), do: "text/plain"
+
   @limit Keyword.get(@instance, :limit)
   def post(user, %{"status" => status} = data) do
     visibility = get_visibility(data)
@@ -90,7 +95,7 @@ defmodule Pleroma.Web.CommonAPI do
              mentions,
              attachments,
              tags,
-             data["content_type"] || "text/plain",
+             get_content_type(data["content_type"]),
              data["no_attachment_links"]
            ),
          context <- make_context(inReplyTo),