diff --git a/lib/algora/library.ex b/lib/algora/library.ex index f096866..079c705 100644 --- a/lib/algora/library.ex +++ b/lib/algora/library.ex @@ -411,6 +411,20 @@ defmodule Algora.Library do end end + def get_og_image_url(%Video{} = video) do + video.og_image_url || get_thumbnail_url(video) + end + + def get_og_image_url(%User{} = user) do + case get_latest_video(user) do + nil -> + get_thumbnail_url(user) + + video -> + get_og_image_url(video) + end + end + def reconcile_livestream(%Video{} = video, stream_key) do user = Accounts.get_user_by!(stream_key: stream_key) diff --git a/lib/algora/library/video.ex b/lib/algora/library/video.ex index e4c5a5f..a63ab74 100644 --- a/lib/algora/library/video.ex +++ b/lib/algora/library/video.ex @@ -18,6 +18,7 @@ defmodule Algora.Library.Video do field :is_live, :boolean, default: false field :thumbnail_url, :string field :vertical_thumbnail_url, :string + field :og_image_url, :string field :url, :string field :url_root, :string field :uuid, :string diff --git a/lib/algora_web/controllers/github_controller.ex b/lib/algora_web/controllers/github_controller.ex index 541201c..efcdc5c 100644 --- a/lib/algora_web/controllers/github_controller.ex +++ b/lib/algora_web/controllers/github_controller.ex @@ -6,7 +6,7 @@ defmodule AlgoraWeb.GithubController do def get_thumbnail(conn, %{"user_id" => user_id}) do case Accounts.get_user_by_provider_id(:github, user_id) do nil -> send_resp(conn, 404, "Not found") - user -> redirect(conn, external: Library.get_thumbnail_url(user)) + user -> redirect(conn, external: Library.get_og_image_url(user)) end end diff --git a/lib/algora_web/live/channel_live.ex b/lib/algora_web/live/channel_live.ex index 43f1984..c762ad7 100644 --- a/lib/algora_web/live/channel_live.ex +++ b/lib/algora_web/live/channel_live.ex @@ -319,7 +319,7 @@ defmodule AlgoraWeb.ChannelLive do socket |> assign(:page_title, socket.assigns.channel.name || params["channel_handle"]) |> assign(:page_description, socket.assigns.channel.tagline) - |> assign(:page_image, Library.get_thumbnail_url(user)) + |> assign(:page_image, Library.get_og_image_url(user)) end defp show_stream_modal(socket) do diff --git a/lib/algora_web/live/chat_live.ex b/lib/algora_web/live/chat_live.ex index 6dbfb1f..98ac199 100644 --- a/lib/algora_web/live/chat_live.ex +++ b/lib/algora_web/live/chat_live.ex @@ -184,6 +184,6 @@ defmodule AlgoraWeb.ChatLive do socket |> assign(:page_title, socket.assigns.channel.name || params["channel_handle"]) |> assign(:page_description, socket.assigns.video.title) - |> assign(:page_image, Library.get_thumbnail_url(socket.assigns.video)) + |> assign(:page_image, Library.get_og_image_url(socket.assigns.video)) end end diff --git a/lib/algora_web/live/embed_live.ex b/lib/algora_web/live/embed_live.ex index 843e3d4..c53246d 100644 --- a/lib/algora_web/live/embed_live.ex +++ b/lib/algora_web/live/embed_live.ex @@ -154,6 +154,6 @@ defmodule AlgoraWeb.EmbedLive do socket |> assign(:page_title, socket.assigns.channel.name || params["channel_handle"]) |> assign(:page_description, socket.assigns.video.title) - |> assign(:page_image, Library.get_thumbnail_url(socket.assigns.video)) + |> assign(:page_image, Library.get_og_image_url(socket.assigns.video)) end end diff --git a/lib/algora_web/live/video_live.ex b/lib/algora_web/live/video_live.ex index 69b383d..a5711d3 100644 --- a/lib/algora_web/live/video_live.ex +++ b/lib/algora_web/live/video_live.ex @@ -634,7 +634,7 @@ defmodule AlgoraWeb.VideoLive do socket |> assign(:page_title, socket.assigns.channel.name || params["channel_handle"]) |> assign(:page_description, socket.assigns.video.title) - |> assign(:page_image, Library.get_thumbnail_url(socket.assigns.video)) + |> assign(:page_image, Library.get_og_image_url(socket.assigns.video)) end defp show_stream_modal(socket) do diff --git a/priv/repo/migrations/20240509132227_add_og_image_url_to_video.exs b/priv/repo/migrations/20240509132227_add_og_image_url_to_video.exs new file mode 100644 index 0000000..368dd4d --- /dev/null +++ b/priv/repo/migrations/20240509132227_add_og_image_url_to_video.exs @@ -0,0 +1,9 @@ +defmodule Algora.Repo.Local.Migrations.AddOgImageUrlToVideo do + use Ecto.Migration + + def change do + alter table("videos") do + add :og_image_url, :string + end + end +end