Skip to content

Commit

Permalink
feat(server): Show configurable footer text
Browse files Browse the repository at this point in the history
  • Loading branch information
exler committed Oct 10, 2023
1 parent 053fa37 commit 4ea4163
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
6 changes: 6 additions & 0 deletions cmd/runserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ var serverCmd = &cli.Command{
Name: "runserver",
Usage: "Run web server",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "extra-footer",
Usage: "Text to be added to the footer of the page",
EnvVars: []string{"EXTRA_FOOTER"},
},
&cli.IntFlag{
Name: "port",
Aliases: []string{"p"},
Expand Down Expand Up @@ -77,6 +82,7 @@ var serverCmd = &cli.Command{
server.MaxUploadSize(cCtx.Int64("max-upload-size")),
server.MaxRequests(cCtx.Int("rate-limit")),
server.UseLogger(logger.NewLogger(cCtx.String("sentry-dsn"), cCtx.String("sentry-environment"))),
server.ExtraFooterText(cCtx.String("extra-footer")),
}

storage, err := GetStorage(cCtx)
Expand Down
6 changes: 5 additions & 1 deletion server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ func generateFileId() string {
}

func (s *Server) indexHandler(w http.ResponseWriter, r *http.Request) {
renderTemplate(w, "index", map[string]interface{}{})
renderTemplate(w, "index", map[string]interface{}{
"extraFooterText": s.extraFooterText,
})
}

func (s *Server) formHandler(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -95,6 +97,7 @@ func (s *Server) fileUploadHandler(w http.ResponseWriter, r *http.Request) {

renderTemplate(w, "index", map[string]interface{}{
"fileUrl": fileUrl,
"extraFooterText": s.extraFooterText,
})
}

Expand Down Expand Up @@ -142,6 +145,7 @@ func (s *Server) pastebinHandler(w http.ResponseWriter, r *http.Request) {

renderTemplate(w, "index", map[string]interface{}{
"fileUrl": fileUrl,
"extraFooterText": s.extraFooterText,
})
}

Expand Down
8 changes: 8 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ func Port(port int) OptionFn {
}
}

func ExtraFooterText(text string) OptionFn {
return func(s *Server) {
s.extraFooterText = text
}
}

type Server struct {
logger *logger.Logger

Expand All @@ -60,6 +66,8 @@ type Server struct {
maxUploadSize int64
maxRequests int

extraFooterText string

port int
}

Expand Down
3 changes: 3 additions & 0 deletions server/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@

<footer>
Copyright (c) {{ now.UTC.Year }} by Kamil Marut |
{{ if .extraFooterText }}
{{ .extraFooterText }} |
{{ end }}
<a href="https://github.com/exler/fileigloo" target="_blank" rel="noopener noreferrer">Github</a>
</footer>
</main>
Expand Down

0 comments on commit 4ea4163

Please sign in to comment.