summaryrefslogtreecommitdiff
path: root/lib/pleroma/ecto_type/activity_pub/object_validators/context_id.ex
blob: 15f47d45f053ac16e5e37d1265cf0cc5bf27de4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Pleroma: A lightweight social networking server
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.ContextID do
  use Ecto.Type

  alias Ecto.UUID
  alias Pleroma.Web.Endpoint

  def type, do: :string

  def cast(context) when is_binary(context), do: {:ok, context}

  def cast(_), do: :error

  def dump(data), do: {:ok, data}

  def load(data), do: {:ok, data}

  def autogenerate do
    "#{Endpoint.url()}/contexts/#{UUID.generate()}"
  end
end