Add configuration property for thumbnail directory used in LNURL-pay metadata

This commit is contained in:
yanas 2022-10-09 19:04:53 +02:00
parent 4d4fe33103
commit 7348039a6f
3 changed files with 43 additions and 2 deletions

View File

@ -65,6 +65,7 @@ Instead of the path to the macaroon and cert files you can also provide the hex
- `static-path`: Path to a folder that you want to serve with LnMe (e.g. /home/bitcoin/lnme/website). Use this if you want to customize your ⚡website. default: disabled
- `lnurlp-min-sendable`: Min sendable amount in sats via LNURL-pay. (default: 1)
- `lnurlp-max-sendable`: Max sendable amount in sats via LNURL-pay. (default: 1000000)
- `lnurlp-thumbnail-dir`: Path to a PNG thumbnail directory for LNURL-pay metadata.
- `lnurlp-comment-allowed`: Allowed length of LNURL-pay comments, maximum around [~2000 characters](https://stackoverflow.com/a/417184). (default: 210)
- `disable-website`: Disable the default LnMe website. Disable the website if you only want to embed the LnMe widget on your existing website.
- `disable-cors`: Disable CORS headers. (default: false)

12
lnme.go
View File

@ -164,7 +164,16 @@ func main() {
lightningAddress := name + "@" + host
lnurlpMinSendable := msats(cfg.Int64("lnurlp-min-sendable"))
lnurlpMaxSendable := msats(cfg.Int64("lnurlp-max-sendable"))
lnurlMetadata := "[[\"text/identifier\", \"" + lightningAddress + "\"], [\"text/plain\", \"Sats for " + lightningAddress + "\"]]"
lnurlpThumbnailPath := cfg.String("lnurlp-thumbnail-dir") + "/" + name + ".png"
lnurlpThumbnailData, err := os.ReadFile(lnurlpThumbnailPath)
if lnurlpThumbnailPath != "" && err != nil {
stdOutLogger.Println("Error reading thumbnail:", err)
}
lnurlMetadata := lnurl.Metadata{}.
Identifier(lightningAddress).
Description("Sats for " + lightningAddress).
Thumbnail(lnurlpThumbnailData).
String()
lnurlpCommentAllowed := cfg.Int64("lnurlp-comment-allowed")
if amount := c.QueryParam("amount"); amount == "" {
@ -251,6 +260,7 @@ func LoadConfig() *koanf.Koanf {
f.String("lnd-cert", "", "HEX string of LND tls cert file.")
f.Int64("lnurlp-min-sendable", 1, "Min sendable amount in sats via LNURL-pay.")
f.Int64("lnurlp-max-sendable", 1000000, "Max sendable amount in sats via LNURL-pay.")
f.String("lnurlp-thumbnail-dir", "", "Path to a PNG thumbnail directory for LNURL-pay metadata.")
f.Int64("lnurlp-comment-allowed", 210, "Allowed length of LNURL-pay comments.")
f.Bool("disable-website", false, "Disable default embedded website.")
f.Bool("disable-ln-address", false, "Disable Lightning Address handling")

View File

@ -2,7 +2,12 @@
// only using the LNURL types here
package lnurl
import "net/url"
import (
"encoding/base64"
"encoding/json"
"net/http"
"net/url"
)
type LNURLResponse struct {
Status string `json:"status,omitempty"`
@ -50,3 +55,28 @@ type LNURLErrorResponse struct {
}
type Metadata [][]string
func (metadata Metadata) Identifier(identifier string) Metadata {
return append(metadata, []string{"text/identifier", identifier})
}
func (metadata Metadata) Description(description string) Metadata {
return append(metadata, []string{"text/plain", description})
}
func (metadata Metadata) Thumbnail(imageData []byte) Metadata {
if len(imageData) == 0 {
return metadata
}
mimeType := http.DetectContentType(imageData)
imageDataBase64 := base64.StdEncoding.EncodeToString(imageData)
return append(metadata, []string{mimeType + ";base64", imageDataBase64})
}
func (metadata Metadata) String() string {
bytes, _ := json.Marshal(metadata)
return string(bytes)
}