diff options
author | marcin mikołajczak <git@mkljczk.pl> | 2022-02-06 17:41:15 +0100 |
---|---|---|
committer | marcin mikołajczak <git@mkljczk.pl> | 2022-02-06 17:41:15 +0100 |
commit | e473bcf7a0390584377d89ff68267a25fe31e44d (patch) | |
tree | 34686c246e9517ae9018175ffee93804935d59c0 /lib/pleroma/web/common_api | |
parent | 60deddb7e5b8bb10037cca6e6f11a5bbef298d39 (diff) | |
download | pleroma-e473bcf7a0390584377d89ff68267a25fe31e44d.tar.gz |
Max media attachment count
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
Diffstat (limited to 'lib/pleroma/web/common_api')
-rw-r--r-- | lib/pleroma/web/common_api/activity_draft.ex | 7 | ||||
-rw-r--r-- | lib/pleroma/web/common_api/utils.ex | 15 |
2 files changed, 21 insertions, 1 deletions
diff --git a/lib/pleroma/web/common_api/activity_draft.ex b/lib/pleroma/web/common_api/activity_draft.ex index b4e3e37ae..451d7323a 100644 --- a/lib/pleroma/web/common_api/activity_draft.ex +++ b/lib/pleroma/web/common_api/activity_draft.ex @@ -112,7 +112,12 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraft do defp attachments(%{params: params} = draft) do attachments = Utils.attachments_from_ids(params) - %__MODULE__{draft | attachments: attachments} + draft = %__MODULE__{draft | attachments: attachments} + + case Utils.validate_attachments_count(attachments) do + :ok -> draft + {:error, message} -> add_error(draft, message) + end end defp in_reply_to(%{params: %{in_reply_to_status_id: ""}} = draft), do: draft diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index b6feaf32a..5bba01cc4 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -492,4 +492,19 @@ defmodule Pleroma.Web.CommonAPI.Utils do {:error, dgettext("errors", "The status is over the character limit")} end end + + def validate_attachments_count([] = _attachments) do + :ok + end + + def validate_attachments_count(attachments) do + limit = Config.get([:instance, :max_media_attachments]) + count = length(attachments) + + if count <= limit do + :ok + else + {:error, dgettext("errors", "Too many attachments")} + end + end end |