From 14fa5a3911f1f55008dcb22f1fd9037c52d18615 Mon Sep 17 00:00:00 2001 From: Tim Mecklem Date: Wed, 30 May 2018 11:39:40 -0400 Subject: [PATCH] Add QR code library and address QR code controller --- .../explorer_web/controllers/address_qr_code_controller.ex | 7 +++++++ apps/explorer_web/lib/explorer_web/router.ex | 2 ++ .../lib/explorer_web/templates/address/overview.html.eex | 2 +- apps/explorer_web/mix.exs | 3 ++- mix.lock | 1 + 5 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 apps/explorer_web/lib/explorer_web/controllers/address_qr_code_controller.ex diff --git a/apps/explorer_web/lib/explorer_web/controllers/address_qr_code_controller.ex b/apps/explorer_web/lib/explorer_web/controllers/address_qr_code_controller.ex new file mode 100644 index 0000000000..73331d7abb --- /dev/null +++ b/apps/explorer_web/lib/explorer_web/controllers/address_qr_code_controller.ex @@ -0,0 +1,7 @@ +defmodule ExplorerWeb.AddressQRCodeController do + use ExplorerWeb, :controller + + def index(conn, %{"address_id" => id}) do + send_download(conn, {:binary, QRCode.to_png(id)}, "content-type": "image/png", filename: "#{id}.png") + end +end diff --git a/apps/explorer_web/lib/explorer_web/router.ex b/apps/explorer_web/lib/explorer_web/router.ex index a5e137d319..efe52f0ba7 100644 --- a/apps/explorer_web/lib/explorer_web/router.ex +++ b/apps/explorer_web/lib/explorer_web/router.ex @@ -80,6 +80,8 @@ defmodule ExplorerWeb.Router do only: [:index], as: :contract ) + + resources("/qrcode", AddressQRCodeController, only: [:index], as: :qr_code) end get("/search", ChainController, :search) diff --git a/apps/explorer_web/lib/explorer_web/templates/address/overview.html.eex b/apps/explorer_web/lib/explorer_web/templates/address/overview.html.eex index 7bb248f0cf..ee5072f804 100644 --- a/apps/explorer_web/lib/explorer_web/templates/address/overview.html.eex +++ b/apps/explorer_web/lib/explorer_web/templates/address/overview.html.eex @@ -69,7 +69,7 @@ - qr_code + <%= img_tag(address_qr_code_path(@conn, :index, @conn.assigns.locale, @address), alt: "qr_code") %>