diff options
author | Brecht Van Lommel <brecht@blender.org> | 2023-05-22 17:51:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-22 23:51:40 +0800 |
commit | 3588edbb08f93aaa56defa82dffdbb202cd9aa4a (patch) | |
tree | ad3b571f18534d3932642d3c069c495a31e9966c /routers | |
parent | 922c83eea3407746a0472e5e3ad8b78a3136c661 (diff) | |
download | gitea-3588edbb08f93aaa56defa82dffdbb202cd9aa4a.tar.gz gitea-3588edbb08f93aaa56defa82dffdbb202cd9aa4a.zip |
Add gitea manager reload-templates command (#24843)
This can be useful to update custom templates in production mode, when
they are updated frequently and a full Gitea restart each time is
disruptive.
Diffstat (limited to 'routers')
-rw-r--r-- | routers/private/internal.go | 1 | ||||
-rw-r--r-- | routers/private/manager.go | 13 |
2 files changed, 14 insertions, 0 deletions
diff --git a/routers/private/internal.go b/routers/private/internal.go index b09fb58d05..407edebeed 100644 --- a/routers/private/internal.go +++ b/routers/private/internal.go @@ -67,6 +67,7 @@ func Routes() *web.Route { r.Get("/serv/command/{keyid}/{owner}/{repo}", ServCommand) r.Post("/manager/shutdown", Shutdown) r.Post("/manager/restart", Restart) + r.Post("/manager/reload-templates", ReloadTemplates) r.Post("/manager/flush-queues", bind(private.FlushOptions{}), FlushQueues) r.Post("/manager/pause-logging", PauseLogging) r.Post("/manager/resume-logging", ResumeLogging) diff --git a/routers/private/manager.go b/routers/private/manager.go index 8ed05da6a5..26096c403b 100644 --- a/routers/private/manager.go +++ b/routers/private/manager.go @@ -15,9 +15,22 @@ import ( "code.gitea.io/gitea/modules/private" "code.gitea.io/gitea/modules/queue" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/templates" "code.gitea.io/gitea/modules/web" ) +// ReloadTemplates reloads all the templates +func ReloadTemplates(ctx *context.PrivateContext) { + err := templates.ReloadHTMLTemplates() + if err != nil { + ctx.JSON(http.StatusInternalServerError, private.Response{ + UserMsg: fmt.Sprintf("Template error: %v", err), + }) + return + } + ctx.PlainText(http.StatusOK, "success") +} + // FlushQueues flushes all the Queues func FlushQueues(ctx *context.PrivateContext) { opts := web.GetForm(ctx).(*private.FlushOptions) |