You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
asciinema.org/lib/asciinema_web/controllers/asciicast_file_controller.ex

25 lines
638 B
Elixir

defmodule AsciinemaWeb.AsciicastFileController do
use AsciinemaWeb, :controller
alias Asciinema.Asciicasts
alias Asciinema.Asciicasts.Asciicast
def show(conn, %{"id" => id} = params) do
asciicast = Asciicasts.get_asciicast!(id)
path = Asciicast.json_store_path(asciicast)
filename = download_filename(asciicast, params)
file_store().serve_file(conn, path, filename)
end
defp download_filename(%Asciicast{id: id}, %{"dl" => _}) do
"asciicast-#{id}.json"
end
defp download_filename(_asciicast, _params) do
nil
end
defp file_store do
Application.get_env(:asciinema, :file_store)
end
end