Add a video thumbnail to the OpenGraph metadata if Media Preview Proxy is enabled.
authorMark Felder <feld@feld.me>
Wed, 9 Jun 2021 15:02:41 +0000 (10:02 -0500)
committerMark Felder <feld@feld.me>
Wed, 9 Jun 2021 15:02:41 +0000 (10:02 -0500)
lib/pleroma/web/metadata/providers/open_graph.ex

index 75d1552369236621b1a613b4344a030303713a03..332684782a49df192657cdd335565a38b784ddc2 100644 (file)
@@ -96,6 +96,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do
                 | acc
               ]
               |> maybe_add_dimensions(url)
+              |> maybe_add_video_thumbnail(url)
 
             _ ->
               acc
@@ -124,4 +125,18 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do
         metadata
     end
   end
+
+  defp maybe_add_video_thumbnail(url, metadata) do
+    cond do
+      Pleroma.Config.get([:media_preview_proxy, :enabled], false) ->
+        [
+          {:meta, [property: "og:image:width", content: "#{url["width"]}"], []},
+          {:meta, [property: "og:image:height", content: "#{url["height"]}"], []},
+          {:meta, [property: "og:image", content: MediaProxy.preview_url(url["href"])], []}
+        ]
+
+      true ->
+        metadata
+    end
+  end
 end