From 8d352d2f05874dd9283360ed3dfc1fa7fc3e530d Mon Sep 17 00:00:00 2001 From: Guillermo Ramos Date: Mon, 10 Feb 2020 17:18:00 +0100 Subject: Fix the stuffs --- lib/waev_web/controllers/exports_controller.ex | 19 ++++++++++++++++--- lib/waev_web/router.ex | 1 + lib/waev_web/templates/exports/show.html.eex | 8 ++++---- 3 files changed, 21 insertions(+), 7 deletions(-) (limited to 'lib/waev_web') diff --git a/lib/waev_web/controllers/exports_controller.ex b/lib/waev_web/controllers/exports_controller.ex index 764accf..f2b6fb4 100644 --- a/lib/waev_web/controllers/exports_controller.ex +++ b/lib/waev_web/controllers/exports_controller.ex @@ -15,15 +15,28 @@ defmodule WaevWeb.ExportsController do end def get_media(conn, %{"id" => id, "at_id" => at_id}) do - case Waev.Export.Message.File.path(id, at_id) do - {:ok, path} -> + case Waev.Export.Message.File.media_path(id, at_id) do + nil -> + conn + |> put_status(:not_found) + |> put_view(WaevWeb.ErrorView) + |> render("404.html") + + path -> send_download(conn, {:file, path}, filename: at_id) + end + end - :error -> + def get_avatar(conn, %{"id" => id, "av_id" => av_id}) do + case Waev.Export.Party.avatar_path(id, av_id) do + nil -> conn |> put_status(:not_found) |> put_view(WaevWeb.ErrorView) |> render("404.html") + + path -> + send_download(conn, {:file, path}, filename: av_id) end end end diff --git a/lib/waev_web/router.ex b/lib/waev_web/router.ex index 1e9ed0f..29d1b20 100644 --- a/lib/waev_web/router.ex +++ b/lib/waev_web/router.ex @@ -20,6 +20,7 @@ defmodule WaevWeb.Router do # index,edit,new,show,create,update resources "/exports", ExportsController, only: [:show] get "/exports/:id/media/:at_id", ExportsController, :get_media + get "/exports/:id/avatars/:av_id", ExportsController, :get_avatar end # Other scopes may use custom stacks. diff --git a/lib/waev_web/templates/exports/show.html.eex b/lib/waev_web/templates/exports/show.html.eex index 265374a..4d7de74 100644 --- a/lib/waev_web/templates/exports/show.html.eex +++ b/lib/waev_web/templates/exports/show.html.eex @@ -1,9 +1,11 @@