Use respond_to for request formats
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
Râu Cao 2023-06-13 12:30:38 +02:00
parent 07fe8dba71
commit 332ad757a5
Signed by: raucao
GPG Key ID: 15E65F399D084BA9

View File

@ -17,39 +17,40 @@ class Services::LightningController < ApplicationController
end end
def qr_lnurlp def qr_lnurlp
lnurlp_url = "https://kosmos.org/.well-known/lnurlp/#{current_user.cn}" respond_to do |format|
lnurlp_bech32 = Lnurl.new(lnurlp_url).to_bech32 lnurlp_url = "https://kosmos.org/.well-known/lnurlp/#{current_user.cn}"
qr_code = RQRCode::QRCode.new("lightning:" + lnurlp_bech32) lnurlp_bech32 = Lnurl.new(lnurlp_url).to_bech32
qr_code = RQRCode::QRCode.new("lightning:" + lnurlp_bech32)
if params[:format] == "svg" format.svg do
qr_svg = qr_code.as_svg( qr_svg = qr_code.as_svg(
color: "000", color: "000",
shape_rendering: "crispEdges", shape_rendering: "crispEdges",
module_size: 6, module_size: 6,
standalone: true, standalone: true,
use_path: true, use_path: true,
svg_attributes: { svg_attributes: {
class: 'inline-block' class: 'inline-block'
} }
) )
send_data( send_data(
qr_svg, qr_svg,
filename: "bitcoin-lightning-#{current_user.address}.svg", filename: "bitcoin-lightning-#{current_user.address}.svg",
type: "image/svg+xml" type: "image/svg+xml"
) )
elsif params[:format] == "png" end
qr_png = qr_code.as_png( format.png do
fill: "white", qr_png = qr_code.as_png(
color: "black", fill: "white",
size: 1024, color: "black",
) size: 1024,
send_data( )
qr_png, send_data(
filename: "bitcoin-lightning-#{current_user.address}.png", qr_png,
type: "image/png" filename: "bitcoin-lightning-#{current_user.address}.png",
) type: "image/png"
else )
http_status :not_found end
end end
end end