diff --git a/internal/dis/component/server/server.go b/internal/dis/component/server/server.go index 1dd147f..649d856 100644 --- a/internal/dis/component/server/server.go +++ b/internal/dis/component/server/server.go @@ -11,6 +11,7 @@ import ( "github.com/FAU-CDI/wisski-distillery/internal/models" "github.com/tkw1536/pkglib/contextx" "github.com/tkw1536/pkglib/httpx" + "github.com/tkw1536/pkglib/httpx/timewrap" "github.com/tkw1536/pkglib/mux" "github.com/gorilla/csrf" @@ -113,6 +114,8 @@ func (server *Server) Server(ctx context.Context, progress io.Writer) (public ht public = WithCSP(public, models.ContentSecurityPolicyDistilery) internal = WithCSP(internal, models.ContentSecurityPolicyNothing) + public = timewrap.Wrap(public) + err = nil return } diff --git a/internal/dis/component/server/templating/base.go b/internal/dis/component/server/templating/base.go index 48efef4..34b1916 100644 --- a/internal/dis/component/server/templating/base.go +++ b/internal/dis/component/server/templating/base.go @@ -13,6 +13,7 @@ import ( "github.com/gorilla/csrf" "github.com/rs/zerolog" "github.com/tkw1536/pkglib/httpx" + "github.com/tkw1536/pkglib/httpx/timewrap" ) //go:embed "src/base.html" @@ -44,6 +45,7 @@ func (tpl *Template[C]) context(r *http.Request, funcs ...FlagFunc) (ctx *tConte // setup the basic properties ctx.ctx = r.Context() ctx.Runtime.RequestURI = r.URL.RequestURI() + ctx.Runtime.StartedAt = timewrap.Start(r).UTC() ctx.Runtime.GeneratedAt = time.Now().UTC() ctx.Runtime.CSRF = csrf.TemplateField(r) ctx.Runtime.Menu = tpl.templating.buildMenu(r) diff --git a/internal/dis/component/server/templating/flags.go b/internal/dis/component/server/templating/flags.go index 771ea80..d56d242 100644 --- a/internal/dis/component/server/templating/flags.go +++ b/internal/dis/component/server/templating/flags.go @@ -37,10 +37,21 @@ type RuntimeFlags struct { RequestURI string // request uri of the current page Menu []component.MenuItem // menu at the top of the page + StartedAt time.Time // time the request started to generate GeneratedAt time.Time // time the underlying data returned CSRF template.HTML // csrf data (if any) } +// Returns how long this request took to render +func (rf RuntimeFlags) Took() time.Duration { + return time.Since(rf.StartedAt) +} +func (rf RuntimeFlags) TookHTML() template.HTML { + took := rf.Took() + + return template.HTML(fmt.Sprintf("", took.Seconds(), took)) +} + var runtimeFlagsName = reflectx.TypeFor[RuntimeFlags]().Name() // Clone clones this flags diff --git a/internal/dis/component/server/templating/src/footer.html b/internal/dis/component/server/templating/src/footer.html index 70a86a1..4e52ffd 100644 --- a/internal/dis/component/server/templating/src/footer.html +++ b/internal/dis/component/server/templating/src/footer.html @@ -1,3 +1,3 @@
- Generated by WissKI Distillery. This site might use cookies for essential purposes, see also Legal Notices. + Generated at in {{ .TookHTML }} by WissKI Distillery. This site might use cookies for essential purposes, see also Legal Notices.
\ No newline at end of file