live_beats/lib/live_beats_web/controllers/file_controller.ex

14 lines
478 B
Elixir
Raw Normal View History

2021-11-06 03:02:31 +00:00
defmodule LiveBeatsWeb.FileController do
use LiveBeatsWeb, :controller
alias LiveBeats.MediaLibrary
def show(conn, %{"id" => filename_uuid, "token" => token}) do
case Phoenix.Token.verify(conn, "file", token, max_age: :timer.minutes(10)) do
{:ok, ^filename_uuid} -> send_file(conn, 200, MediaLibrary.local_filepath(filename_uuid))
{:ok, _} -> send_resp(conn, :unauthorized, "")
{:error, _} -> send_resp(conn, :unauthorized, "")
end
end
end