aboutsummaryrefslogtreecommitdiff
path: root/lib/waev_web/controllers/exports_controller.ex
blob: 764accfb2f809fbb4076d6c73fa2af5d4252227b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
defmodule WaevWeb.ExportsController do
  use WaevWeb, :controller

  def show(conn, %{"id" => id}) do
    case Waev.Export.get(id) do
      {:ok, export} ->
        render(conn, "show.html", id: id, export: export)

      :error ->
        conn
        |> put_status(:not_found)
        |> put_view(WaevWeb.ErrorView)
        |> render("404.html")
    end
  end

  def get_media(conn, %{"id" => id, "at_id" => at_id}) do
    case Waev.Export.Message.File.path(id, at_id) do
      {:ok, path} ->
        send_download(conn, {:file, path}, filename: at_id)

      :error ->
        conn
        |> put_status(:not_found)
        |> put_view(WaevWeb.ErrorView)
        |> render("404.html")
    end
  end
end