aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/web/rich_media/parser/ttl.ex
blob: 7e56375ff727a876dabb125f0f3e0e81f16f7374 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.Web.RichMedia.Parser.TTL do
  @callback ttl(map(), String.t()) :: integer() | nil

  @spec process(map(), String.t()) :: {:ok, integer() | nil}
  def process(data, url) do
    [:rich_media, :ttl_setters]
    |> Pleroma.Config.get()
    |> Enum.reduce_while({:ok, nil}, fn
      module, acc ->
        case module.ttl(data, url) do
          ttl when is_number(ttl) -> {:halt, {:ok, ttl}}
          _ -> {:cont, acc}
        end
    end)
  end
end