Skip to content

Commit

Permalink
fix #98
Browse files Browse the repository at this point in the history
  • Loading branch information
Wessie committed Mar 24, 2024
1 parent b6446b6 commit fafc713
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions templates/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ import (

type themeKey struct{}

const ThemeCookieName = "theme"
const ThemeAdminCookieName = "admin-theme"

func ThemeCtx(storage radio.StorageService) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
theme := DEFAULT_DIR
cookieName := theme
cookieName := ThemeCookieName
if strings.HasPrefix(r.URL.Path, "/admin") {
theme = DEFAULT_ADMIN_DIR
cookieName = "admin-theme"
cookieName = ThemeAdminCookieName
}

if cookie, err := r.Cookie(cookieName); err == nil {
Expand Down
5 changes: 4 additions & 1 deletion website/admin/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ func Route(ctx context.Context, s State) func(chi.Router) {
r = r.With(
s.Authentication.LoginMiddleware,
)
r.Handle("/set-theme", templates.SetThemeHandler("admin-theme", s.Templates.ResolveThemeName))
r.Handle("/set-theme", templates.SetThemeHandler(
templates.ThemeAdminCookieName,
s.Templates.ResolveThemeName,
))
r.HandleFunc("/", s.GetHome)
r.Get("/profile", s.GetProfile)
r.Post("/profile", s.PostProfile)
Expand Down
2 changes: 1 addition & 1 deletion website/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func Execute(ctx context.Context, cfg config.Config) error {
r.Handle("/assets/*", http.StripPrefix("/assets/",
AssetsHandler(cfg.Conf().AssetsPath, siteTemplates)),
)
r.Handle("/set-theme", templates.SetThemeHandler("theme", siteTemplates.ResolveThemeName))
r.Handle("/set-theme", templates.SetThemeHandler(templates.ThemeCookieName, siteTemplates.ResolveThemeName))

// version 0 of the api (the legacy PHP version)
// it's mostly self-contained to the /api/* route, except for /request that
Expand Down

0 comments on commit fafc713

Please sign in to comment.