summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>2023-05-17 17:12:21 +0200
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>2023-05-17 17:14:38 +0200
commitfb3335ffe287205274167d73a3124d2f811f2b6b (patch)
treec4c404a7ed364038cb5a762645741bceb952d84e /lib
parent3867b52aefdab5c26bcd4f58155b1370ee40e4dd (diff)
downloadpleroma-fb3335ffe287205274167d73a3124d2f811f2b6b.tar.gz
pleroma-fb3335ffe287205274167d73a3124d2f811f2b6b.zip
EctoType: Add BareUri
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/ecto_type/activity_pub/object_validators/bare_uri.ex23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/pleroma/ecto_type/activity_pub/object_validators/bare_uri.ex b/lib/pleroma/ecto_type/activity_pub/object_validators/bare_uri.ex
new file mode 100644
index 000000000..1038296e7
--- /dev/null
+++ b/lib/pleroma/ecto_type/activity_pub/object_validators/bare_uri.ex
@@ -0,0 +1,23 @@
+# 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.BareUri do
+ use Ecto.Type
+
+ def type, do: :string
+
+ def cast(uri) when is_binary(uri) do
+ case URI.parse(uri) do
+ %URI{scheme: nil} -> :error
+ %URI{} -> {:ok, uri}
+ _ -> :error
+ end
+ end
+
+ def cast(_), do: :error
+
+ def dump(data), do: {:ok, data}
+
+ def load(data), do: {:ok, data}
+end