From 895c8d00eaa0e8999ab11f282a2680e43d36e208 Mon Sep 17 00:00:00 2001 From: Nicholas Date: Tue, 24 Sep 2024 12:10:59 +0200 Subject: [PATCH] bug: hide download button for audio codes without text to speech #348 (#349) --- .sobelow-skips | 4 ++- .../controllers/qr_code_controller.ex | 27 +++++++++---------- .../templates/qr_code/show.html.heex | 2 +- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/.sobelow-skips b/.sobelow-skips index 56db7bd..430b4e5 100644 --- a/.sobelow-skips +++ b/.sobelow-skips @@ -4,4 +4,6 @@ 76C7CB9B90E933C9501B18B9124BD05D A9D5553F8331410859AF88EF58EA9AE9 C15BCE8CAF49A8448E904E375BA0C396 -E9EC6059DDCABE1D610279F283E82FB1 \ No newline at end of file +E9EC6059DDCABE1D610279F283E82FB1 +11E74AEC6C2EA228E03C98EC061EA62B +FD9446AAA8E9DE3E789E3601040E6D52 \ No newline at end of file diff --git a/lib/qrstorage_web/controllers/qr_code_controller.ex b/lib/qrstorage_web/controllers/qr_code_controller.ex index e04b916..10a48c3 100644 --- a/lib/qrstorage_web/controllers/qr_code_controller.ex +++ b/lib/qrstorage_web/controllers/qr_code_controller.ex @@ -11,23 +11,22 @@ defmodule QrstorageWeb.QrCodeController do def audio_file(conn, %{"id" => id}) do qr_code = Repo.get!(QrCode, id) - case qr_code.content_type do - :recording -> + cond do + qr_code.content_type == :recording -> send_file(conn, qr_code) - :audio -> - if qr_code.audio_file != nil do - # old qr_codes will have the file stored in the database, so the field is populated. newer codes will need to access the object storage: - conn - |> put_resp_content_type(qr_code.audio_file_type, nil) - |> send_resp(200, qr_code.audio_file) - else - send_file(conn, qr_code) - end - - _ -> + qr_code.content_type == :audio && qr_code.audio_file != nil -> + # old qr_codes will have the file stored in the database, so the field is populated. newer codes will need to access the object storage: conn - |> send_resp(404, "qr code type does not have a audio file") + |> put_resp_content_type(qr_code.audio_file_type, nil) + |> send_resp(200, qr_code.audio_file) + + qr_code.content_type == :audio && qr_code.tts -> + send_file(conn, qr_code) + + true -> + conn + |> send_resp(404, "qr code type does not have an audio file") end end diff --git a/lib/qrstorage_web/templates/qr_code/show.html.heex b/lib/qrstorage_web/templates/qr_code/show.html.heex index 58b2b0c..9d81ca7 100644 --- a/lib/qrstorage_web/templates/qr_code/show.html.heex +++ b/lib/qrstorage_web/templates/qr_code/show.html.heex @@ -55,7 +55,7 @@ <% end %> -<%= if @qr_code.content_type == :audio do %> +<%= if @qr_code.content_type == :audio && @qr_code.tts do %>
<%= link(gettext("Download"),