ash_hq/lib/ash_hq_web/components/forum/attachment.ex

37 lines
733 B
Elixir

defmodule AshHqWeb.Components.Forum.Attachment do
use Surface.Component
prop attachment, :any, required: true
def render(assigns) do
~F"""
<div>
{#case video_type(@attachment.filename)}
{#match {:video, mime}}
<video controls width={@attachment.width} height={@attachment.height}>
<source src={@attachment.url} type={mime}>
</video>
{#match :image}
image
{#match _}
other
{/case}
</div>
"""
end
defp video_type(path) do
mime = MIME.from_path(path)
case mime do
"image/" <> _ ->
{:image, mime}
"video/" <> _ ->
{:video, mime}
_ ->
{:other, mime}
end
end
end