mirror of
https://github.com/ash-project/ash_hq.git
synced 2024-09-20 21:33:10 +12:00
38 lines
856 B
Elixir
38 lines
856 B
Elixir
defmodule AshHqWeb.Components.Forum.Attachment do
|
|
@moduledoc "Renders an attachment"
|
|
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, _mime}}
|
|
<img src={@attachment.url} width={@attachment.width} height={@attachment.height}>
|
|
{#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
|