Skip to content

Commit

Permalink
Merge pull request #2546 from gobitfly/BIDS-2472/follow_up
Browse files Browse the repository at this point in the history
Bids 2472/follow up
  • Loading branch information
peterbitfly authored Sep 13, 2023
2 parents 43d6ccd + e53378b commit e1b86ff
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 51 deletions.
7 changes: 0 additions & 7 deletions cmd/explorer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ func main() {
utils.LogFatal(err, "invalid chain configuration specified, you must specify the slots per epoch, seconds per slot and genesis timestamp in the config file", 0)
}

err = handlers.CheckAndPreloadImprint()
if err != nil {
logrus.Fatalf("error check / preload imprint: %v", err)
}

if utils.Config.Pprof.Enabled {
go func() {
logrus.Infof("starting pprof http server on port %s", utils.Config.Pprof.Port)
Expand Down Expand Up @@ -626,8 +621,6 @@ func main() {
jsHandler := http.FileServer(http.Dir("static/js"))
router.PathPrefix("/js").Handler(http.StripPrefix("/js/", jsHandler))
}
legalFs := http.Dir(utils.Config.Frontend.LegalDir)
router.PathPrefix("/legal").Handler(http.StripPrefix("/legal/", handlers.CustomFileServer(http.FileServer(legalFs), legalFs, handlers.NotFound)))
fileSys := http.FS(static.Files)
router.PathPrefix("/").Handler(handlers.CustomFileServer(http.FileServer(fileSys), fileSys, handlers.NotFound))

Expand Down
43 changes: 5 additions & 38 deletions handlers/imprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,18 @@ import (
"eth2-exporter/utils"
"html/template"
"net/http"
"os"
"path"
)

// Imprint will show the imprint data using a go template
func Imprint(w http.ResponseWriter, r *http.Request) {
templateFiles := []string{getImprintPath()}
if len(templateFiles) == 0 {
templateFiles = append(layoutTemplateFiles, "imprint.example.html")
}

imprintTemplate := templates.GetTemplate(layoutTemplateFiles...)
imprintTemplate = template.Must(imprintTemplate.Parse(utils.Config.Frontend.Legal.ImprintTemplate))
w.Header().Set("Content-Type", "text/html")

data := InitPageData(w, r, "imprint", "/imprint", "Imprint", templateFiles)
data := InitPageData(w, r, "imprint", "/imprint", "Imprint", layoutTemplateFiles)

if handleTemplateError(w, r, "imprint.go", "Imprint", "", getImprintTemplate(getImprintPath()).ExecuteTemplate(w, "layout", data)) != nil {
if handleTemplateError(w, r, "imprint.go", "Imprint", "", imprintTemplate.ExecuteTemplate(w, "layout", data)) != nil {
return // an error has occurred and was processed
}
}

func CheckAndPreloadImprint() error {
imprintPath := getImprintPath()
if len(imprintPath) > 0 {
_, err := os.Stat(imprintPath) // check file exists
if err != nil {
return err
}
}

getImprintTemplate(imprintPath) // preload
return nil
}

func getImprintPath() string {
if utils.Config.Frontend.LegalDir == "" {
return utils.Config.Frontend.Imprint
}
return path.Join(utils.Config.Frontend.LegalDir, "index.html")
}

func getImprintTemplate(path string) *template.Template {
if len(path) == 0 {
return templates.GetTemplate(append(layoutTemplateFiles, "imprint.example.html")...)
}

var imprintTemplate = templates.GetTemplate(layoutTemplateFiles...)
imprintTemplate = templates.AddTemplateFile(imprintTemplate, path)
return imprintTemplate
}
2 changes: 2 additions & 0 deletions handlers/pageData.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ func InitPageData(w http.ResponseWriter, r *http.Request, active, path, title st
GlobalNotification: services.GlobalNotificationMessage(),
AvailableCurrencies: price.GetAvailableCurrencies(),
MainMenuItems: createMenuItems(active, isMainnet),
TermsOfServiceUrl: utils.Config.Frontend.Legal.TermsOfServiceUrl,
PrivacyPolicyUrl: utils.Config.Frontend.Legal.PrivacyPolicyUrl,
}

adConfigurations, err := db.GetAdConfigurationsForTemplate(mainTemplates, data.NoAds)
Expand Down
5 changes: 5 additions & 0 deletions local-deployment/provision-explorer-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ frontend:
domain: mg.localhost
privateKey: "key-11111111111111111111111111111111"
csrfAuthKey: '1111111111111111111111111111111111111111111111111111111111111111'
legal:
termsOfServiceUrl: "tos.pdf"
privacyPolicyUrl: "privacy.pdf"
imprintTemplate: '{{ define "js" }}{{ end }}{{ define "css" }}{{ end }}{{ define "content" }}Imprint{{ end }}'
indexer:
# fullIndexOnStartup: false # Perform a one time full db index on startup
# indexMissingEpochsOnStartup: true # Check for missing epochs and export them after startup
Expand Down
14 changes: 13 additions & 1 deletion notify/firebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package notify
import (
"context"
"eth2-exporter/utils"
"fmt"
"strings"
"time"

Expand Down Expand Up @@ -33,7 +34,18 @@ func SendPushBatch(messages []*messaging.Message) error {
}

ctx := context.Background()
opt := option.WithCredentialsFile(credentialsPath)
var opt option.ClientOption

if strings.HasPrefix(credentialsPath, "projects/") {
x, err := utils.AccessSecretVersion(credentialsPath)
if err != nil {
return fmt.Errorf("error getting firebase config from secret store: %v", err)
}
opt = option.WithCredentialsJSON([]byte(*x))
} else {
opt = option.WithCredentialsFile(credentialsPath)
}

app, err := firebase.NewApp(context.Background(), nil, opt)
if err != nil {
logger.Errorf("error initializing app: %v", err)
Expand Down
6 changes: 3 additions & 3 deletions templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@
<div style="width: 80%; max-width: 600px;" class="card card-body row">
<div class="row">
<div class="col">
<span>By using our site you agree to our <a href="/legal/privacy.pdf">use of cookies</a> to deliver a better user experience.</span>
<span>By using our site you agree to our <a href="{{ $.PrivacyPolicyUrl }}">use of cookies</a> to deliver a better user experience.</span>
</div>
</div>
<div class="row">
Expand All @@ -281,10 +281,10 @@ <h5>Legal Notices</h5>
<a class="my-1" href="/imprint"><i class="fas fa-building mr-2"></i>Imprint</a>
</div>
<div class="d-flex flex-column">
<a class="my-1" href="/legal/tos.pdf"><i class="fas fa-file-contract mr-2"></i>Terms</a>
<a class="my-1" href="{{ $.TermsOfServiceUrl }}"><i class="fas fa-file-contract mr-2"></i>Terms</a>
</div>
<div class="d-flex flex-column">
<a class="my-1" href="/legal/privacy.pdf"><i class="fas fa-user-secret mr-2"></i>Privacy</a>
<a class="my-1" href="{{ $.PrivacyPolicyUrl }}"><i class="fas fa-user-secret mr-2"></i>Privacy</a>
</div>
</div>
<div class="col-md-4 mb-2">
Expand Down
8 changes: 6 additions & 2 deletions types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,12 @@ type Config struct {
RecaptchaSecretKey string `yaml:"recaptchaSecretKey" envconfig:"FRONTEND_RECAPTCHA_SECRETKEY"`
Enabled bool `yaml:"enabled" envconfig:"FRONTEND_ENABLED"`
// Imprint is deprdecated place imprint file into the legal directory
Imprint string `yaml:"imprint" envconfig:"FRONTEND_IMPRINT"`
LegalDir string `yaml:"legalDir" envconfig:"FRONTEND_LEGAL"`
Imprint string `yaml:"imprint" envconfig:"FRONTEND_IMPRINT"`
Legal struct {
TermsOfServiceUrl string `yaml:"termsOfServiceUrl" envconfig:"FRONTEND_LEGAL_TERMS_OF_SERVICE_URL"`
PrivacyPolicyUrl string `yaml:"privacyPolicyUrl" envconfig:"FRONTEND_LEGAL_PRIVACY_POLICY_URL"`
ImprintTemplate string `yaml:"imprintTemplate" envconfig:"FRONTEND_LEGAL_IMPRINT_TEMPLATE"`
} `yaml:"legal"`
SiteDomain string `yaml:"siteDomain" envconfig:"FRONTEND_SITE_DOMAIN"`
SiteName string `yaml:"siteName" envconfig:"FRONTEND_SITE_NAME"`
SiteSubtitle string `yaml:"siteSubtitle" envconfig:"FRONTEND_SITE_SUBTITLE"`
Expand Down
2 changes: 2 additions & 0 deletions types/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ type PageData struct {
GlobalNotification template.HTML
AvailableCurrencies []string
MainMenuItems []MainMenuItem
TermsOfServiceUrl string
PrivacyPolicyUrl string
}

type MainMenuItem struct {
Expand Down

0 comments on commit e1b86ff

Please sign in to comment.