diff --git a/routers/web/admin/branding.go b/routers/web/admin/branding.go index b4d5affb1c..2e4c038c47 100644 --- a/routers/web/admin/branding.go +++ b/routers/web/admin/branding.go @@ -165,6 +165,40 @@ func BrandingUpload(ctx *context.Context) { ctx.Redirect(setting.AppSubURL + "/-/admin/branding") } +// BrandingReset removes a custom branding image, reverting to the built-in default. +func BrandingReset(ctx *context.Context) { + imageType := ctx.FormString("type") + + var filename string + switch imageType { + case "nav-icon": + filename = "logo-small.png" + case "logo": + filename = "logo.png" + case "favicon": + filename = "favicon.png" + default: + ctx.Flash.Error("Invalid image type") + ctx.Redirect(setting.AppSubURL + "/-/admin/branding") + return + } + + path := filepath.Join(brandingImageDir(), filename) + if fileExists(path) { + if err := os.Remove(path); err != nil { + ctx.Flash.Error("Failed to remove custom image") + log.Error("Remove %s: %v", path, err) + } else { + ctx.Flash.Success("Reset to default: " + imageType) + log.Info("Branding reset to default: %s", filename) + } + } else { + ctx.Flash.Info("Already using default: " + imageType) + } + + ctx.Redirect(setting.AppSubURL + "/-/admin/branding") +} + func fileExists(path string) bool { _, err := os.Stat(path) return err == nil diff --git a/routers/web/web.go b/routers/web/web.go index ff6f18a99a..3a831b02c1 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -769,6 +769,7 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) { m.Get("", admin.Branding) m.Post("/upload", admin.BrandingUpload) m.Post("/settings", admin.BrandingSettings) + m.Get("/reset", admin.BrandingReset) }) m.Group("/monitor", func() { diff --git a/templates/admin/branding.tmpl b/templates/admin/branding.tmpl index d1010ca31d..38ba384508 100644 --- a/templates/admin/branding.tmpl +++ b/templates/admin/branding.tmpl @@ -62,6 +62,7 @@
+ {{if .HasNavIcon}}{{svg "octicon-sync" 12}} Reset{{end}} @@ -81,6 +82,7 @@
+ {{if .HasLogo}}{{svg "octicon-sync" 12}} Reset{{end}} @@ -100,6 +102,7 @@
+ {{if .HasFavicon}}{{svg "octicon-sync" 12}} Reset{{end}}