mirror of
https://github.com/thomiceli/opengist.git
synced 2025-06-11 04:57:13 +02:00
Add custom logo configuration (#209)
This commit is contained in:
@ -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) {
|
||||
|
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user