Add QR component
This commit is contained in:
parent
db23fbb64a
commit
9b8734f5a9
16
lib/qr.go
16
lib/qr.go
|
@ -1,16 +0,0 @@
|
|||
package lib
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
|
||||
"github.com/skip2/go-qrcode"
|
||||
)
|
||||
|
||||
func ToQR(s string) (string, error) {
|
||||
png, err := qrcode.Encode(s, qrcode.Medium, 256)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
qr := base64.StdEncoding.EncodeToString([]byte(png))
|
||||
return qr, nil
|
||||
}
|
|
@ -5,7 +5,6 @@ import (
|
|||
"net/http"
|
||||
"time"
|
||||
|
||||
"git.ekzyis.com/ekzyis/delphi.market/lib"
|
||||
"git.ekzyis.com/ekzyis/delphi.market/server/auth"
|
||||
"git.ekzyis.com/ekzyis/delphi.market/server/router/context"
|
||||
"git.ekzyis.com/ekzyis/delphi.market/server/router/pages"
|
||||
|
@ -41,7 +40,6 @@ func LnAuth(sc context.Context, c echo.Context, action string) error {
|
|||
sessionId string
|
||||
// sessions expire in 30 days. TODO: refresh sessions
|
||||
expires = time.Now().Add(60 * 60 * 24 * 30 * time.Second)
|
||||
qr string
|
||||
err error
|
||||
)
|
||||
|
||||
|
@ -56,10 +54,6 @@ func LnAuth(sc context.Context, c echo.Context, action string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if qr, err = lib.ToQR(lnAuth.LNURL); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c.SetCookie(&http.Cookie{
|
||||
Name: "session",
|
||||
HttpOnly: true,
|
||||
|
@ -69,7 +63,7 @@ func LnAuth(sc context.Context, c echo.Context, action string) error {
|
|||
Expires: expires,
|
||||
})
|
||||
|
||||
return pages.LnAuth(qr, lnAuth.LNURL, mapAction(action)).Render(context.RenderContext(sc, c), c.Response().Writer)
|
||||
return pages.LnAuth(lnAuth.LNURL, mapAction(action)).Render(context.RenderContext(sc, c), c.Response().Writer)
|
||||
}
|
||||
|
||||
func HandleLnAuthCallback(sc context.Context) echo.HandlerFunc {
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package components
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"github.com/skip2/go-qrcode"
|
||||
)
|
||||
|
||||
templ Qr(value string, href string) {
|
||||
if href != "" {
|
||||
<a
|
||||
class="mx-auto no-link"
|
||||
href={ templ.SafeURL(href) }
|
||||
>
|
||||
<img src={ "data:image/jpeg;base64," + qrEncode(value) }/>
|
||||
</a>
|
||||
} else {
|
||||
<img src={ "data:image/jpeg;base64," + qrEncode(value) }/>
|
||||
}
|
||||
}
|
||||
|
||||
func qrEncode(value string) string {
|
||||
png, err := qrcode.Encode(value, qrcode.Medium, 256)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return base64.StdEncoding.EncodeToString([]byte(png))
|
||||
}
|
|
@ -2,7 +2,7 @@ package pages
|
|||
|
||||
import "git.ekzyis.com/ekzyis/delphi.market/server/router/pages/components"
|
||||
|
||||
templ LnAuth(qr string, lnurl string, action string) {
|
||||
templ LnAuth(lnurl string, action string) {
|
||||
<html>
|
||||
@components.Head()
|
||||
<body class="container">
|
||||
|
@ -17,12 +17,7 @@ templ LnAuth(qr string, lnurl string, action string) {
|
|||
hx-select="#content"
|
||||
hx-push-url="true"
|
||||
>
|
||||
<a
|
||||
class="mx-auto no-link"
|
||||
href={ templ.SafeURL("lightning:" + lnurl) }
|
||||
>
|
||||
<img src={ "data:image/jpeg;base64," + qr }/>
|
||||
</a>
|
||||
@components.Qr(lnurl, "lightning:"+lnurl)
|
||||
<small class="mx-auto w-[256px] my-1 break-words">{ lnurl }</small>
|
||||
</div>
|
||||
<div hx-get="/session" hx-trigger="every 1s" hx-swap="none"></div>
|
||||
|
|
Loading…
Reference in New Issue