Open ryvasquez opened 1 year ago
This could also be helpful for download actions. In my case I want to generate a qr code and sent it as an download to the user.
def resource_actions(_conn) do
[
generate_qr_code: %{name: "Generate QR Code", action: fn c, p -> generate_qr_code(c, p) end}
]
end
defp generate_qr_code(conn, product) do
filename = "qr-product_id-#{product.id}.png"
filepath = "/tmp/#{filename}"
unverified_url(conn, "/admin/inventory/physical_product_variant/#{product.id}")
|> QRCode.create(:high)
|> QRCode.render(:png)
|> QRCode.save(filepath)
conn
|> put_resp_header(
"content-disposition",
~s(attachment; filename="#{filename}")
)
|> send_download({:file, filepath})
end
@aesmail any feedback on the request? 🙂 apologies for constantly pinging 🙇♂️
Describe the problem you're proposing to solve
So I have a action in
resource_actions
that requires redirect to some internal page after performing the actionHowever
action
only accepts{:ok, record} | {:error, changeset} | {:error, record, custom_error}
as a return value, and if you modify with theconn
it will successfully redirect but raise an error something likeDescribe the solution you'd like
Maybe we can pattern match a
Plug.Conn
in this part https://github.com/aesmail/kaffy/blob/c0b16cafe085638e198c7a4ad3e3afe0c31a2076/lib/kaffy_web/controllers/resource_controller.ex#L326-L337and return as is since it was a conn.
Let me know if this is a valid solution, Im happy to work on it 👍
Describe alternatives you've considered
Additional context Add any other context or screenshots about the feature request here.