Add custom logo configuration (#209)

This commit is contained in:
Thomas Miceli
2024-01-20 23:46:47 +01:00
parent 7f4be43bb4
commit afbecd9a1e
6 changed files with 50 additions and 13 deletions

View File

@ -60,6 +60,9 @@ type config struct {
OIDCClientKey string `yaml:"oidc.client-key" env:"OG_OIDC_CLIENT_KEY"`
OIDCSecret string `yaml:"oidc.secret" env:"OG_OIDC_SECRET"`
OIDCDiscoveryUrl string `yaml:"oidc.discovery-url" env:"OG_OIDC_DISCOVERY_URL"`
CustomLogo string `yaml:"custom.logo" env:"OG_CUSTOM_LOGO"`
CustomFavicon string `yaml:"custom.favicon" env:"OG_CUSTOM_FAVICON"`
}
func configWithDefaults() (*config, error) {

View File

@ -10,6 +10,9 @@ import (
"html/template"
"io"
"net/http"
"net/url"
"os"
"path"
"path/filepath"
"regexp"
"strconv"
@ -88,7 +91,8 @@ var (
return defaultAvatar()
},
"asset": asset,
"asset": asset,
"custom": customAsset,
"dev": func() bool {
return dev
},
@ -205,8 +209,15 @@ func NewServer(isDev bool) *Server {
if !dev {
parseManifestEntries()
e.GET("/assets/*", cacheControl(echo.WrapHandler(http.FileServer(http.FS(public.Files)))))
}
customFs := os.DirFS(filepath.Join(config.GetHomeDir(), "custom"))
e.GET("/assets/*", func(c echo.Context) error {
if _, err := public.Files.Open(path.Join("assets", c.Param("*"))); !dev && err == nil {
return echo.WrapHandler(http.FileServer(http.FS(public.Files)))(c)
}
return echo.WrapHandler(http.StripPrefix("/assets/", http.FileServer(http.FS(customFs))))(c)
})
// Web based routes
g1 := e.Group("")
@ -466,13 +477,6 @@ func checkRequireLogin(next echo.HandlerFunc) echo.HandlerFunc {
}
}
func cacheControl(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
c.Response().Header().Set(echo.HeaderCacheControl, "public, max-age=31536000")
return next(c)
}
}
func noRouteFound(echo.Context) error {
return notFound("Page not found")
}
@ -512,3 +516,11 @@ func asset(file string) string {
}
return config.C.ExternalUrl + "/" + manifestEntries[file].File
}
func customAsset(file string) string {
assetpath, err := url.JoinPath("/", "assets", file)
if err != nil {
log.Error().Err(err).Msgf("Failed to join path for custom file %s", file)
}
return config.C.ExternalUrl + assetpath
}