feat(themes): 添加可编辑的站点外观和皮肤主题(#408)
This commit is contained in:
1 parent
c768fccbc2
commit
5e66cb7c45
70 files changed
+3654
-327
No files matched your search
@@ -29,7 +29,7 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
appearanceSchemaVersion = 3
|
||||
appearanceSchemaVersion = 6
|
||||
appearanceLogoMaxBytes int64 = 5 << 20
|
||||
appearancePosterMaxBytes int64 = 10 << 20
|
||||
appearanceVideoMaxBytes int64 = 256 << 20
|
||||
@@ -46,38 +46,52 @@ const (
|
||||
)
|
||||
|
||||
type AppearanceSetting struct {
|
||||
SchemaVersion int `json:"schemaVersion"`
|
||||
BrandName string `json:"brandName"`
|
||||
BrandSlug string `json:"brandSlug"`
|
||||
AuthHeroTitle string `json:"authHeroTitle"`
|
||||
AuthHeroDescription string `json:"authHeroDescription"`
|
||||
LogoResourceID string `json:"logoResourceId"`
|
||||
DarkLogoResourceID string `json:"darkLogoResourceId"`
|
||||
LogoFrameEnabled bool `json:"logoFrameEnabled"`
|
||||
AuthVideoResourceID string `json:"authVideoResourceId"`
|
||||
AuthVideoPosterResourceID string `json:"authVideoPosterResourceId"`
|
||||
SkinID string `json:"skinId"`
|
||||
SchemaVersion int `json:"schemaVersion"`
|
||||
BrandName string `json:"brandName"`
|
||||
BrandSlug string `json:"brandSlug"`
|
||||
AuthHeroTitle string `json:"authHeroTitle"`
|
||||
AuthHeroDescription string `json:"authHeroDescription"`
|
||||
LogoResourceID string `json:"logoResourceId"`
|
||||
DarkLogoResourceID string `json:"darkLogoResourceId"`
|
||||
LogoFrameEnabled bool `json:"logoFrameEnabled"`
|
||||
AuthVideoResourceID string `json:"authVideoResourceId"`
|
||||
AuthVideoPosterResourceID string `json:"authVideoPosterResourceId"`
|
||||
SkinID string `json:"skinId"`
|
||||
SkinThemes []AppearanceSkinTheme `json:"skinThemes"`
|
||||
SEOTitle string `json:"seoTitle"`
|
||||
SEODescription string `json:"seoDescription"`
|
||||
SEOKeywords string `json:"seoKeywords"`
|
||||
FooterCopyright string `json:"footerCopyright"`
|
||||
ICPFilingEnabled bool `json:"icpFilingEnabled"`
|
||||
ICPFilingNumber string `json:"icpFilingNumber"`
|
||||
}
|
||||
|
||||
type PublicAppearanceSetting struct {
|
||||
SchemaVersion int `json:"schemaVersion"`
|
||||
BrandName string `json:"brandName"`
|
||||
BrandSlug string `json:"brandSlug"`
|
||||
AuthHeroTitle string `json:"authHeroTitle"`
|
||||
AuthHeroDescription string `json:"authHeroDescription"`
|
||||
LogoURL string `json:"logoUrl"`
|
||||
DarkLogoURL string `json:"darkLogoUrl"`
|
||||
LogoFrameEnabled bool `json:"logoFrameEnabled"`
|
||||
AuthVideoURL string `json:"authVideoUrl"`
|
||||
AuthVideoPosterURL string `json:"authVideoPosterUrl"`
|
||||
SkinID string `json:"skinId"`
|
||||
LogoConfigured bool `json:"logoConfigured"`
|
||||
DarkLogoConfigured bool `json:"darkLogoConfigured"`
|
||||
AuthVideoConfigured bool `json:"authVideoConfigured"`
|
||||
AuthVideoPosterConfigured bool `json:"authVideoPosterConfigured"`
|
||||
Configured bool `json:"configured"`
|
||||
Revision string `json:"revision"`
|
||||
UpdatedAt time.Time `json:"updatedAt,omitempty"`
|
||||
SchemaVersion int `json:"schemaVersion"`
|
||||
BrandName string `json:"brandName"`
|
||||
BrandSlug string `json:"brandSlug"`
|
||||
AuthHeroTitle string `json:"authHeroTitle"`
|
||||
AuthHeroDescription string `json:"authHeroDescription"`
|
||||
LogoURL string `json:"logoUrl"`
|
||||
DarkLogoURL string `json:"darkLogoUrl"`
|
||||
LogoFrameEnabled bool `json:"logoFrameEnabled"`
|
||||
AuthVideoURL string `json:"authVideoUrl"`
|
||||
AuthVideoPosterURL string `json:"authVideoPosterUrl"`
|
||||
SkinID string `json:"skinId"`
|
||||
ActiveSkin AppearanceSkinTheme `json:"activeSkin"`
|
||||
SEOTitle string `json:"seoTitle"`
|
||||
SEODescription string `json:"seoDescription"`
|
||||
SEOKeywords string `json:"seoKeywords"`
|
||||
FooterCopyright string `json:"footerCopyright"`
|
||||
ICPFilingEnabled bool `json:"icpFilingEnabled"`
|
||||
ICPFilingNumber string `json:"icpFilingNumber"`
|
||||
LogoConfigured bool `json:"logoConfigured"`
|
||||
DarkLogoConfigured bool `json:"darkLogoConfigured"`
|
||||
AuthVideoConfigured bool `json:"authVideoConfigured"`
|
||||
AuthVideoPosterConfigured bool `json:"authVideoPosterConfigured"`
|
||||
Configured bool `json:"configured"`
|
||||
Revision string `json:"revision"`
|
||||
UpdatedAt time.Time `json:"updatedAt,omitempty"`
|
||||
}
|
||||
|
||||
type AdminAppearanceSetting struct {
|
||||
@@ -97,6 +111,7 @@ func defaultAppearanceSetting() AppearanceSetting {
|
||||
AuthHeroTitle: defaultAppearanceHeroTitle,
|
||||
LogoFrameEnabled: true,
|
||||
SkinID: defaultAppearanceSkinID,
|
||||
SkinThemes: defaultAppearanceSkinThemes(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,6 +171,15 @@ func (s *Service) UpdateAppearance(actor *model.User, value AppearanceSetting) (
|
||||
value.AuthVideoResourceID = strings.TrimSpace(value.AuthVideoResourceID)
|
||||
value.AuthVideoPosterResourceID = strings.TrimSpace(value.AuthVideoPosterResourceID)
|
||||
value.SkinID = strings.TrimSpace(value.SkinID)
|
||||
if len(value.SkinThemes) == 0 {
|
||||
value.SkinThemes = defaultAppearanceSkinThemes()
|
||||
}
|
||||
value.SkinThemes = normalizeAppearanceSkinThemes(value.SkinThemes)
|
||||
value.SEOTitle = normalizeAppearanceSingleLine(value.SEOTitle)
|
||||
value.SEODescription = normalizeAppearanceCopy(value.SEODescription)
|
||||
value.SEOKeywords = normalizeAppearanceSingleLine(value.SEOKeywords)
|
||||
value.FooterCopyright = normalizeAppearanceSingleLine(value.FooterCopyright)
|
||||
value.ICPFilingNumber = normalizeAppearanceSingleLine(value.ICPFilingNumber)
|
||||
if err := validateAppearanceSetting(value); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -328,6 +352,15 @@ func (s *Service) readAppearance() (*model.SystemSetting, AppearanceSetting, err
|
||||
if value.SkinID == "" {
|
||||
value.SkinID = defaultAppearanceSkinID
|
||||
}
|
||||
if len(value.SkinThemes) == 0 {
|
||||
value.SkinThemes = defaultAppearanceSkinThemes()
|
||||
}
|
||||
value.SkinThemes = normalizeAppearanceSkinThemes(value.SkinThemes)
|
||||
value.SEOTitle = normalizeAppearanceSingleLine(value.SEOTitle)
|
||||
value.SEODescription = normalizeAppearanceCopy(value.SEODescription)
|
||||
value.SEOKeywords = normalizeAppearanceSingleLine(value.SEOKeywords)
|
||||
value.FooterCopyright = normalizeAppearanceSingleLine(value.FooterCopyright)
|
||||
value.ICPFilingNumber = normalizeAppearanceSingleLine(value.ICPFilingNumber)
|
||||
return setting, value, nil
|
||||
}
|
||||
|
||||
@@ -349,8 +382,26 @@ func validateAppearanceSetting(value AppearanceSetting) error {
|
||||
if err := validateAppearanceCopy(value.AuthHeroDescription, "登录页说明文案", 160, false); err != nil {
|
||||
return err
|
||||
}
|
||||
if value.SkinID != defaultAppearanceSkinID {
|
||||
return BadAuthRequest("当前版本仅支持经典皮肤")
|
||||
if err := validateAppearanceSkinThemes(value.SkinThemes, value.SkinID); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, field := range []struct {
|
||||
value string
|
||||
label string
|
||||
max int
|
||||
}{
|
||||
{value.SEOTitle, "SEO 标题", 70},
|
||||
{value.SEODescription, "SEO 描述", 200},
|
||||
{value.SEOKeywords, "SEO 关键词", 300},
|
||||
{value.FooterCopyright, "版权信息", 160},
|
||||
{value.ICPFilingNumber, "备案号", 64},
|
||||
} {
|
||||
if err := validateAppearanceCopy(field.value, field.label, field.max, false); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if value.ICPFilingEnabled && value.ICPFilingNumber == "" {
|
||||
return BadAuthRequest("显示备案号前请先填写备案号")
|
||||
}
|
||||
for _, resourceID := range []string{value.LogoResourceID, value.DarkLogoResourceID, value.AuthVideoResourceID, value.AuthVideoPosterResourceID} {
|
||||
if len(resourceID) > 80 {
|
||||
@@ -364,6 +415,10 @@ func normalizeAppearanceCopy(value string) string {
|
||||
return strings.TrimSpace(strings.ReplaceAll(strings.ReplaceAll(value, "\r\n", "\n"), "\r", "\n"))
|
||||
}
|
||||
|
||||
func normalizeAppearanceSingleLine(value string) string {
|
||||
return strings.TrimSpace(strings.ReplaceAll(strings.ReplaceAll(value, "\r\n", " "), "\r", " "))
|
||||
}
|
||||
|
||||
func validAppearanceBrandSlug(value string) bool {
|
||||
if len(value) == 0 || len(value) > 48 || value[0] == '-' || value[len(value)-1] == '-' {
|
||||
return false
|
||||
@@ -517,6 +572,13 @@ func publicAppearanceSetting(setting *model.SystemSetting, value AppearanceSetti
|
||||
AuthVideoURL: defaultAppearanceVideoURL,
|
||||
AuthVideoPosterURL: defaultAppearancePosterURL,
|
||||
SkinID: value.SkinID,
|
||||
ActiveSkin: activeAppearanceSkin(value.SkinThemes, value.SkinID),
|
||||
SEOTitle: effectiveAppearanceSEOTitle(value),
|
||||
SEODescription: effectiveAppearanceSEODescription(value),
|
||||
SEOKeywords: value.SEOKeywords,
|
||||
FooterCopyright: effectiveAppearanceCopyright(value),
|
||||
ICPFilingEnabled: value.ICPFilingEnabled && value.ICPFilingNumber != "",
|
||||
ICPFilingNumber: value.ICPFilingNumber,
|
||||
Configured: setting != nil,
|
||||
Revision: revision,
|
||||
}
|
||||
@@ -556,6 +618,40 @@ func publicAppearanceSetting(setting *model.SystemSetting, value AppearanceSetti
|
||||
return result
|
||||
}
|
||||
|
||||
func effectiveAppearanceSEOTitle(value AppearanceSetting) string {
|
||||
if value.SEOTitle != "" {
|
||||
return value.SEOTitle
|
||||
}
|
||||
return value.BrandName
|
||||
}
|
||||
|
||||
func effectiveAppearanceSEODescription(value AppearanceSetting) string {
|
||||
if value.SEODescription != "" {
|
||||
return value.SEODescription
|
||||
}
|
||||
return value.BrandName + ",面向 AI 影视与短剧创作的工作台。"
|
||||
}
|
||||
|
||||
func effectiveAppearanceCopyright(value AppearanceSetting) string {
|
||||
if value.FooterCopyright != "" {
|
||||
return value.FooterCopyright
|
||||
}
|
||||
return fmt.Sprintf("© %d %s. All rights reserved.", time.Now().Year(), value.BrandName)
|
||||
}
|
||||
|
||||
func (s *Service) appearanceBrandName() string {
|
||||
brandName, _ := s.appearanceIdentity()
|
||||
return brandName
|
||||
}
|
||||
|
||||
func (s *Service) appearanceIdentity() (string, string) {
|
||||
_, value, err := s.readAppearance()
|
||||
if err != nil || strings.TrimSpace(value.BrandName) == "" {
|
||||
return defaultAppearanceBrandName, defaultAppearanceBrandSlug
|
||||
}
|
||||
return value.BrandName, value.BrandSlug
|
||||
}
|
||||
|
||||
func appearanceAssetURL(slot string, revision string) string {
|
||||
return "/api/public/appearance/assets/" + url.PathEscape(slot) + "?v=" + url.QueryEscape(revision)
|
||||
}
|
||||
@@ -0,0 +1,395 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strings"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
const maxAppearanceSkinThemes = 16
|
||||
|
||||
var (
|
||||
appearanceSkinIDPattern = regexp.MustCompile(`^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$`)
|
||||
appearanceColorPattern = regexp.MustCompile(`^#[0-9a-fA-F]{6}(?:[0-9a-fA-F]{2})?$`)
|
||||
)
|
||||
|
||||
// AppearanceSkinModeTokens is deliberately an allowlist instead of arbitrary CSS.
|
||||
// Every value is validated as a six- or eight-digit hex color before it is exposed
|
||||
// by the public appearance endpoint.
|
||||
type AppearanceSkinModeTokens struct {
|
||||
Canvas string `json:"canvas"`
|
||||
Surface string `json:"surface"`
|
||||
SurfaceSubtle string `json:"surfaceSubtle"`
|
||||
SurfaceRaised string `json:"surfaceRaised"`
|
||||
Overlay string `json:"overlay"`
|
||||
Text string `json:"text"`
|
||||
TextMuted string `json:"textMuted"`
|
||||
Border string `json:"border"`
|
||||
Control string `json:"control"`
|
||||
ControlHover string `json:"controlHover"`
|
||||
ControlActive string `json:"controlActive"`
|
||||
ControlBorder string `json:"controlBorder"`
|
||||
ControlFocus string `json:"controlFocus"`
|
||||
ControlDisabledBackground string `json:"controlDisabledBackground"`
|
||||
ControlDisabledForeground string `json:"controlDisabledForeground"`
|
||||
SwitchChecked string `json:"switchChecked"`
|
||||
SwitchCheckedHover string `json:"switchCheckedHover"`
|
||||
SwitchCheckedHandle string `json:"switchCheckedHandle"`
|
||||
SwitchUnchecked string `json:"switchUnchecked"`
|
||||
SwitchUncheckedHover string `json:"switchUncheckedHover"`
|
||||
SwitchUncheckedHandle string `json:"switchUncheckedHandle"`
|
||||
Primary string `json:"primary"`
|
||||
PrimaryHover string `json:"primaryHover"`
|
||||
PrimaryActive string `json:"primaryActive"`
|
||||
PrimaryForeground string `json:"primaryForeground"`
|
||||
Selected string `json:"selected"`
|
||||
SelectedHover string `json:"selectedHover"`
|
||||
SelectedActive string `json:"selectedActive"`
|
||||
SelectedForeground string `json:"selectedForeground"`
|
||||
Icon string `json:"icon"`
|
||||
IconMuted string `json:"iconMuted"`
|
||||
IconActive string `json:"iconActive"`
|
||||
Success string `json:"success"`
|
||||
Warning string `json:"warning"`
|
||||
Danger string `json:"danger"`
|
||||
DangerHover string `json:"dangerHover"`
|
||||
DangerActive string `json:"dangerActive"`
|
||||
DangerForeground string `json:"dangerForeground"`
|
||||
Info string `json:"info"`
|
||||
Workspace string `json:"workspace"`
|
||||
WorkspaceGrid string `json:"workspaceGrid"`
|
||||
AdminBackground string `json:"adminBackground"`
|
||||
AdminSurface string `json:"adminSurface"`
|
||||
AdminSubtle string `json:"adminSubtle"`
|
||||
AdminStrong string `json:"adminStrong"`
|
||||
AuthBackground string `json:"authBackground"`
|
||||
AuthPanel string `json:"authPanel"`
|
||||
AuthCard string `json:"authCard"`
|
||||
AuthAccent string `json:"authAccent"`
|
||||
AuthMuted string `json:"authMuted"`
|
||||
}
|
||||
|
||||
type AppearanceSkinComponentTokens struct {
|
||||
ButtonRadius int `json:"buttonRadius"`
|
||||
InputRadius int `json:"inputRadius"`
|
||||
CardRadius int `json:"cardRadius"`
|
||||
OverlayRadius int `json:"overlayRadius"`
|
||||
MenuRadius int `json:"menuRadius"`
|
||||
CheckboxRadius int `json:"checkboxRadius"`
|
||||
ControlHeight int `json:"controlHeight"`
|
||||
ControlHeightSmall int `json:"controlHeightSmall"`
|
||||
ControlHeightLarge int `json:"controlHeightLarge"`
|
||||
BorderWidth int `json:"borderWidth"`
|
||||
FocusRingWidth int `json:"focusRingWidth"`
|
||||
IconSize int `json:"iconSize"`
|
||||
ButtonFontWeight int `json:"buttonFontWeight"`
|
||||
HoverLift int `json:"hoverLift"`
|
||||
MotionFast int `json:"motionFast"`
|
||||
MotionNormal int `json:"motionNormal"`
|
||||
ShadowStyle string `json:"shadowStyle"`
|
||||
}
|
||||
|
||||
type AppearanceSkinTokens struct {
|
||||
Light AppearanceSkinModeTokens `json:"light"`
|
||||
Dark AppearanceSkinModeTokens `json:"dark"`
|
||||
Components AppearanceSkinComponentTokens `json:"components"`
|
||||
}
|
||||
|
||||
type AppearanceSkinTheme struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Locked bool `json:"locked"`
|
||||
Tokens AppearanceSkinTokens `json:"tokens"`
|
||||
}
|
||||
|
||||
func defaultAppearanceSkinThemes() []AppearanceSkinTheme {
|
||||
classic := defaultClassicAppearanceSkin()
|
||||
studio := cloneAppearanceSkin(classic, "studio-indigo", "青瓷工作室", "雾白青瓷 · 珊瑚点睛")
|
||||
studio.Tokens.Light = tintAppearanceSkinMode(studio.Tokens.Light, appearanceSkinPalette{
|
||||
canvas: "#f6f8f9", surface: "#ffffff", subtle: "#edf4f3", raised: "#d7e8e5", overlay: "#ffffff", text: "#142026", muted: "#607079", border: "#d5e0e2",
|
||||
primary: "#087f76", primaryHover: "#076d66", primaryActive: "#095c57", primaryForeground: "#ffffff", selected: "#dff4f0", selectedHover: "#ccebe6", selectedActive: "#b9e3dd", selectedForeground: "#075f59", info: "#dd7a38",
|
||||
switchChecked: "#087f76", switchCheckedHover: "#076d66", switchCheckedHandle: "#ffffff", switchUnchecked: "#a8b7b9", switchUncheckedHover: "#899b9e", switchUncheckedHandle: "#ffffff",
|
||||
success: "#16866f", warning: "#c46722", danger: "#c83f3a", dangerHover: "#ad3532", dangerActive: "#922e2c", dangerForeground: "#ffffff",
|
||||
workspace: "#ffffff", grid: "#e8f2f0", adminBackground: "#eef3f4", adminSurface: "#ffffff", adminSubtle: "#f5f9f9", adminStrong: "#dce9e8", authBackground: "#071a1d", authPanel: "#0b2226", authCard: "#0d272b", authAccent: "#72eadc", authMuted: "#8db9b4",
|
||||
})
|
||||
studio.Tokens.Dark = tintAppearanceSkinMode(studio.Tokens.Dark, appearanceSkinPalette{
|
||||
canvas: "#0b1215", surface: "#121d21", subtle: "#142428", raised: "#203a3b", overlay: "#172328", text: "#e7f4f2", muted: "#8ca6a7", border: "#294044",
|
||||
primary: "#43d8c7", primaryHover: "#72eadc", primaryActive: "#2db9aa", primaryForeground: "#052724", selected: "#193735", selectedHover: "#214743", selectedActive: "#28554f", selectedForeground: "#baf5ee", info: "#ff9e57",
|
||||
switchChecked: "#31bfae", switchCheckedHover: "#43d8c7", switchCheckedHandle: "#052724", switchUnchecked: "#3f5559", switchUncheckedHover: "#526a6d", switchUncheckedHandle: "#e7f4f2",
|
||||
success: "#4ade80", warning: "#ffb454", danger: "#ff7875", dangerHover: "#ff9a98", dangerActive: "#df5e5b", dangerForeground: "#2d0808",
|
||||
workspace: "#111d21", grid: "#17292c", adminBackground: "#0c171a", adminSurface: "#132126", adminSubtle: "#192a2e", adminStrong: "#21383a", authBackground: "#061416", authPanel: "#091c20", authCard: "#0d272b", authAccent: "#72eadc", authMuted: "#8db9b4",
|
||||
})
|
||||
studio.Tokens.Components = appearanceSkinComponentPreset(8, 8, 14, 14, 10, 5)
|
||||
|
||||
warm := cloneAppearanceSkin(classic, "warm-persimmon", "暖柿纸境", "米纸暖棕 · 柿橙强调")
|
||||
warm.Tokens.Light = tintAppearanceSkinMode(warm.Tokens.Light, appearanceSkinPalette{
|
||||
canvas: "#fbf7f2", surface: "#fffdf9", subtle: "#f6ebe3", raised: "#ead2c2", overlay: "#fffdf9", text: "#35261f", muted: "#806b61", border: "#e5d6cb",
|
||||
primary: "#b94f2f", primaryHover: "#9e4128", primaryActive: "#843621", primaryForeground: "#fffaf6", selected: "#f8e0cf", selectedHover: "#f1d1bb", selectedActive: "#e9c1a6", selectedForeground: "#8c3d25", info: "#c58a3b",
|
||||
switchChecked: "#a84a2f", switchCheckedHover: "#bd5b3c", switchCheckedHandle: "#fffaf6", switchUnchecked: "#c7b3a7", switchUncheckedHover: "#aa9182", switchUncheckedHandle: "#fffdf9",
|
||||
success: "#4d7f50", warning: "#bd6819", danger: "#bd3d32", dangerHover: "#a33229", dangerActive: "#892a23", dangerForeground: "#fffaf6",
|
||||
workspace: "#fffdf9", grid: "#f3e9e1", adminBackground: "#f6eee7", adminSurface: "#fffdf9", adminSubtle: "#faf3ed", adminStrong: "#ead8ca", authBackground: "#1f1410", authPanel: "#291813", authCard: "#361f17", authAccent: "#ffc08b", authMuted: "#b99d89",
|
||||
})
|
||||
warm.Tokens.Dark = tintAppearanceSkinMode(warm.Tokens.Dark, appearanceSkinPalette{
|
||||
canvas: "#1b1210", surface: "#291a16", subtle: "#33211b", raised: "#493027", overlay: "#31201a", text: "#f8e9df", muted: "#b89c8c", border: "#50372e",
|
||||
primary: "#ef8a61", primaryHover: "#ffab83", primaryActive: "#d87350", primaryForeground: "#37140a", selected: "#4b2a20", selectedHover: "#5b3427", selectedActive: "#6b3e2e", selectedForeground: "#ffd9c4", info: "#f0b36c",
|
||||
switchChecked: "#df7752", switchCheckedHover: "#ef8a61", switchCheckedHandle: "#37140a", switchUnchecked: "#65483d", switchUncheckedHover: "#7b5a4c", switchUncheckedHandle: "#f8e9df",
|
||||
success: "#8dcc72", warning: "#f2b35f", danger: "#ff8375", dangerHover: "#ffa094", dangerActive: "#df6a5e", dangerForeground: "#32100b",
|
||||
workspace: "#241714", grid: "#31201b", adminBackground: "#1c1210", adminSurface: "#291b17", adminSubtle: "#35231d", adminStrong: "#493027", authBackground: "#160d0a", authPanel: "#21120e", authCard: "#361f17", authAccent: "#ffc08b", authMuted: "#b99d89",
|
||||
})
|
||||
warm.Tokens.Components = appearanceSkinComponentPreset(10, 10, 16, 18, 12, 5)
|
||||
|
||||
violet := cloneAppearanceSkin(classic, "brand-violet", "霓光紫境", "冷白雾紫 · 夜幕电光")
|
||||
violet.Tokens.Light = tintAppearanceSkinMode(violet.Tokens.Light, appearanceSkinPalette{
|
||||
canvas: "#f8f7fc", surface: "#ffffff", subtle: "#f0eefb", raised: "#dfd9f5", overlay: "#ffffff", text: "#211b35", muted: "#716a86", border: "#ddd8ec",
|
||||
primary: "#6656d9", primaryHover: "#5847c7", primaryActive: "#4939b2", primaryForeground: "#ffffff", selected: "#ebe8ff", selectedHover: "#ded9ff", selectedActive: "#d0c9ff", selectedForeground: "#4f3fb5", info: "#8f61e8",
|
||||
switchChecked: "#6656d9", switchCheckedHover: "#5847c7", switchCheckedHandle: "#ffffff", switchUnchecked: "#b4afc5", switchUncheckedHover: "#9891ae", switchUncheckedHandle: "#ffffff",
|
||||
success: "#2f966e", warning: "#b96f16", danger: "#c73559", dangerHover: "#ac2c4b", dangerActive: "#912640", dangerForeground: "#ffffff",
|
||||
workspace: "#ffffff", grid: "#f0eef8", adminBackground: "#f1f0f7", adminSurface: "#ffffff", adminSubtle: "#f7f6fb", adminStrong: "#e4e0f1", authBackground: "#110d20", authPanel: "#17112b", authCard: "#211936", authAccent: "#b4a8ff", authMuted: "#958dad",
|
||||
})
|
||||
violet.Tokens.Dark = tintAppearanceSkinMode(violet.Tokens.Dark, appearanceSkinPalette{
|
||||
canvas: "#0f0c19", surface: "#171321", subtle: "#201a2f", raised: "#302746", overlay: "#1c1734", text: "#f2efff", muted: "#a9a2bd", border: "#39304d",
|
||||
primary: "#9a90ff", primaryHover: "#b5adff", primaryActive: "#8175ed", primaryForeground: "#171126", selected: "#292347", selectedHover: "#352d59", selectedActive: "#40366a", selectedForeground: "#ddd9ff", info: "#c45dff",
|
||||
switchChecked: "#8175ed", switchCheckedHover: "#9a90ff", switchCheckedHandle: "#171126", switchUnchecked: "#504967", switchUncheckedHover: "#665d7f", switchUncheckedHandle: "#f2efff",
|
||||
success: "#5bd6a2", warning: "#ffc46b", danger: "#ff7795", dangerHover: "#ff99ae", dangerActive: "#df607f", dangerForeground: "#310b17",
|
||||
workspace: "#15111f", grid: "#211b30", adminBackground: "#110e1a", adminSurface: "#191524", adminSubtle: "#211b30", adminStrong: "#302746", authBackground: "#0b0812", authPanel: "#120d20", authCard: "#211936", authAccent: "#b4a8ff", authMuted: "#958dad",
|
||||
})
|
||||
violet.Tokens.Components = appearanceSkinComponentPreset(7, 7, 12, 14, 9, 4)
|
||||
|
||||
return []AppearanceSkinTheme{classic, studio, warm, violet}
|
||||
}
|
||||
|
||||
func defaultClassicAppearanceSkin() AppearanceSkinTheme {
|
||||
return AppearanceSkinTheme{
|
||||
ID: "classic", Name: "经典黑白", Description: "项目原始样式 · 不可修改", Locked: true,
|
||||
Tokens: AppearanceSkinTokens{
|
||||
Light: AppearanceSkinModeTokens{
|
||||
Canvas: "#ffffff", Surface: "#ffffff", SurfaceSubtle: "#f7f7f7", SurfaceRaised: "#ececec", Overlay: "#ffffff", Text: "#171717", TextMuted: "#737373", Border: "#e5e5e5",
|
||||
Control: "#ffffff", ControlHover: "#f5f5f5", ControlActive: "#ececec", ControlBorder: "#d1d1d1", ControlFocus: "#171717", ControlDisabledBackground: "#f2f2f2", ControlDisabledForeground: "#a3a3a3", SwitchChecked: "#16a34a", SwitchCheckedHover: "#15803d", SwitchCheckedHandle: "#ffffff", SwitchUnchecked: "#b8b8b8", SwitchUncheckedHover: "#9f9f9f", SwitchUncheckedHandle: "#ffffff",
|
||||
Primary: "#171717", PrimaryHover: "#303030", PrimaryActive: "#404040", PrimaryForeground: "#ffffff", Selected: "#e8e8e8", SelectedHover: "#dedede", SelectedActive: "#d5d5d5", SelectedForeground: "#171717",
|
||||
Icon: "#3f3f46", IconMuted: "#a1a1aa", IconActive: "#171717", Success: "#16a34a", Warning: "#d97706", Danger: "#dc2626", DangerHover: "#b91c1c", DangerActive: "#991b1b", DangerForeground: "#ffffff", Info: "#2563eb", Workspace: "#ffffff", WorkspaceGrid: "#f3f3f3",
|
||||
AdminBackground: "#f3f4f6", AdminSurface: "#ffffff", AdminSubtle: "#f7f8fa", AdminStrong: "#eceff3", AuthBackground: "#08090c", AuthPanel: "#0b0c10", AuthCard: "#121318", AuthAccent: "#93c5fd", AuthMuted: "#8a8b91",
|
||||
},
|
||||
Dark: AppearanceSkinModeTokens{
|
||||
Canvas: "#0a0a0a", Surface: "#181818", SurfaceSubtle: "#202020", SurfaceRaised: "#2a2a2a", Overlay: "#1f1f20", Text: "#f5f5f5", TextMuted: "#a3a3a3", Border: "#2d2d2d",
|
||||
Control: "#202020", ControlHover: "#292929", ControlActive: "#333333", ControlBorder: "#4a4a4a", ControlFocus: "#f5f5f5", ControlDisabledBackground: "#252525", ControlDisabledForeground: "#737373", SwitchChecked: "#22c55e", SwitchCheckedHover: "#4ade80", SwitchCheckedHandle: "#071a0f", SwitchUnchecked: "#525252", SwitchUncheckedHover: "#686868", SwitchUncheckedHandle: "#f5f5f5",
|
||||
Primary: "#f5f5f5", PrimaryHover: "#ffffff", PrimaryActive: "#e5e5e5", PrimaryForeground: "#171717", Selected: "#2b2b2b", SelectedHover: "#343434", SelectedActive: "#3d3d3d", SelectedForeground: "#f5f5f5",
|
||||
Icon: "#d4d4d8", IconMuted: "#71717a", IconActive: "#ffffff", Success: "#4ade80", Warning: "#fbbf24", Danger: "#f87171", DangerHover: "#fca5a5", DangerActive: "#ef4444", DangerForeground: "#2b0808", Info: "#60a5fa", Workspace: "#181818", WorkspaceGrid: "#222222",
|
||||
AdminBackground: "#101010", AdminSurface: "#181818", AdminSubtle: "#202020", AdminStrong: "#2a2a2a", AuthBackground: "#08090c", AuthPanel: "#0b0c10", AuthCard: "#121318", AuthAccent: "#93c5fd", AuthMuted: "#8a8b91",
|
||||
},
|
||||
Components: appearanceSkinComponentPreset(6, 6, 12, 12, 8, 4),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type appearanceSkinPalette struct {
|
||||
canvas, surface, subtle, raised, overlay, text, muted, border string
|
||||
primary, primaryHover, primaryActive, primaryForeground, selected, selectedHover, selectedActive, selectedForeground string
|
||||
switchChecked, switchCheckedHover, switchCheckedHandle, switchUnchecked, switchUncheckedHover, switchUncheckedHandle string
|
||||
success, warning, danger, dangerHover, dangerActive, dangerForeground, info string
|
||||
workspace, grid, adminBackground, adminSurface, adminSubtle, adminStrong string
|
||||
authBackground, authPanel, authCard, authAccent, authMuted string
|
||||
}
|
||||
|
||||
func tintAppearanceSkinMode(value AppearanceSkinModeTokens, palette appearanceSkinPalette) AppearanceSkinModeTokens {
|
||||
value.Canvas, value.Surface, value.SurfaceSubtle, value.SurfaceRaised, value.Overlay = palette.canvas, palette.surface, palette.subtle, palette.raised, palette.overlay
|
||||
value.Text, value.TextMuted, value.Border = palette.text, palette.muted, palette.border
|
||||
value.Control, value.ControlHover, value.ControlActive, value.ControlBorder, value.ControlFocus = palette.surface, palette.subtle, palette.raised, palette.border, palette.primary
|
||||
value.ControlDisabledBackground, value.ControlDisabledForeground = palette.subtle, palette.muted
|
||||
value.SwitchChecked, value.SwitchCheckedHover, value.SwitchCheckedHandle = palette.switchChecked, palette.switchCheckedHover, palette.switchCheckedHandle
|
||||
value.SwitchUnchecked, value.SwitchUncheckedHover, value.SwitchUncheckedHandle = palette.switchUnchecked, palette.switchUncheckedHover, palette.switchUncheckedHandle
|
||||
value.Primary, value.PrimaryHover, value.PrimaryActive, value.PrimaryForeground = palette.primary, palette.primaryHover, palette.primaryActive, palette.primaryForeground
|
||||
value.Selected, value.SelectedHover, value.SelectedActive, value.SelectedForeground = palette.selected, palette.selectedHover, palette.selectedActive, palette.selectedForeground
|
||||
value.Icon, value.IconMuted, value.IconActive = palette.text, palette.muted, palette.primary
|
||||
value.Success, value.Warning, value.Danger = palette.success, palette.warning, palette.danger
|
||||
value.DangerHover, value.DangerActive, value.DangerForeground = palette.dangerHover, palette.dangerActive, palette.dangerForeground
|
||||
value.Info, value.Workspace, value.WorkspaceGrid = palette.info, palette.workspace, palette.grid
|
||||
value.AdminBackground, value.AdminSurface, value.AdminSubtle, value.AdminStrong = palette.adminBackground, palette.adminSurface, palette.adminSubtle, palette.adminStrong
|
||||
value.AuthBackground, value.AuthPanel, value.AuthCard, value.AuthAccent, value.AuthMuted = palette.authBackground, palette.authPanel, palette.authCard, palette.authAccent, palette.authMuted
|
||||
return value
|
||||
}
|
||||
|
||||
func appearanceSkinComponentPreset(buttonRadius, inputRadius, cardRadius, overlayRadius, menuRadius, checkboxRadius int) AppearanceSkinComponentTokens {
|
||||
return AppearanceSkinComponentTokens{
|
||||
ButtonRadius: buttonRadius, InputRadius: inputRadius, CardRadius: cardRadius, OverlayRadius: overlayRadius, MenuRadius: menuRadius, CheckboxRadius: checkboxRadius,
|
||||
ControlHeight: 36, ControlHeightSmall: 30, ControlHeightLarge: 42, BorderWidth: 1, FocusRingWidth: 2, IconSize: 16, ButtonFontWeight: 500,
|
||||
HoverLift: 1, MotionFast: 120, MotionNormal: 180, ShadowStyle: "soft",
|
||||
}
|
||||
}
|
||||
|
||||
func cloneAppearanceSkin(source AppearanceSkinTheme, id, name, description string) AppearanceSkinTheme {
|
||||
source.ID, source.Name, source.Description, source.Locked = id, name, description, false
|
||||
return source
|
||||
}
|
||||
|
||||
func normalizeAppearanceSkinThemes(themes []AppearanceSkinTheme) []AppearanceSkinTheme {
|
||||
result := make([]AppearanceSkinTheme, len(themes))
|
||||
copy(result, themes)
|
||||
builtins := defaultAppearanceSkinThemes()
|
||||
for index := range result {
|
||||
result[index].ID = strings.ToLower(strings.TrimSpace(result[index].ID))
|
||||
result[index].Name = strings.TrimSpace(result[index].Name)
|
||||
result[index].Description = strings.TrimSpace(result[index].Description)
|
||||
result[index].Locked = result[index].ID == defaultAppearanceSkinID
|
||||
var fallback AppearanceSkinTokens
|
||||
for _, builtin := range builtins {
|
||||
if builtin.ID == result[index].ID {
|
||||
fallback = builtin.Tokens
|
||||
break
|
||||
}
|
||||
}
|
||||
backfillAppearanceSkinModeColors(&result[index].Tokens.Light, fallback.Light)
|
||||
backfillAppearanceSkinModeColors(&result[index].Tokens.Dark, fallback.Dark)
|
||||
normalizeAppearanceSkinModeColors(&result[index].Tokens.Light)
|
||||
normalizeAppearanceSkinModeColors(&result[index].Tokens.Dark)
|
||||
result[index].Tokens.Components.ShadowStyle = strings.ToLower(strings.TrimSpace(result[index].Tokens.Components.ShadowStyle))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func backfillAppearanceSkinModeColors(mode *AppearanceSkinModeTokens, fallback AppearanceSkinModeTokens) {
|
||||
for _, field := range []struct {
|
||||
value *string
|
||||
fallback string
|
||||
derived string
|
||||
}{
|
||||
{&mode.SwitchChecked, fallback.SwitchChecked, mode.Primary},
|
||||
{&mode.SwitchCheckedHover, fallback.SwitchCheckedHover, mode.PrimaryHover},
|
||||
{&mode.SwitchCheckedHandle, fallback.SwitchCheckedHandle, mode.PrimaryForeground},
|
||||
{&mode.SwitchUnchecked, fallback.SwitchUnchecked, mode.ControlBorder},
|
||||
{&mode.SwitchUncheckedHover, fallback.SwitchUncheckedHover, mode.ControlActive},
|
||||
{&mode.SwitchUncheckedHandle, fallback.SwitchUncheckedHandle, mode.SelectedForeground},
|
||||
{&mode.DangerHover, fallback.DangerHover, mode.Danger},
|
||||
{&mode.DangerActive, fallback.DangerActive, mode.Danger},
|
||||
{&mode.DangerForeground, fallback.DangerForeground, mode.PrimaryForeground},
|
||||
} {
|
||||
if strings.TrimSpace(*field.value) != "" {
|
||||
continue
|
||||
}
|
||||
if field.fallback != "" {
|
||||
*field.value = field.fallback
|
||||
} else {
|
||||
*field.value = field.derived
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func normalizeAppearanceSkinModeColors(mode *AppearanceSkinModeTokens) {
|
||||
value := reflect.ValueOf(mode).Elem()
|
||||
for index := 0; index < value.NumField(); index++ {
|
||||
field := value.Field(index)
|
||||
field.SetString(strings.ToLower(strings.TrimSpace(field.String())))
|
||||
}
|
||||
}
|
||||
|
||||
func validateAppearanceSkinThemes(themes []AppearanceSkinTheme, selectedID string) error {
|
||||
if len(themes) == 0 || len(themes) > maxAppearanceSkinThemes {
|
||||
return BadAuthRequest(fmt.Sprintf("皮肤主题数量必须为 1 到 %d 套", maxAppearanceSkinThemes))
|
||||
}
|
||||
seen := make(map[string]struct{}, len(themes))
|
||||
foundSelected := false
|
||||
foundClassic := false
|
||||
classic := defaultClassicAppearanceSkin()
|
||||
for _, skin := range themes {
|
||||
if !appearanceSkinIDPattern.MatchString(skin.ID) {
|
||||
return BadAuthRequest("皮肤主题 ID 无效")
|
||||
}
|
||||
if _, exists := seen[skin.ID]; exists {
|
||||
return BadAuthRequest("皮肤主题 ID 不能重复")
|
||||
}
|
||||
seen[skin.ID] = struct{}{}
|
||||
if skin.ID == selectedID {
|
||||
foundSelected = true
|
||||
}
|
||||
if skin.ID == defaultAppearanceSkinID {
|
||||
foundClassic = true
|
||||
if skin.Name != classic.Name || skin.Description != classic.Description || !reflect.DeepEqual(skin.Tokens, classic.Tokens) {
|
||||
return BadAuthRequest("经典黑白为系统默认主题,不能修改或删除")
|
||||
}
|
||||
}
|
||||
if err := validateAppearanceSkinText(skin.Name, "皮肤主题名称", 40, true); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateAppearanceSkinText(skin.Description, "皮肤主题说明", 100, false); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateAppearanceSkinMode(skin.Tokens.Light); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateAppearanceSkinMode(skin.Tokens.Dark); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateAppearanceSkinComponents(skin.Tokens.Components); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if !foundClassic {
|
||||
return BadAuthRequest("经典黑白为系统默认主题,不能修改或删除")
|
||||
}
|
||||
if !foundSelected {
|
||||
return BadAuthRequest("当前启用的皮肤主题不存在")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateAppearanceSkinMode(mode AppearanceSkinModeTokens) error {
|
||||
value := reflect.ValueOf(mode)
|
||||
for index := 0; index < value.NumField(); index++ {
|
||||
if !appearanceColorPattern.MatchString(value.Field(index).String()) {
|
||||
return BadAuthRequest("皮肤颜色必须使用 6 或 8 位十六进制颜色")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateAppearanceSkinComponents(value AppearanceSkinComponentTokens) error {
|
||||
for _, candidate := range []struct {
|
||||
value, min, max int
|
||||
label string
|
||||
}{
|
||||
{value.ButtonRadius, 0, 32, "按钮圆角"}, {value.InputRadius, 0, 32, "输入框圆角"}, {value.CardRadius, 0, 40, "卡片圆角"}, {value.OverlayRadius, 0, 40, "弹层圆角"}, {value.MenuRadius, 0, 32, "菜单圆角"}, {value.CheckboxRadius, 0, 12, "勾选框圆角"},
|
||||
{value.ControlHeight, 30, 48, "控件高度"}, {value.ControlHeightSmall, 24, 40, "小控件高度"}, {value.ControlHeightLarge, 36, 56, "大控件高度"}, {value.BorderWidth, 1, 3, "描边宽度"}, {value.FocusRingWidth, 1, 4, "焦点环宽度"},
|
||||
{value.IconSize, 12, 24, "图标尺寸"}, {value.ButtonFontWeight, 400, 700, "按钮字重"}, {value.HoverLift, 0, 4, "悬停抬升"}, {value.MotionFast, 0, 400, "快速动效时长"}, {value.MotionNormal, 0, 800, "常规动效时长"},
|
||||
} {
|
||||
if candidate.value < candidate.min || candidate.value > candidate.max {
|
||||
return BadAuthRequest(fmt.Sprintf("%s必须在 %d 到 %d 之间", candidate.label, candidate.min, candidate.max))
|
||||
}
|
||||
}
|
||||
if value.ControlHeightSmall > value.ControlHeight || value.ControlHeight > value.ControlHeightLarge {
|
||||
return BadAuthRequest("控件高度须满足小号不大于标准、标准不大于大号")
|
||||
}
|
||||
if value.MotionFast > value.MotionNormal {
|
||||
return BadAuthRequest("快速动效时长不能大于常规动效时长")
|
||||
}
|
||||
if value.ShadowStyle != "none" && value.ShadowStyle != "soft" && value.ShadowStyle != "strong" {
|
||||
return BadAuthRequest("阴影风格无效")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateAppearanceSkinText(value, label string, maxRunes int, required bool) error {
|
||||
if required && value == "" {
|
||||
return BadAuthRequest(label + "不能为空")
|
||||
}
|
||||
if utf8.RuneCountInString(value) > maxRunes {
|
||||
return BadAuthRequest(fmt.Sprintf("%s不能超过 %d 个字符", label, maxRunes))
|
||||
}
|
||||
for _, char := range value {
|
||||
if unicode.IsControl(char) {
|
||||
return BadAuthRequest(label + "不能包含控制字符")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func activeAppearanceSkin(themes []AppearanceSkinTheme, id string) AppearanceSkinTheme {
|
||||
for _, skin := range themes {
|
||||
if skin.ID == id {
|
||||
return skin
|
||||
}
|
||||
}
|
||||
return defaultClassicAppearanceSkin()
|
||||
}
|
||||
@@ -27,15 +27,28 @@ func TestAppearanceDefaultsPreserveBuiltInBrand(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if appearance.Configured || appearance.SchemaVersion != appearanceSchemaVersion || appearance.BrandName != defaultAppearanceBrandName || appearance.BrandSlug != defaultAppearanceBrandSlug || appearance.AuthHeroTitle != defaultAppearanceHeroTitle || appearance.AuthHeroDescription != "" || appearance.LogoURL != defaultAppearanceLogoURL || appearance.DarkLogoURL != defaultAppearanceLogoURL || !appearance.LogoFrameEnabled || appearance.AuthVideoURL != defaultAppearanceVideoURL || appearance.AuthVideoPosterURL != defaultAppearancePosterURL || appearance.SkinID != defaultAppearanceSkinID {
|
||||
if appearance.Configured || appearance.SchemaVersion != appearanceSchemaVersion || appearance.BrandName != defaultAppearanceBrandName || appearance.BrandSlug != defaultAppearanceBrandSlug || appearance.AuthHeroTitle != defaultAppearanceHeroTitle || appearance.AuthHeroDescription != "" || appearance.LogoURL != defaultAppearanceLogoURL || appearance.DarkLogoURL != defaultAppearanceLogoURL || !appearance.LogoFrameEnabled || appearance.AuthVideoURL != defaultAppearanceVideoURL || appearance.AuthVideoPosterURL != defaultAppearancePosterURL || appearance.SkinID != defaultAppearanceSkinID || appearance.SEOTitle != defaultAppearanceBrandName || !strings.Contains(appearance.SEODescription, defaultAppearanceBrandName) || !strings.Contains(appearance.FooterCopyright, defaultAppearanceBrandName) || appearance.ICPFilingEnabled {
|
||||
t.Fatalf("Appearance() = %#v", appearance)
|
||||
}
|
||||
if appearance.LogoConfigured || appearance.DarkLogoConfigured || appearance.AuthVideoConfigured || appearance.AuthVideoPosterConfigured || appearance.Revision != "builtin" {
|
||||
t.Fatalf("Appearance() configured state = %#v", appearance)
|
||||
}
|
||||
if appearance.ActiveSkin.ID != defaultAppearanceSkinID || !appearance.ActiveSkin.Locked {
|
||||
t.Fatalf("Appearance() active skin = %#v", appearance.ActiveSkin)
|
||||
}
|
||||
if appearance.ActiveSkin.Tokens.Light.SwitchChecked == appearance.ActiveSkin.Tokens.Light.SwitchUnchecked || appearance.ActiveSkin.Tokens.Dark.SwitchChecked == appearance.ActiveSkin.Tokens.Dark.SwitchUnchecked || appearance.ActiveSkin.Tokens.Light.DangerForeground == "" {
|
||||
t.Fatalf("Appearance() state colors = %#v", appearance.ActiveSkin.Tokens)
|
||||
}
|
||||
adminAppearance, err := svc.AdminAppearance(&model.User{ID: "admin", Role: model.UserRoleAdmin, Status: model.UserStatusActive})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(adminAppearance.SkinThemes) != 4 || !adminAppearance.SkinThemes[0].Locked {
|
||||
t.Fatalf("AdminAppearance() skin library = %#v", adminAppearance.SkinThemes)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppearanceBackfillsVersionThreeFieldsForExistingSetting(t *testing.T) {
|
||||
func TestAppearanceBackfillsVersionSixFieldsForExistingSetting(t *testing.T) {
|
||||
svc, db, _, _ := newAppearanceTestService(t)
|
||||
legacy := model.SystemSetting{Key: appearanceSettingKey, ValueJSON: `{"schemaVersion":1,"brandName":"旧品牌","skinId":"classic"}`}
|
||||
if err := db.Create(&legacy).Error; err != nil {
|
||||
@@ -46,7 +59,7 @@ func TestAppearanceBackfillsVersionThreeFieldsForExistingSetting(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if appearance.SchemaVersion != appearanceSchemaVersion || appearance.BrandName != "旧品牌" || appearance.BrandSlug != defaultAppearanceBrandSlug || appearance.AuthHeroTitle != defaultAppearanceHeroTitle || appearance.AuthHeroDescription != "" || appearance.DarkLogoURL != defaultAppearanceLogoURL || !appearance.LogoFrameEnabled {
|
||||
if appearance.SchemaVersion != appearanceSchemaVersion || appearance.BrandName != "旧品牌" || appearance.BrandSlug != defaultAppearanceBrandSlug || appearance.AuthHeroTitle != defaultAppearanceHeroTitle || appearance.AuthHeroDescription != "" || appearance.DarkLogoURL != defaultAppearanceLogoURL || !appearance.LogoFrameEnabled || appearance.SEOTitle != "旧品牌" || !strings.Contains(appearance.SEODescription, "旧品牌") || !strings.Contains(appearance.FooterCopyright, "旧品牌") || appearance.ActiveSkin.ID != "classic" {
|
||||
t.Fatalf("legacy appearance = %#v", appearance)
|
||||
}
|
||||
}
|
||||
@@ -73,12 +86,18 @@ func TestUpdateAppearancePersistsAuditsAndUsesVersionedPublicAssets(t *testing.T
|
||||
LogoFrameEnabled: false,
|
||||
AuthVideoResourceID: "brand-video",
|
||||
AuthVideoPosterResourceID: "brand-poster",
|
||||
SkinID: defaultAppearanceSkinID,
|
||||
SkinID: "studio-indigo",
|
||||
SEOTitle: "HIMA Studio - AI 影视工作台",
|
||||
SEODescription: "面向 Agent、图片、视频、画布与短剧生产的一体化 AI 创作工作台。",
|
||||
SEOKeywords: "AI 影视,短剧,画布",
|
||||
FooterCopyright: "© 2026 HIMA Studio. All rights reserved.",
|
||||
ICPFilingEnabled: true,
|
||||
ICPFilingNumber: "蜀ICP备2026000000号-1",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !updated.Configured || updated.BrandName != "HIMA Studio" || updated.BrandSlug != "hima-studio" || updated.Public.BrandSlug != "hima-studio" || updated.AuthHeroTitle != "把灵感,\n变成可见的故事。" || updated.Public.AuthHeroDescription != "从画布开始,持续推进你的创作。" || !updated.Public.LogoConfigured || !updated.Public.DarkLogoConfigured || updated.Public.LogoFrameEnabled || !updated.Public.AuthVideoConfigured || !updated.Public.AuthVideoPosterConfigured {
|
||||
if !updated.Configured || updated.BrandName != "HIMA Studio" || updated.BrandSlug != "hima-studio" || updated.Public.BrandSlug != "hima-studio" || updated.AuthHeroTitle != "把灵感,\n变成可见的故事。" || updated.Public.AuthHeroDescription != "从画布开始,持续推进你的创作。" || !updated.Public.LogoConfigured || !updated.Public.DarkLogoConfigured || updated.Public.LogoFrameEnabled || !updated.Public.AuthVideoConfigured || !updated.Public.AuthVideoPosterConfigured || updated.Public.SkinID != "studio-indigo" || updated.Public.SEOTitle != "HIMA Studio - AI 影视工作台" || updated.Public.SEOKeywords != "AI 影视,短剧,画布" || !updated.Public.ICPFilingEnabled || updated.Public.ICPFilingNumber != "蜀ICP备2026000000号-1" {
|
||||
t.Fatalf("UpdateAppearance() = %#v", updated)
|
||||
}
|
||||
for _, assetURL := range []string{updated.Public.LogoURL, updated.Public.DarkLogoURL, updated.Public.AuthVideoURL, updated.Public.AuthVideoPosterURL} {
|
||||
@@ -93,6 +112,9 @@ func TestUpdateAppearancePersistsAuditsAndUsesVersionedPublicAssets(t *testing.T
|
||||
if strings.Contains(string(encodedPublic), "brand-logo") || strings.Contains(string(encodedPublic), "brand-logo-dark") || strings.Contains(string(encodedPublic), "brand-video") || strings.Contains(string(encodedPublic), "brand-poster") {
|
||||
t.Fatalf("public appearance leaked resource IDs: %s", encodedPublic)
|
||||
}
|
||||
if strings.Contains(string(encodedPublic), "skinThemes") {
|
||||
t.Fatalf("public appearance leaked the complete skin library: %s", encodedPublic)
|
||||
}
|
||||
var auditCount int64
|
||||
if err := db.Model(&model.AdminAuditEvent{}).Where("action = ?", "appearance.update").Count(&auditCount).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -230,6 +252,70 @@ func TestUpdateAppearanceValidatesLoginCopy(t *testing.T) {
|
||||
if err == nil || !strings.Contains(err.Error(), "英文品牌标识") {
|
||||
t.Fatalf("invalid slug error = %v", err)
|
||||
}
|
||||
_, err = svc.UpdateAppearance(admin, AppearanceSetting{BrandName: "HIMA Studio", BrandSlug: "hima-studio", AuthHeroTitle: defaultAppearanceHeroTitle, SkinID: "unknown-skin"})
|
||||
if err == nil || !strings.Contains(err.Error(), "皮肤主题") {
|
||||
t.Fatalf("invalid skin error = %v", err)
|
||||
}
|
||||
_, err = svc.UpdateAppearance(admin, AppearanceSetting{BrandName: "HIMA Studio", BrandSlug: "hima-studio", AuthHeroTitle: defaultAppearanceHeroTitle, SkinID: defaultAppearanceSkinID, ICPFilingEnabled: true})
|
||||
if err == nil || !strings.Contains(err.Error(), "备案号") {
|
||||
t.Fatalf("missing ICP number error = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppearanceSkinLibrarySupportsEditableCopiesAndProtectsClassic(t *testing.T) {
|
||||
svc, _, _, admin := newAppearanceTestService(t)
|
||||
themes := defaultAppearanceSkinThemes()
|
||||
custom := cloneAppearanceSkin(themes[0], "custom-editorial", "片场夜蓝", "自定义控件与明暗色")
|
||||
custom.Tokens.Light.Primary = "#123456"
|
||||
custom.Tokens.Light.PrimaryHover = "#234567"
|
||||
custom.Tokens.Dark.Primary = "#abcdef"
|
||||
custom.Tokens.Components.ButtonRadius = 14
|
||||
themes = append(themes, custom)
|
||||
legacyCustom := custom
|
||||
legacyCustom.Tokens.Light.SwitchChecked = ""
|
||||
legacyCustom.Tokens.Light.SwitchCheckedHover = ""
|
||||
legacyCustom.Tokens.Light.SwitchCheckedHandle = ""
|
||||
legacyCustom.Tokens.Light.SwitchUnchecked = ""
|
||||
legacyCustom.Tokens.Light.SwitchUncheckedHover = ""
|
||||
legacyCustom.Tokens.Light.SwitchUncheckedHandle = ""
|
||||
legacyCustom.Tokens.Light.DangerHover = ""
|
||||
legacyCustom.Tokens.Light.DangerActive = ""
|
||||
legacyCustom.Tokens.Light.DangerForeground = ""
|
||||
backfilled := normalizeAppearanceSkinThemes([]AppearanceSkinTheme{legacyCustom})[0]
|
||||
if backfilled.Tokens.Light.SwitchChecked != "#123456" || backfilled.Tokens.Light.SwitchCheckedHover != "#234567" || backfilled.Tokens.Light.SwitchUnchecked != legacyCustom.Tokens.Light.ControlBorder || backfilled.Tokens.Light.DangerHover != legacyCustom.Tokens.Light.Danger {
|
||||
t.Fatalf("legacy skin state backfill = %#v", backfilled.Tokens.Light)
|
||||
}
|
||||
|
||||
updated, err := svc.UpdateAppearance(admin, AppearanceSetting{
|
||||
BrandName: "HIMA Studio", BrandSlug: "hima-studio", AuthHeroTitle: defaultAppearanceHeroTitle,
|
||||
SkinID: custom.ID, SkinThemes: themes,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if updated.Public.ActiveSkin.ID != custom.ID || updated.Public.ActiveSkin.Tokens.Light.Primary != "#123456" || updated.Public.ActiveSkin.Tokens.Components.ButtonRadius != 14 || len(updated.SkinThemes) != 5 {
|
||||
t.Fatalf("custom skin round trip = %#v", updated)
|
||||
}
|
||||
|
||||
withoutClassic := append([]AppearanceSkinTheme(nil), themes[1:]...)
|
||||
_, err = svc.UpdateAppearance(admin, AppearanceSetting{BrandName: "HIMA Studio", BrandSlug: "hima-studio", AuthHeroTitle: defaultAppearanceHeroTitle, SkinID: custom.ID, SkinThemes: withoutClassic})
|
||||
if err == nil || !strings.Contains(err.Error(), "不能修改或删除") {
|
||||
t.Fatalf("missing classic error = %v", err)
|
||||
}
|
||||
|
||||
mutatedClassic := append([]AppearanceSkinTheme(nil), themes...)
|
||||
mutatedClassic[0].Name = "改名"
|
||||
_, err = svc.UpdateAppearance(admin, AppearanceSetting{BrandName: "HIMA Studio", BrandSlug: "hima-studio", AuthHeroTitle: defaultAppearanceHeroTitle, SkinID: custom.ID, SkinThemes: mutatedClassic})
|
||||
if err == nil || !strings.Contains(err.Error(), "不能修改或删除") {
|
||||
t.Fatalf("mutated classic error = %v", err)
|
||||
}
|
||||
|
||||
invalidColor := append([]AppearanceSkinTheme(nil), themes...)
|
||||
invalidColor[len(invalidColor)-1].Tokens.Light.Primary = "red; background:url(x)"
|
||||
_, err = svc.UpdateAppearance(admin, AppearanceSetting{BrandName: "HIMA Studio", BrandSlug: "hima-studio", AuthHeroTitle: defaultAppearanceHeroTitle, SkinID: custom.ID, SkinThemes: invalidColor})
|
||||
if err == nil || !strings.Contains(err.Error(), "十六进制") {
|
||||
t.Fatalf("invalid color error = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateAppearanceUploadSniffsBytesInsteadOfDeclaredMIME(t *testing.T) {
|
||||
|
||||
@@ -233,14 +233,15 @@ func (s *Service) ExportDiagnosticBundle(userID string, req DiagnosticExportRequ
|
||||
RedactionVersion: diagnosticRedactionVersion, Truncated: collection.Truncated,
|
||||
Counts: diagnosticCounts{ClientEvents: len(collection.ClientEvents), Tasks: len(collection.Tasks), TaskLogs: len(collection.TaskLogs), APICalls: len(collection.APICalls)},
|
||||
}
|
||||
data, err := buildDiagnosticZIP(bundleID, manifest, collection)
|
||||
brandName, brandSlug := s.appearanceIdentity()
|
||||
data, err := buildDiagnosticZIP(brandName, bundleID, manifest, collection)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(data) > diagnosticMaxBundleBytes {
|
||||
return nil, BadAuthRequest("诊断包超过 10 MB,请缩短时间范围后重试")
|
||||
}
|
||||
fileName := fmt.Sprintf("yingce-diagnostics-%s-%s.zip", time.Now().UTC().Format("20060102-150405"), bundleID)
|
||||
fileName := fmt.Sprintf("%s-diagnostics-%s-%s.zip", brandSlug, time.Now().UTC().Format("20060102-150405"), bundleID)
|
||||
return &DiagnosticBundle{BundleID: bundleID, FileName: fileName, Data: data}, nil
|
||||
}
|
||||
|
||||
@@ -372,7 +373,7 @@ func sanitizeDiagnosticAPICall(log model.ApiCallLog) diagnosticAPICallRecord {
|
||||
}
|
||||
}
|
||||
|
||||
func buildDiagnosticZIP(bundleID string, manifest diagnosticManifest, collection *diagnosticCollection) ([]byte, error) {
|
||||
func buildDiagnosticZIP(brandName string, bundleID string, manifest diagnosticManifest, collection *diagnosticCollection) ([]byte, error) {
|
||||
var buffer bytes.Buffer
|
||||
archive := zip.NewWriter(&buffer)
|
||||
manifestData, err := json.MarshalIndent(manifest, "", " ")
|
||||
@@ -383,7 +384,7 @@ func buildDiagnosticZIP(bundleID string, manifest diagnosticManifest, collection
|
||||
return nil, err
|
||||
}
|
||||
newline := string(rune(10))
|
||||
readme := fmt.Sprintf("影策用户诊断包%s%s诊断编号:%s%s时间范围:%s 至 %s%s%s该文件由用户主动导出,仅包含有限时间范围内的脱敏诊断摘要。%s", newline, newline, bundleID, newline, collection.Window.From.Format(time.RFC3339), collection.Window.To.Format(time.RFC3339), newline, newline, newline)
|
||||
readme := fmt.Sprintf("%s 用户诊断包%s%s诊断编号:%s%s时间范围:%s 至 %s%s%s该文件由用户主动导出,仅包含有限时间范围内的脱敏诊断摘要。%s", brandName, newline, newline, bundleID, newline, collection.Window.From.Format(time.RFC3339), collection.Window.To.Format(time.RFC3339), newline, newline, newline)
|
||||
if err := writeDiagnosticZipFile(archive, "README.txt", []byte(readme)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -40,17 +40,18 @@ type EmailSettingRequest struct {
|
||||
}
|
||||
|
||||
type PublicEmailSetting struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
Host string `json:"host"`
|
||||
Port int `json:"port"`
|
||||
Username string `json:"username"`
|
||||
Encryption string `json:"encryption"`
|
||||
FromEmail string `json:"fromEmail"`
|
||||
FromName string `json:"fromName"`
|
||||
HasPassword bool `json:"hasPassword"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Host string `json:"host"`
|
||||
Port int `json:"port"`
|
||||
Username string `json:"username"`
|
||||
Encryption string `json:"encryption"`
|
||||
FromEmail string `json:"fromEmail"`
|
||||
FromName string `json:"fromName"`
|
||||
FromNameInherited bool `json:"fromNameInherited"`
|
||||
HasPassword bool `json:"hasPassword"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
type emailSettingValue struct {
|
||||
@@ -72,7 +73,7 @@ func (s *Service) AdminEmailSetting(actor *model.User) (*PublicEmailSetting, err
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return publicEmailSetting(setting, value), nil
|
||||
return s.publicEmailSetting(setting, value), nil
|
||||
}
|
||||
|
||||
func (s *Service) UpdateEmailSetting(actor *model.User, req EmailSettingRequest) (*PublicEmailSetting, error) {
|
||||
@@ -106,7 +107,7 @@ func (s *Service) UpdateEmailSetting(actor *model.User, req EmailSettingRequest)
|
||||
if err := s.repo.SaveSystemSetting(&setting); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return publicEmailSetting(&setting, next), nil
|
||||
return s.publicEmailSetting(&setting, next), nil
|
||||
}
|
||||
|
||||
func (s *Service) EmailEnabled() (bool, error) {
|
||||
@@ -168,7 +169,9 @@ func (s *Service) SendRegistrationEmailCode(rawEmail string) error {
|
||||
if err := s.repo.Create(&record); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.deliverEmail(setting, email, "影策注册验证码", registrationEmailBody(code)); err != nil {
|
||||
brandName := s.appearanceBrandName()
|
||||
setting = resolveEmailSender(setting, brandName)
|
||||
if err := s.deliverEmail(setting, email, brandName+"注册验证码", registrationEmailBody(brandName, code)); err != nil {
|
||||
cleanupErr := s.repo.DeleteEmailVerificationCode(record.ID)
|
||||
if cleanupErr != nil {
|
||||
return errors.Join(
|
||||
@@ -278,14 +281,13 @@ func normalizeEmailSetting(value emailSettingValue) emailSettingValue {
|
||||
default:
|
||||
value.Encryption = "starttls"
|
||||
}
|
||||
if value.FromName == "" {
|
||||
value.FromName = "影策"
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func publicEmailSetting(setting *model.SystemSetting, value emailSettingValue) *PublicEmailSetting {
|
||||
result := &PublicEmailSetting{Enabled: value.Enabled, Host: value.Host, Port: value.Port, Username: value.Username, Encryption: value.Encryption, FromEmail: value.FromEmail, FromName: value.FromName, HasPassword: value.Password != ""}
|
||||
func (s *Service) publicEmailSetting(setting *model.SystemSetting, value emailSettingValue) *PublicEmailSetting {
|
||||
inherited := value.FromName == "" || value.FromName == defaultAppearanceBrandName
|
||||
value = resolveEmailSender(value, s.appearanceBrandName())
|
||||
result := &PublicEmailSetting{Enabled: value.Enabled, Host: value.Host, Port: value.Port, Username: value.Username, Encryption: value.Encryption, FromEmail: value.FromEmail, FromName: value.FromName, FromNameInherited: inherited, HasPassword: value.Password != ""}
|
||||
if setting != nil {
|
||||
result.UpdatedBy = setting.UpdatedBy
|
||||
result.CreatedAt = setting.CreatedAt
|
||||
@@ -294,6 +296,13 @@ func publicEmailSetting(setting *model.SystemSetting, value emailSettingValue) *
|
||||
return result
|
||||
}
|
||||
|
||||
func resolveEmailSender(value emailSettingValue, brandName string) emailSettingValue {
|
||||
if value.FromName == "" || value.FromName == defaultAppearanceBrandName {
|
||||
value.FromName = brandName
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func sendSMTPMail(setting emailSettingValue, recipient string, subject string, body string) error {
|
||||
address := net.JoinHostPort(setting.Host, strconv.Itoa(setting.Port))
|
||||
tlsConfig := &tls.Config{ServerName: setting.Host, MinVersion: tls.VersionTLS12}
|
||||
@@ -363,6 +372,6 @@ func randomNumericCode(length int) (string, error) {
|
||||
return fmt.Sprintf("%0*d", length, value.Int64()), nil
|
||||
}
|
||||
|
||||
func registrationEmailBody(code string) string {
|
||||
return "你正在注册影策。\n\n验证码:" + code + "\n\n验证码 10 分钟内有效。若非本人操作,请忽略本邮件。"
|
||||
func registrationEmailBody(brandName string, code string) string {
|
||||
return "你正在注册" + brandName + "。\n\n验证码:" + code + "\n\n验证码 10 分钟内有效。若非本人操作,请忽略本邮件。"
|
||||
}
|
||||
@@ -245,7 +245,7 @@ func (s *Service) ImportLibTV(userID, canvasProjectID, projectUUID string) (*Lib
|
||||
userID = strings.TrimSpace(userID)
|
||||
canvasProjectID = strings.TrimSpace(canvasProjectID)
|
||||
if userID == "" || canvasProjectID == "" {
|
||||
return nil, Unauthorized("请先打开已同步的影策画布")
|
||||
return nil, Unauthorized("请先打开已同步的" + s.appearanceBrandName() + "画布")
|
||||
}
|
||||
if _, err := s.repo.CanvasProjectForUser(userID, canvasProjectID); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -56,7 +56,7 @@ func adaptLibTVDetail(detail *libTVDetail) (*LibTVImportResult, error) {
|
||||
sourceType := strings.ToLower(strings.TrimSpace(data.Type))
|
||||
kind := sourceType
|
||||
if sourceType == "material-style" {
|
||||
// 风格素材没有普通生成 URL,但有可复用封面时可以降级为影策图片参考节点。
|
||||
// 风格素材没有普通生成 URL,但有可复用封面时可以降级为宿主图片参考节点。
|
||||
kind = "image"
|
||||
} else if kind != "image" && kind != "video" {
|
||||
result.SkippedNodes = append(result.SkippedNodes, LibTVImportIssue{ID: nodeKey, Name: raw.Name, Reason: "暂不支持的节点类型"})
|
||||
|
||||
@@ -74,7 +74,9 @@ func (s *Service) SendPasswordResetEmailCode(rawEmail string) error {
|
||||
if err := s.repo.Create(&record); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.deliverEmail(setting, email, "影策密码重置验证码", passwordResetEmailBody(code)); err != nil {
|
||||
brandName := s.appearanceBrandName()
|
||||
setting = resolveEmailSender(setting, brandName)
|
||||
if err := s.deliverEmail(setting, email, brandName+"密码重置验证码", passwordResetEmailBody(brandName, code)); err != nil {
|
||||
if cleanupErr := s.repo.DeleteEmailVerificationCode(record.ID); cleanupErr != nil {
|
||||
log.Printf("password reset email cleanup failed: recipient=%s error=%v", maskedEmail(email), cleanupErr)
|
||||
}
|
||||
@@ -144,8 +146,8 @@ func invalidPasswordResetCode() *AuthError {
|
||||
return BadAuthRequest("验证码无效或已过期")
|
||||
}
|
||||
|
||||
func passwordResetEmailBody(code string) string {
|
||||
return "你正在重置影策账号密码。\n\n验证码:" + code + "\n\n验证码 10 分钟内有效。若非本人操作,请忽略本邮件,并确保邮箱账号安全。"
|
||||
func passwordResetEmailBody(brandName string, code string) string {
|
||||
return "你正在重置" + brandName + "账号密码。\n\n验证码:" + code + "\n\n验证码 10 分钟内有效。若非本人操作,请忽略本邮件,并确保邮箱账号安全。"
|
||||
}
|
||||
|
||||
func maskedEmail(email string) string {
|
||||
|
||||
@@ -187,6 +187,65 @@ func TestPasswordResetDeliveryFailureRemovesUnusableCode(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCustomAppearanceBrandsRegistrationAndPasswordResetEmails(t *testing.T) {
|
||||
svc, db := newPasswordResetTestService(t)
|
||||
appearanceJSON, err := json.Marshal(AppearanceSetting{
|
||||
SchemaVersion: appearanceSchemaVersion,
|
||||
BrandName: "HIMA Studio",
|
||||
BrandSlug: "hima-studio",
|
||||
AuthHeroTitle: defaultAppearanceHeroTitle,
|
||||
LogoFrameEnabled: true,
|
||||
SkinID: defaultAppearanceSkinID,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.Create(&model.SystemSetting{Key: appearanceSettingKey, ValueJSON: string(appearanceJSON)}).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.Create(&model.SystemSetting{Key: registrationSettingKey, ValueJSON: `{"enabled":true}`}).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
passwordHash, err := hashPassword("strong-password")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
existing := model.User{ID: "brand-admin", Username: "brand-admin", Email: "admin@example.com", Role: model.UserRoleAdmin, Status: model.UserStatusActive, PasswordHash: passwordHash}
|
||||
resetUser := model.User{ID: "brand-user", Username: "brand-user", Email: "member@example.com", Role: model.UserRoleUser, Status: model.UserStatusActive, PasswordHash: passwordHash}
|
||||
if err := db.Create(&[]model.User{existing, resetUser}).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
type delivery struct {
|
||||
fromName string
|
||||
recipient string
|
||||
subject string
|
||||
body string
|
||||
}
|
||||
deliveries := make([]delivery, 0, 2)
|
||||
svc.mailSender = func(setting emailSettingValue, recipient string, subject string, body string) error {
|
||||
deliveries = append(deliveries, delivery{fromName: setting.FromName, recipient: recipient, subject: subject, body: body})
|
||||
return nil
|
||||
}
|
||||
if err := svc.SendRegistrationEmailCode("new-member@example.com"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := svc.SendPasswordResetEmailCode(resetUser.Email); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(deliveries) != 2 {
|
||||
t.Fatalf("deliveries = %d, want 2", len(deliveries))
|
||||
}
|
||||
for _, delivered := range deliveries {
|
||||
if delivered.fromName != "HIMA Studio" || !strings.Contains(delivered.subject, "HIMA Studio") || !strings.Contains(delivered.body, "HIMA Studio") || strings.Contains(delivered.subject, defaultAppearanceBrandName) || strings.Contains(delivered.body, defaultAppearanceBrandName) {
|
||||
t.Fatalf("email did not inherit custom appearance: %#v", delivered)
|
||||
}
|
||||
}
|
||||
if deliveries[0].subject != "HIMA Studio注册验证码" || deliveries[1].subject != "HIMA Studio密码重置验证码" {
|
||||
t.Fatalf("unexpected branded subjects: %#v", deliveries)
|
||||
}
|
||||
}
|
||||
|
||||
func newPasswordResetTestService(t *testing.T) (*Service, *gorm.DB) {
|
||||
t.Helper()
|
||||
db, err := gorm.Open(sqlite.Open("file:"+newID()+"?mode=memory&cache=shared"), &gorm.Config{})
|
||||
|
||||
@@ -41,9 +41,9 @@ func workflowPluginManifest(id, name, description string) protocol.Manifest {
|
||||
ID: id,
|
||||
Version: "1.0.0",
|
||||
Name: name,
|
||||
Vendor: "影策",
|
||||
Vendor: "内置工作流",
|
||||
Description: description,
|
||||
Documentation: "# " + name + "\n\n## 影策运行时合同\n\n该工作流能力由插件运行时统一管理。",
|
||||
Documentation: "# " + name + "\n\n## 宿主运行时合同\n\n该工作流能力由插件运行时统一管理。",
|
||||
Enabled: false,
|
||||
Installable: true,
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user