Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F33101542
content_language_map.ex
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
content_language_map.ex
View Options
# Pleroma: A lightweight social networking server
# Copyright © 2017-2023 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule
Pleroma.EctoType.ActivityPub.ObjectValidators.ContentLanguageMap
do
use
Ecto.Type
import
Pleroma.EctoType.ActivityPub.ObjectValidators.LanguageCode
,
only
:
[
good_locale_code?
:
1
]
def
type
,
do
:
:map
def
cast
(%{}
=
object
)
do
with
{
status
,
%{}
=
data
}
when
status
in
[
:modified
,
:ok
]
<-
validate_map
(
object
)
do
{
:ok
,
data
}
else
{
_
,
nil
}
->
{
:ok
,
nil
}
{
:error
,
_
}
->
:error
end
end
def
cast
(
_
),
do
:
:error
def
dump
(
data
),
do
:
{
:ok
,
data
}
def
load
(
data
),
do
:
{
:ok
,
data
}
defp
validate_map
(%{}
=
object
)
do
{
status
,
data
}
=
object
|>
Enum
.
reduce
({
:ok
,
%{}},
fn
{
lang
,
value
},
{
status
,
acc
}
when
is_binary
(
lang
)
and
is_binary
(
value
)
->
if
good_locale_code?
(
lang
)
do
{
status
,
Map
.
put
(
acc
,
lang
,
value
)}
else
{
:modified
,
acc
}
end
_
,
{
_status
,
acc
}
->
{
:modified
,
acc
}
end
)
if
data
==
%{}
do
{
status
,
nil
}
else
{
status
,
data
}
end
end
end
File Metadata
Details
Attached
Mime Type
text/x-ruby
Expires
Tue, Jan 20, 12:27 PM (1 d, 14 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
972052
Default Alt Text
content_language_map.ex (1 KB)
Attached To
Mode
rPUBE pleroma-upstream
Attached
Detach File
Event Timeline
Log In to Comment