Add four DB-backed configuration tables for site-wide settings: site_settings (logo, top-left title, header/footer text with zh/en variants), upload_configs (master switch, default size, storage dir), upload_file_types (per-extension whitelist with per-type size limits), and download_baseurls (multiple download sources with priority/default). - Models, AutoMigrate, and first-run seed (18 common file types) - Process-level config cache warmed at startup, refreshed on admin save - SetUserContext injects cached site settings into templates - base.html renders logo (local upload or external URL), title, header banner, and footer with i18n fallback - Upload validator drives avatar uploads (form + AJAX) through the configured switch/type/size policy - Admin pages for site/upload/download settings with i18n keys Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
57 lines
1.6 KiB
Go
57 lines
1.6 KiB
Go
package handlers
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// DefaultData builds a base gin.H map populated with values set by the
|
|
// SetUserContext middleware (translations, language, auth state). Handlers
|
|
// add page-specific fields on top and pass it to c.HTML().
|
|
func DefaultData(c *gin.Context) gin.H {
|
|
tr, _ := c.Get("tr")
|
|
isLoggedIn, _ := c.Get("is_logged_in")
|
|
username, _ := c.Get("username")
|
|
lang, _ := c.Get("lang")
|
|
switchLang, _ := c.Get("switch_lang")
|
|
avatar, _ := c.Get("avatar")
|
|
displayName, _ := c.Get("display_name")
|
|
role, _ := c.Get("role")
|
|
siteSetting, _ := c.Get("site_setting")
|
|
siteLogo, _ := c.Get("site_logo")
|
|
siteLogoIsURL, _ := c.Get("site_logo_is_url")
|
|
siteLogoText, _ := c.Get("site_logo_text")
|
|
siteHeaderText, _ := c.Get("site_header_text")
|
|
siteFooterText, _ := c.Get("site_footer_text")
|
|
|
|
return gin.H{
|
|
"Tr": tr,
|
|
"IsLoggedIn": isLoggedIn,
|
|
"Username": username,
|
|
"Lang": lang,
|
|
"SwitchLang": switchLang,
|
|
"Avatar": avatar,
|
|
"DisplayName": displayName,
|
|
"Role": role,
|
|
"SiteSetting": siteSetting,
|
|
"SiteLogo": siteLogo,
|
|
"SiteLogoIsURL": siteLogoIsURL,
|
|
"SiteLogoText": siteLogoText,
|
|
"SiteHeaderText": siteHeaderText,
|
|
"SiteFooterText": siteFooterText,
|
|
}
|
|
}
|
|
|
|
// getTr is a convenience helper that returns the translation map from the
|
|
// Gin context, falling back to an empty map if not set.
|
|
func getTr(c *gin.Context) map[string]string {
|
|
tr, ok := c.Get("tr")
|
|
if !ok {
|
|
return map[string]string{}
|
|
}
|
|
m, ok := tr.(map[string]string)
|
|
if !ok {
|
|
return map[string]string{}
|
|
}
|
|
return m
|
|
}
|