Skip to content

Commit

Permalink
bug: hide download button for audio codes without text to speech #348 (
Browse files Browse the repository at this point in the history
  • Loading branch information
nwittstruck authored Sep 24, 2024
1 parent 81c8825 commit 895c8d0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
4 changes: 3 additions & 1 deletion .sobelow-skips
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
76C7CB9B90E933C9501B18B9124BD05D
A9D5553F8331410859AF88EF58EA9AE9
C15BCE8CAF49A8448E904E375BA0C396
E9EC6059DDCABE1D610279F283E82FB1
E9EC6059DDCABE1D610279F283E82FB1
11E74AEC6C2EA228E03C98EC061EA62B
FD9446AAA8E9DE3E789E3601040E6D52
27 changes: 13 additions & 14 deletions lib/qrstorage_web/controllers/qr_code_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/qrstorage_web/templates/qr_code/show.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<% end %>
</div>

<%= if @qr_code.content_type == :audio do %>
<%= if @qr_code.content_type == :audio && @qr_code.tts do %>
<div class="row mt-3">
<div class="col">
<%= link(gettext("Download"),
Expand Down

0 comments on commit 895c8d0

Please sign in to comment.