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/file_store/local.ex

37 lines
842 B
Elixir

defmodule Asciinema.FileStore.Local do
@behaviour Asciinema.FileStore
import Plug.Conn
alias Plug.MIME
def serve_file(conn, path, nil) do
do_serve_file(conn, path)
end
def serve_file(conn, path, filename) do
conn
|> put_resp_header("content-disposition", "attachment; filename=#{filename}")
|> do_serve_file(path)
end
defp do_serve_file(conn, path) do
conn
|> put_resp_header("content-type", MIME.path(path))
|> send_file(200, base_path() <> path)
|> halt
end
def open(path) do
File.open(base_path() <> path, [:binary, :read])
end
def open(path, function) do
File.open(base_path() <> path, [:binary, :read], function)
end
defp config do
Application.get_env(:asciinema, Asciinema.FileStore.Local)
end
defp base_path do
Keyword.get(config(), :path)
end
end