@ -2,9 +2,10 @@
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.ObjectValidators.AudioV alidator do
defmodule Pleroma.Web.ActivityPub.ObjectValidators.AudioV ideoV alidator do
use Ecto.Schema
use Ecto.Schema
alias Pleroma.EarmarkRenderer
alias Pleroma.EctoType.ActivityPub.ObjectValidators
alias Pleroma.EctoType.ActivityPub.ObjectValidators
alias Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidator
alias Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidator
alias Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes
alias Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes
@ -25,14 +26,19 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AudioValidator do
# TODO: Write type
# TODO: Write type
field ( :tag , { :array , :map } , default : [ ] )
field ( :tag , { :array , :map } , default : [ ] )
field ( :type , :string )
field ( :type , :string )
field ( :name , :string )
field ( :summary , :string )
field ( :content , :string )
field ( :content , :string )
field ( :context , :string )
field ( :context , :string )
# short identifier for PleromaFE to group statuses by context
field ( :context_id , :integer )
# TODO: Remove actor on objects
# TODO: Remove actor on objects
field ( :actor , ObjectValidators.ObjectID )
field ( :actor , ObjectValidators.ObjectID )
field ( :attributedTo , ObjectValidators.ObjectID )
field ( :attributedTo , ObjectValidators.ObjectID )
field ( :summary , :string )
field ( :published , ObjectValidators.DateTime )
field ( :published , ObjectValidators.DateTime )
field ( :emoji , ObjectValidators.Emoji , default : %{ } )
field ( :emoji , ObjectValidators.Emoji , default : %{ } )
field ( :sensitive , :boolean , default : false )
field ( :sensitive , :boolean , default : false )
@ -40,10 +46,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AudioValidator do
field ( :replies_count , :integer , default : 0 )
field ( :replies_count , :integer , default : 0 )
field ( :like_count , :integer , default : 0 )
field ( :like_count , :integer , default : 0 )
field ( :announcement_count , :integer , default : 0 )
field ( :announcement_count , :integer , default : 0 )
field ( :inReplyTo , :string )
field ( :inReplyTo , ObjectValidators.ObjectID )
field ( :url , ObjectValidators.Uri )
field ( :url , ObjectValidators.Uri )
# short identifier for PleromaFE to group statuses by context
field ( :context_id , :integer )
field ( :likes , { :array , :string } , default : [ ] )
field ( :likes , { :array , :string } , default : [ ] )
field ( :announcements , { :array , :string } , default : [ ] )
field ( :announcements , { :array , :string } , default : [ ] )
@ -68,9 +72,18 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AudioValidator do
defp fix_url ( %{ " url " = > url } = data ) when is_list ( url ) do
defp fix_url ( %{ " url " = > url } = data ) when is_list ( url ) do
attachment =
attachment =
Enum . find ( url , fn x -> is_map ( x ) and String . starts_with? ( x [ " mimeType " ] , " audio/ " ) end )
Enum . find ( url , fn x ->
mime_type = x [ " mimeType " ] || x [ " mediaType " ] || " "
is_map ( x ) and String . starts_with? ( mime_type , [ " video/ " , " audio/ " ] )
end )
link_element = Enum . find ( url , fn x -> is_map ( x ) and x [ " mimeType " ] == " text/html " end )
link_element =
Enum . find ( url , fn x ->
mime_type = x [ " mimeType " ] || x [ " mediaType " ] || " "
is_map ( x ) and mime_type == " text/html "
end )
data
data
|> Map . put ( " attachment " , [ attachment ] )
|> Map . put ( " attachment " , [ attachment ] )
@ -79,12 +92,26 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AudioValidator do
defp fix_url ( data ) , do : data
defp fix_url ( data ) , do : data
defp fix_content ( %{ " mediaType " = > " text/markdown " , " content " = > content } = data )
when is_binary ( content ) do
content =
content
|> Earmark . as_html! ( % Earmark.Options { renderer : EarmarkRenderer } )
|> Pleroma.HTML . filter_tags ( )
Map . put ( data , " content " , content )
end
defp fix_content ( data ) , do : data
defp fix ( data ) do
defp fix ( data ) do
data
data
|> CommonFixes . fix_defaults ( )
|> CommonFixes . fix_defaults ( )
|> CommonFixes . fix_attribution ( )
|> CommonFixes . fix_attribution ( )
|> CommonFixes . fix_actor ( )
|> Transmogrifier . fix_emoji ( )
|> Transmogrifier . fix_emoji ( )
|> fix_url ( )
|> fix_url ( )
|> fix_content ( )
end
end
def changeset ( struct , data ) do
def changeset ( struct , data ) do
@ -97,7 +124,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AudioValidator do
def validate_data ( data_cng ) do
def validate_data ( data_cng ) do
data_cng
data_cng
|> validate_inclusion ( :type , [ " Audio " ])
|> validate_inclusion ( :type , [ " Audio " , " Video " ])
|> validate_required ( [ :id , :actor , :attributedTo , :type , :context , :attachment ] )
|> validate_required ( [ :id , :actor , :attributedTo , :type , :context , :attachment ] )
|> CommonValidations . validate_any_presence ( [ :cc , :to ] )
|> CommonValidations . validate_any_presence ( [ :cc , :to ] )
|> CommonValidations . validate_fields_match ( [ :actor , :attributedTo ] )
|> CommonValidations . validate_fields_match ( [ :actor , :attributedTo ] )