Add QR code
This commit is contained in:
parent
56236d5409
commit
700df20260
1
go.mod
1
go.mod
|
@ -11,6 +11,7 @@ require (
|
||||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
github.com/namsral/flag v1.7.4-pre // 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/bytebufferpool v1.0.0 // indirect
|
||||||
github.com/valyala/fasttemplate v1.2.2 // indirect
|
github.com/valyala/fasttemplate v1.2.2 // indirect
|
||||||
golang.org/x/crypto v0.31.0 // indirect
|
golang.org/x/crypto v0.31.0 // indirect
|
||||||
|
|
2
go.sum
2
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.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||||
github.com/onsi/ginkgo v1.7.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/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 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||||
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
|
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package pages
|
package pages
|
||||||
|
|
||||||
templ Overlay() {
|
import "github.com/skip2/go-qrcode"
|
||||||
|
import "encoding/base64"
|
||||||
|
|
||||||
|
templ Overlay(lnurl string) {
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
|
@ -25,6 +28,22 @@ templ Overlay() {
|
||||||
}, 60_000)
|
}, 60_000)
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
<div class="bg-white fixed bottom-0 left-0 text-center p-3">
|
||||||
|
<img src={ "data:image/jpeg;base64," + qrEncode(lnurl) }/>
|
||||||
|
<div>scan to zap message</div>
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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))
|
||||||
|
}
|
||||||
|
|
|
@ -27,8 +27,10 @@ func GetEnv(ctx context.Context) string {
|
||||||
return "development"
|
return "development"
|
||||||
}
|
}
|
||||||
|
|
||||||
func OverlayHandler(c echo.Context) error {
|
func OverlayHandler(lnurl string) echo.HandlerFunc {
|
||||||
return render(c, http.StatusOK, Overlay())
|
return func(c echo.Context) error {
|
||||||
|
return render(c, http.StatusOK, Overlay(lnurl))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func render(ctx echo.Context, statusCode int, t templ.Component) error {
|
func render(ctx echo.Context, statusCode int, t templ.Component) error {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
|
@ -44,7 +45,9 @@ func NewServer() *Server {
|
||||||
|
|
||||||
s.Static("/", "public/")
|
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()))
|
s.GET("/overlay/sse", sseHandler(p.IncomingPayments()))
|
||||||
|
|
||||||
return s
|
return s
|
||||||
|
|
Loading…
Reference in New Issue