total rebase
[anni] / lib / pleroma / web / rich_media / parser / ttl / opengraph.ex
diff --git a/lib/pleroma/web/rich_media/parser/ttl/opengraph.ex b/lib/pleroma/web/rich_media/parser/ttl/opengraph.ex
new file mode 100644 (file)
index 0000000..b068896
--- /dev/null
@@ -0,0 +1,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.Opengraph do
+  @behaviour Pleroma.Web.RichMedia.Parser.TTL
+
+  @impl true
+  def ttl(%{"ttl" => ttl_string}, _url) when is_binary(ttl_string) do
+    try do
+      ttl = String.to_integer(ttl_string)
+      now = DateTime.utc_now() |> DateTime.to_unix()
+      now + ttl
+    rescue
+      _ -> nil
+    end
+  end
+
+  def ttl(_, _), do: nil
+end