Skip to content

Commit

Permalink
Make it possible to override branding
Browse files Browse the repository at this point in the history
  • Loading branch information
prusnak committed Jul 12, 2022
1 parent 8959601 commit 3f4d154
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 34 deletions.
12 changes: 12 additions & 0 deletions controllers/home.ctrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ type HomepageContent struct {
BlockHeight int
Uris []string
Channels []Channel
BrandingTitle string
BrandingDesc string
BrandingUrl string
BrandingLogo string
BrandingFavicon string
BrandingFooter map[string]string
}

type Channel struct {
Expand Down Expand Up @@ -111,6 +117,12 @@ func (controller *HomeController) Home(c echo.Context) error {
BlockHeight: int(info.BlockHeight),
Channels: channelSlice,
Uris: info.Uris,
BrandingTitle: controller.svc.Config.BrandingTitle,
BrandingDesc: controller.svc.Config.BrandingDesc,
BrandingUrl: controller.svc.Config.BrandingUrl,
BrandingLogo: controller.svc.Config.BrandingLogo,
BrandingFavicon: controller.svc.Config.BrandingFavicon,
BrandingFooter: controller.svc.Config.BrandingFooter,
}
var buf bytes.Buffer
err = tmpl.Execute(&buf, content)
Expand Down
75 changes: 52 additions & 23 deletions lib/service/config.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,56 @@
package service

import (
"fmt"
"strings"
)

type Config struct {
DatabaseUri string `envconfig:"DATABASE_URI" required:"true"`
SentryDSN string `envconfig:"SENTRY_DSN"`
LogFilePath string `envconfig:"LOG_FILE_PATH"`
JWTSecret []byte `envconfig:"JWT_SECRET" required:"true"`
JWTRefreshTokenExpiry int `envconfig:"JWT_REFRESH_EXPIRY" default:"604800"` // in seconds, default 7 days
JWTAccessTokenExpiry int `envconfig:"JWT_ACCESS_EXPIRY" default:"172800"` // in seconds, default 2 days
LNDAddress string `envconfig:"LND_ADDRESS" required:"true"`
LNDMacaroonHex string `envconfig:"LND_MACAROON_HEX" required:"true"`
LNDCertHex string `envconfig:"LND_CERT_HEX"`
CustomName string `envconfig:"CUSTOM_NAME"`
Host string `envconfig:"HOST" default:"localhost:3000"`
Port int `envconfig:"PORT" default:"3000"`
DefaultRateLimit int `envconfig:"DEFAULT_RATE_LIMIT" default:"10"`
StrictRateLimit int `envconfig:"STRICT_RATE_LIMIT" default:"10"`
BurstRateLimit int `envconfig:"BURST_RATE_LIMIT" default:"1"`
EnablePrometheus bool `envconfig:"ENABLE_PROMETHEUS" default:"false"`
PrometheusPort int `envconfig:"PROMETHEUS_PORT" default:"9092"`
WebhookUrl string `envconfig:"WEBHOOK_URL"`
FeeReserve bool `envconfig:"FEE_RESERVE" default:"false"`
AllowAccountCreation bool `envconfig:"ALLOW_ACCOUNT_CREATION" default:"true"`
MaxReceiveAmount int64 `envconfig:"MAX_RECEIVE_AMOUNT" default:"0"`
MaxSendAmount int64 `envconfig:"MAX_SEND_AMOUNT" default:"0"`
MaxAccountBalance int64 `envconfig:"MAX_ACCOUNT_BALANCE" default:"0"`
DatabaseUri string `envconfig:"DATABASE_URI" required:"true"`
SentryDSN string `envconfig:"SENTRY_DSN"`
LogFilePath string `envconfig:"LOG_FILE_PATH"`
JWTSecret []byte `envconfig:"JWT_SECRET" required:"true"`
JWTRefreshTokenExpiry int `envconfig:"JWT_REFRESH_EXPIRY" default:"604800"` // in seconds, default 7 days
JWTAccessTokenExpiry int `envconfig:"JWT_ACCESS_EXPIRY" default:"172800"` // in seconds, default 2 days
LNDAddress string `envconfig:"LND_ADDRESS" required:"true"`
LNDMacaroonHex string `envconfig:"LND_MACAROON_HEX" required:"true"`
LNDCertHex string `envconfig:"LND_CERT_HEX"`
CustomName string `envconfig:"CUSTOM_NAME"`
Host string `envconfig:"HOST" default:"localhost:3000"`
Port int `envconfig:"PORT" default:"3000"`
DefaultRateLimit int `envconfig:"DEFAULT_RATE_LIMIT" default:"10"`
StrictRateLimit int `envconfig:"STRICT_RATE_LIMIT" default:"10"`
BurstRateLimit int `envconfig:"BURST_RATE_LIMIT" default:"1"`
EnablePrometheus bool `envconfig:"ENABLE_PROMETHEUS" default:"false"`
PrometheusPort int `envconfig:"PROMETHEUS_PORT" default:"9092"`
WebhookUrl string `envconfig:"WEBHOOK_URL"`
FeeReserve bool `envconfig:"FEE_RESERVE" default:"false"`
AllowAccountCreation bool `envconfig:"ALLOW_ACCOUNT_CREATION" default:"true"`
MaxReceiveAmount int64 `envconfig:"MAX_RECEIVE_AMOUNT" default:"0"`
MaxSendAmount int64 `envconfig:"MAX_SEND_AMOUNT" default:"0"`
MaxAccountBalance int64 `envconfig:"MAX_ACCOUNT_BALANCE" default:"0"`
BrandingTitle string `envconfig:"BRANDING_TITLE" default:"LndHub - Alby Lightning"`
BrandingDesc string `envconfig:"BRANDING_DESC" default:"Alby server for the Lightning Network"`
BrandingUrl string `envconfig:"BRANDING_URL" default:"https://ln.getalby.com"`
BrandingLogo string `envconfig:"BRANDING_LOGO" default:""`
BrandingFavicon string `envconfig:"BRANDING_FAVICON" default:"../static/img/favicon.png"`
BrandingFooter FooterLinkMap `envconfig:"BRANDING_FOOTER" default:"about=https://getalby.com;community=https://t.me/getAlby"`
}

// envconfig map decoder uses colon (:) as the default separator
// we have to override the decoder so we can use colon for the protocol prefix (e.g. "https:")

type FooterLinkMap map[string]string

func (flm *FooterLinkMap) Decode(value string) error {
m := map[string]string{}
for _, pair := range strings.Split(value, ";") {
kvpair := strings.Split(pair, "=")
if len(kvpair) != 2 {
return fmt.Errorf("invalid map item: %q", pair)
}
m[kvpair[0]] = kvpair[1]
}
*flm = m
return nil
}
6 changes: 3 additions & 3 deletions static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ body {
top: 24px;
right: 24px;
}

#progressbar {
appearance: none;
margin: 0;
Expand Down Expand Up @@ -186,6 +185,9 @@ footer a {
body {
padding-right: 300px;
}
.logo {
width: 200px;
}
.sidebar {
position: fixed;
top: 0;
Expand Down Expand Up @@ -249,5 +251,3 @@ footer a {
}

}


24 changes: 16 additions & 8 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@
@charset "UTF-8";
</style>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta content="http://lndhub.io" property="og:url">
<meta content="lndhub.io" property="og:title">
<meta content="Alby server for the Lightning Network" property="og:description">
<meta content="{{.BrandingUrl}}" property="og:url">
<meta content="{{.BrandingTitle}}" property="og:title">
<meta content="{{.BrandingDesc}}" property="og:description">
<link rel="stylesheet" href="../static/css/style.css">
<link rel=icon href=../static/img/favicon.png>
<title>LndHub - Alby Lightning</title>
<link rel="icon" href="{{.BrandingFavicon}}">
<title>{{.BrandingTitle}}</title>
<meta content="lightning network, lndhub" name="keywords">
<body>
<div class="holder">
<div class="container32">
<div class="logo">
<svg width="20%" height="20%" viewBox="0 0 1094 525" fill="none" xmlns="http://www.w3.org/2000/svg">
{{if eq .BrandingLogo ""}}
<svg viewBox="0 0 1094 525" fill="none" xmlns="http://www.w3.org/2000/svg">
<ellipse opacity="0.1" cx="162.28" cy="480.52" rx="79.0085" ry="14.5862" fill="black"/>
<path d="M238.442 409.511C279.259 409.511 297.837 319.131 297.837 284.862C297.837 258.151 279.407 241.963 255.177 241.963C231.098 241.963 211.55 252.318 211.307 265.14C211.306 298.978 205.351 409.511 238.442 409.511Z" fill="white" stroke="black" stroke-width="12.1552"/>
<path d="M89.3601 409.511C48.5429 409.511 29.9648 319.131 29.9648 284.862C29.9648 258.151 48.3954 241.963 72.6254 241.963C96.7043 241.963 116.252 252.318 116.495 265.14C116.496 298.978 122.451 409.511 89.3601 409.511Z" fill="white" stroke="black" stroke-width="12.1552"/>
Expand All @@ -39,6 +40,9 @@
<ellipse cx="131.763" cy="218.167" rx="20.1557" ry="16.1246" fill="white"/>
<path d="M557.311 263.36H514.751L535.551 204.16L557.311 263.36ZM507.391 134.4L425.791 352H483.711L498.751 309.12H573.951L589.631 355.2L646.911 349.44L565.631 134.4H507.391ZM721.131 352V126.08L662.891 129.6V352H721.131ZM782.494 352L811.294 322.88V126.08L753.054 129.6V352H782.494ZM792.414 257.28C798.6 250.88 804.36 245.76 809.694 241.92C815.027 238.08 820.254 236.16 825.374 236.16C831.56 236.16 836.68 237.547 840.734 240.32C845 243.093 848.2 247.253 850.334 252.8C852.68 258.133 853.854 264.747 853.854 272.64C853.854 280.533 852.68 287.36 850.334 293.12C847.987 298.88 844.894 303.253 841.054 306.24C837.214 309.227 832.84 310.72 827.934 310.72C822.387 310.72 816.627 309.227 810.654 306.24C804.68 303.04 798.6 298.56 792.414 292.8L776.094 327.04C782.067 333.867 788.04 339.413 794.014 343.68C800.2 347.733 806.387 350.72 812.574 352.64C818.974 354.56 825.374 355.52 831.774 355.52C848.2 355.52 862.494 352.427 874.654 346.24C887.027 340.053 896.627 330.773 903.454 318.4C910.494 306.027 914.014 290.667 914.014 272.32C914.014 253.76 910.494 238.507 903.454 226.56C896.627 214.613 887.24 205.76 875.294 200C863.347 194.24 849.694 191.36 834.334 191.36C826.44 191.36 818.76 192.747 811.294 195.52C803.827 198.293 797 201.92 790.814 206.4C784.84 210.667 779.934 215.147 776.094 219.84L792.414 257.28ZM971.616 352.64C970.55 355.627 967.776 358.613 963.296 361.6C958.816 364.587 953.696 367.36 947.936 369.92C942.39 372.48 937.056 374.827 931.936 376.96L951.456 422.08C961.696 419.733 971.616 416.107 981.216 411.2C990.816 406.293 999.243 400.32 1006.5 393.28C1013.75 386.24 1018.98 378.56 1022.18 370.24L1090.34 196.8H1032.42L1002.66 284.48L970.976 191.04L917.216 206.4L972.896 349.12L971.616 352.64Z" fill="black"/>
</svg>
{{else}}
<img src="{{.BrandingLogo}}">
{{end}}
</div>
<div class="scroll">
<div class="boxes">
Expand Down Expand Up @@ -102,8 +106,12 @@ <h2>{{.RemotePubkey}}</h2>
{{end}}
</div>
<footer>
<a href="https://getalby.com" target="_blank">about</a> |
<a href="https://t.me/getAlby" target="_blank">community</a>
{{$first := true}}
{{range $text, $link := .BrandingFooter}}
{{if not $first}} | {{end}}
<a href="{{ $link }}" target="_blank">{{ $text }}</a>
{{$first = false}}
{{end}}
</footer>
</div>

Expand Down

0 comments on commit 3f4d154

Please sign in to comment.