Max media attachment count
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
60deddb7e5
commit
e473bcf7a0
6 changed files with 58 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue