mirror of
https://github.com/algora-io/tv.git
synced 2024-11-26 01:00:20 +02:00
move thumbnail logic into library context
This commit is contained in:
parent
454db217d4
commit
d8e468f731
@ -396,6 +396,21 @@ defmodule Algora.Library do
|
||||
end
|
||||
end
|
||||
|
||||
def get_thumbnail_url(%Video{} = video) do
|
||||
video.thumbnail_url || "#{AlgoraWeb.Endpoint.url()}/images/og/default.png"
|
||||
end
|
||||
|
||||
def get_thumbnail_url(%User{} = user) do
|
||||
case get_latest_video(user) do
|
||||
# TODO:
|
||||
nil ->
|
||||
"#{AlgoraWeb.Endpoint.url()}/images/og/default.png"
|
||||
|
||||
video ->
|
||||
get_thumbnail_url(video)
|
||||
end
|
||||
end
|
||||
|
||||
def reconcile_livestream(%Video{} = video, stream_key) do
|
||||
user = Accounts.get_user_by!(stream_key: stream_key)
|
||||
|
||||
|
@ -4,43 +4,16 @@ defmodule AlgoraWeb.GithubController do
|
||||
alias Algora.{Accounts, Library}
|
||||
|
||||
def get_thumbnail(conn, %{"user_id" => user_id}) do
|
||||
with {:ok, user} <- get_user(user_id),
|
||||
{:ok, video} <- get_latest_video(user) do
|
||||
redirect(conn, external: get_thumbnail_url(video))
|
||||
else
|
||||
{:error, :video_not_found} -> redirect(conn, to: ~p"/images/og/default.png")
|
||||
_ -> send_resp(conn, 404, "Not found")
|
||||
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))
|
||||
end
|
||||
end
|
||||
|
||||
def get_channel(conn, %{"user_id" => user_id}) do
|
||||
case get_user(user_id) do
|
||||
{:ok, user} ->
|
||||
redirect(conn, to: ~p"/#{user.handle}")
|
||||
|
||||
_ ->
|
||||
send_resp(conn, 404, "Not found")
|
||||
end
|
||||
end
|
||||
|
||||
defp get_user(id) do
|
||||
case Accounts.get_user_by_provider_id(:github, id) do
|
||||
nil -> {:error, :user_not_found}
|
||||
user -> {:ok, user}
|
||||
end
|
||||
end
|
||||
|
||||
defp get_latest_video(user) do
|
||||
case Library.get_latest_video(user) do
|
||||
nil -> {:error, :video_not_found}
|
||||
user -> {:ok, user}
|
||||
end
|
||||
end
|
||||
|
||||
defp get_thumbnail_url(video) do
|
||||
case video.thumbnail_url do
|
||||
nil -> ~p"/images/og/default.png"
|
||||
url -> url
|
||||
case Accounts.get_user_by_provider_id(:github, user_id) do
|
||||
nil -> send_resp(conn, 404, "Not found")
|
||||
user -> redirect(conn, to: ~p"/#{user.handle}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user