feat: Include images for certain chat messages
This commit is contained in:
parent
fdbf5b82e3
commit
f9102c4c27
2 changed files with 27 additions and 5 deletions
|
@ -105,11 +105,33 @@ defmodule BdfrBrowser.HTTP.Plug do
|
||||||
get "/media/*path" do
|
get "/media/*path" do
|
||||||
base_directory = Application.fetch_env!(:bdfr_browser, :base_directory)
|
base_directory = Application.fetch_env!(:bdfr_browser, :base_directory)
|
||||||
joined_path = Path.join(path)
|
joined_path = Path.join(path)
|
||||||
{:ok, media} = [base_directory, joined_path] |> Path.join() |> File.read()
|
file_path = Path.join([base_directory, joined_path])
|
||||||
|
|
||||||
|
if File.exists?(file_path) do
|
||||||
|
{:ok, media} = File.read(file_path)
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_resp_header("content-type", mime_from_ext(joined_path))
|
|> put_resp_header("content-type", mime_from_ext(file_path))
|
||||||
|> send_resp(200, media)
|
|> send_resp(200, media)
|
||||||
|
else
|
||||||
|
send_resp(conn, 404, "Not Found")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
get "/chat_media/*path" do
|
||||||
|
chat_directory = Application.fetch_env!(:bdfr_browser, :chat_directory)
|
||||||
|
joined_path = Path.join(path)
|
||||||
|
file_path = Path.join([chat_directory, "images", joined_path])
|
||||||
|
|
||||||
|
if File.exists?(file_path) do
|
||||||
|
{:ok, media} = File.read(file_path)
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> put_resp_header("content-type", mime_from_ext(file_path))
|
||||||
|
|> send_resp(200, media)
|
||||||
|
else
|
||||||
|
send_resp(conn, 404, "Not Found")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
post "/_import" do
|
post "/_import" do
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-body" style="padding: 8px;">
|
<div class="card-body" style="padding: 8px;">
|
||||||
<blockquote class="blockquote mb-0" style="font-size: 1rem;">
|
<blockquote class="blockquote mb-0" style="font-size: 1rem;">
|
||||||
<%= Earmark.as_html!(message.message) %>
|
<%= BdfrBrowser.RenderUtils.message(message.message) %>
|
||||||
|
|
||||||
<footer class="blockquote-footer">
|
<footer class="blockquote-footer">
|
||||||
<%= message.author %>,
|
<%= message.author %>,
|
||||||
|
|
Reference in a new issue