Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F33095796
tag_validator.ex
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
tag_validator.ex
View Options
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule
Pleroma.Web.ActivityPub.ObjectValidators.TagValidator
do
use
Ecto.Schema
alias
Pleroma.EctoType.ActivityPub.ObjectValidators
import
Ecto.Changeset
require
Pleroma.Constants
@primary_key
false
embedded_schema
do
# Common
field
(
:type
,
:string
)
field
(
:name
,
:string
)
# Mention, Hashtag, Link
field
(
:href
,
ObjectValidators.Uri
)
# Link
field
(
:mediaType
,
:string
)
# Emoji
embeds_one
:icon
,
IconObjectValidator
,
primary_key
:
false
do
field
(
:type
,
:string
)
field
(
:url
,
ObjectValidators.Uri
)
end
field
(
:updated
,
ObjectValidators.DateTime
)
field
(
:id
,
ObjectValidators.Uri
)
end
def
cast_and_validate
(
data
)
do
data
|>
cast_data
()
end
def
cast_data
(
data
)
do
%
__MODULE__
{}
|>
changeset
(
data
)
end
def
changeset
(
struct
,
%{
"type"
=>
"Mention"
}
=
data
)
do
struct
|>
cast
(
data
,
[
:type
,
:name
,
:href
])
|>
validate_required
([
:type
,
:href
])
end
def
changeset
(
struct
,
%{
"type"
=>
"Hashtag"
,
"name"
=>
name
}
=
data
)
do
name
=
cond
do
"
#
"
<>
name
->
name
name
->
name
end
|>
String
.
downcase
()
data
=
Map
.
put
(
data
,
"name"
,
name
)
struct
|>
cast
(
data
,
[
:type
,
:name
,
:href
])
|>
validate_required
([
:type
,
:name
])
end
def
changeset
(
struct
,
%{
"type"
=>
"Emoji"
}
=
data
)
do
data
=
Map
.
put
(
data
,
"name"
,
String
.
trim
(
data
[
"name"
],
":"
))
struct
|>
cast
(
data
,
[
:type
,
:name
,
:updated
,
:id
])
|>
cast_embed
(
:icon
,
with
:
&
icon_changeset
/
2
)
|>
validate_required
([
:type
,
:name
,
:icon
])
end
def
changeset
(
struct
,
%{
"type"
=>
"Link"
}
=
data
)
do
struct
|>
cast
(
data
,
[
:type
,
:name
,
:mediaType
,
:href
])
|>
validate_inclusion
(
:mediaType
,
Pleroma.Constants
.
activity_json_mime_types
())
|>
validate_required
([
:type
,
:href
,
:mediaType
])
end
def
changeset
(
struct
,
%{
"type"
=>
_
}
=
data
)
do
struct
|>
cast
(
data
,
[])
|>
Map
.
put
(
:action
,
:ignore
)
end
def
icon_changeset
(
struct
,
data
)
do
struct
|>
cast
(
data
,
[
:type
,
:url
])
|>
validate_inclusion
(
:type
,
~w[Image]
)
|>
validate_required
([
:type
,
:url
])
end
end
File Metadata
Details
Attached
Mime Type
text/x-ruby
Expires
Tue, Jan 20, 9:41 AM (1 d, 13 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
964014
Default Alt Text
tag_validator.ex (2 KB)
Attached To
Mode
rPUBE pleroma-upstream
Attached
Detach File
Event Timeline
Log In to Comment