From 700df20260937f1843bc52e23126dd41ef725f4f Mon Sep 17 00:00:00 2001 From: ekzyis Date: Fri, 27 Dec 2024 19:34:36 +0100 Subject: [PATCH] Add QR code --- go.mod | 1 + go.sum | 2 ++ pages/overlay.templ | 21 ++++++++++++++++++++- pages/render.go | 6 ++++-- server/server.go | 5 ++++- 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index f702389..b9bdda0 100644 --- a/go.mod +++ b/go.mod @@ -11,6 +11,7 @@ require ( github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/namsral/flag v1.7.4-pre // indirect + github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v1.2.2 // indirect golang.org/x/crypto v0.31.0 // indirect diff --git a/go.sum b/go.sum index 7f22a5b..e3cc822 100644 --- a/go.sum +++ b/go.sum @@ -34,6 +34,8 @@ github.com/namsral/flag v1.7.4-pre/go.mod h1:OXldTctbM6SWH1K899kPZcf65KxJiD7Msce github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0= +github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo= diff --git a/pages/overlay.templ b/pages/overlay.templ index 7e51f3e..280ea44 100644 --- a/pages/overlay.templ +++ b/pages/overlay.templ @@ -1,6 +1,9 @@ package pages -templ Overlay() { +import "github.com/skip2/go-qrcode" +import "encoding/base64" + +templ Overlay(lnurl string) { @@ -25,6 +28,22 @@ templ Overlay() { }, 60_000) }) +
+ +
scan to zap message
+
} + +func qrEncode(value string) string { + q, err := qrcode.New(value, qrcode.Medium) + q.DisableBorder = true + + png, err := q.PNG(256) + if err != nil { + return "" + } + + return base64.StdEncoding.EncodeToString([]byte(png)) +} diff --git a/pages/render.go b/pages/render.go index ee64946..d61bb35 100644 --- a/pages/render.go +++ b/pages/render.go @@ -27,8 +27,10 @@ func GetEnv(ctx context.Context) string { return "development" } -func OverlayHandler(c echo.Context) error { - return render(c, http.StatusOK, Overlay()) +func OverlayHandler(lnurl string) echo.HandlerFunc { + return func(c echo.Context) error { + return render(c, http.StatusOK, Overlay(lnurl)) + } } func render(ctx echo.Context, statusCode int, t templ.Component) error { diff --git a/server/server.go b/server/server.go index 10ba75e..a4fe4ba 100644 --- a/server/server.go +++ b/server/server.go @@ -1,6 +1,7 @@ package server import ( + "fmt" "log" "net/url" @@ -44,7 +45,9 @@ func NewServer() *Server { s.Static("/", "public/") - s.GET("/overlay", pages.OverlayHandler) + s.GET("/overlay", pages.OverlayHandler( + lnurl.Encode(fmt.Sprintf("%s/.well-known/lnurlp/%s", env.PublicUrl, "SNL")), + )) s.GET("/overlay/sse", sseHandler(p.IncomingPayments())) return s