summaryrefslogtreecommitdiff
path: root/lib/pleroma/ecto_type/activity_pub/object_validators/context_id.ex
blob: 88074926639b21d64e87ee3f9ac37b3e078a50e9 (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.Config

  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
    "#{Config.url()}/contexts/#{UUID.generate()}"
  end
end