projects
/
akkoma
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
history
|
raw
|
HEAD
Validators: Correct ObjectID filename
[akkoma]
/
lib
/
pleroma
/
web
/
activity_pub
/
object_validators
/
types
/
object_id.ex
1
defmodule Pleroma.Web.ActivityPub.ObjectValidators.Types.ObjectID do
2
use Ecto.Type
3
4
def type, do: :string
5
6
def cast(object) when is_binary(object) do
7
with %URI{
8
scheme: scheme,
9
host: host
10
}
11
when scheme in ["https", "http"] and not is_nil(host) <-
12
URI.parse(object) do
13
{:ok, object}
14
else
15
_ ->
16
:error
17
end
18
end
19
20
def cast(%{"id" => object}), do: cast(object)
21
22
def cast(_) do
23
:error
24
end
25
26
def dump(data) do
27
{:ok, data}
28
end
29
30
def load(data) do
31
{:ok, data}
32
end
33
end