feat: add configurable platform appearance (#385)
This commit is contained in:
1 parent
a6504c0e00
commit
5dd515b8ab
31 files changed
+2795
-153
No files matched your search
@@ -49,3 +49,4 @@ assets/prototypes/.*.drawio.bkp
|
|||||||
camera_language_guide.md
|
camera_language_guide.md
|
||||||
.superdesign
|
.superdesign
|
||||||
.playwright-cli/
|
.playwright-cli/
|
||||||
|
/project-memory/
|
||||||
@@ -113,6 +113,7 @@ func run(ctx context.Context) error {
|
|||||||
registerSystemStatusRoutes(api, status)
|
registerSystemStatusRoutes(api, status)
|
||||||
handler.RegisterOAuthCallbackRoutes(r, svc)
|
handler.RegisterOAuthCallbackRoutes(r, svc)
|
||||||
handler.RegisterAuthRoutes(api, svc)
|
handler.RegisterAuthRoutes(api, svc)
|
||||||
|
handler.RegisterAppearanceRoutes(api, svc)
|
||||||
handler.RegisterFeatureAvailabilityRoutes(api, svc)
|
handler.RegisterFeatureAvailabilityRoutes(api, svc)
|
||||||
handler.RegisterResponseInterceptionRoutes(api, svc)
|
handler.RegisterResponseInterceptionRoutes(api, svc)
|
||||||
handler.RegisterAdminRoutes(api, svc)
|
handler.RegisterAdminRoutes(api, svc)
|
||||||
|
|||||||
@@ -0,0 +1,136 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"infinite-canvas/backend/internal/service"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
func RegisterAppearanceRoutes(r *gin.RouterGroup, svc *service.Service) {
|
||||||
|
r.GET("/public/appearance", func(c *gin.Context) {
|
||||||
|
setting, err := svc.Appearance()
|
||||||
|
if err != nil {
|
||||||
|
failService(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.Header("Cache-Control", "no-store")
|
||||||
|
ok(c, gin.H{"appearance": setting})
|
||||||
|
})
|
||||||
|
|
||||||
|
r.GET("/public/appearance/assets/:slot", func(c *gin.Context) {
|
||||||
|
stream, err := svc.OpenAppearanceAsset(c.Param("slot"), c.GetHeader("Range"))
|
||||||
|
if err != nil {
|
||||||
|
failService(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer stream.Body.Close()
|
||||||
|
resource := stream.Resource
|
||||||
|
mimeType := resource.MimeType
|
||||||
|
if mimeType == "" {
|
||||||
|
mimeType = "application/octet-stream"
|
||||||
|
}
|
||||||
|
if c.Query("v") != "" {
|
||||||
|
c.Header("Cache-Control", "public, max-age=31536000, immutable")
|
||||||
|
} else {
|
||||||
|
c.Header("Cache-Control", "public, no-cache")
|
||||||
|
}
|
||||||
|
c.Header("Accept-Ranges", "bytes")
|
||||||
|
c.Header("Referrer-Policy", "no-referrer")
|
||||||
|
c.Header("X-Content-Type-Options", "nosniff")
|
||||||
|
if stream.ContentRange != "" {
|
||||||
|
c.Header("Content-Range", stream.ContentRange)
|
||||||
|
}
|
||||||
|
if seeker, available := stream.Body.(io.ReadSeeker); available {
|
||||||
|
c.Header("Content-Type", mimeType)
|
||||||
|
http.ServeContent(c.Writer, c.Request, resource.ID, resource.UpdatedAt, seeker)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.DataFromReader(stream.StatusCode, stream.ContentLength, mimeType, stream.Body, nil)
|
||||||
|
})
|
||||||
|
|
||||||
|
r.GET("/admin/settings/appearance", func(c *gin.Context) {
|
||||||
|
actor, err := currentUser(c, svc)
|
||||||
|
if err != nil {
|
||||||
|
failService(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
setting, err := svc.AdminAppearance(actor)
|
||||||
|
if err != nil {
|
||||||
|
failService(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ok(c, gin.H{"setting": setting})
|
||||||
|
})
|
||||||
|
|
||||||
|
r.PATCH("/admin/settings/appearance", func(c *gin.Context) {
|
||||||
|
actor, err := currentUser(c, svc)
|
||||||
|
if err != nil {
|
||||||
|
failService(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
current, err := svc.AdminAppearance(actor)
|
||||||
|
if err != nil {
|
||||||
|
failService(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, 32<<10)
|
||||||
|
req := current.AppearanceSetting
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
fail(c, http.StatusBadRequest, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
setting, err := svc.UpdateAppearance(actor, req)
|
||||||
|
if err != nil {
|
||||||
|
failService(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ok(c, gin.H{"setting": setting})
|
||||||
|
})
|
||||||
|
|
||||||
|
r.DELETE("/admin/settings/appearance", func(c *gin.Context) {
|
||||||
|
actor, err := currentUser(c, svc)
|
||||||
|
if err != nil {
|
||||||
|
failService(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
setting, err := svc.ResetAppearance(actor)
|
||||||
|
if err != nil {
|
||||||
|
failService(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ok(c, gin.H{"setting": setting})
|
||||||
|
})
|
||||||
|
|
||||||
|
r.POST("/admin/settings/appearance/assets/:slot", func(c *gin.Context) {
|
||||||
|
actor, err := currentUser(c, svc)
|
||||||
|
if err != nil {
|
||||||
|
failService(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
policy, available := loadRuntimePolicy(c, svc)
|
||||||
|
if !available || !enforceRateLimit(c, "admin-appearance-upload:"+actor.ID, policy.Request.ResourceUploadPerMinute, time.Minute) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
maxBytes, err := service.AppearanceAssetMaxBytes(c.Param("slot"))
|
||||||
|
if err != nil {
|
||||||
|
failService(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, maxBytes+(1<<20))
|
||||||
|
file, err := c.FormFile("file")
|
||||||
|
if err != nil {
|
||||||
|
fail(c, http.StatusBadRequest, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resource, err := svc.UploadAppearanceAsset(actor, c.Param("slot"), file)
|
||||||
|
if err != nil {
|
||||||
|
failService(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ok(c, gin.H{"resource": resource})
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"infinite-canvas/backend/internal/service"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAppearanceRoutesAreRegistered(t *testing.T) {
|
||||||
|
gin.SetMode(gin.TestMode)
|
||||||
|
router := gin.New()
|
||||||
|
RegisterAppearanceRoutes(router.Group("/api"), &service.Service{})
|
||||||
|
wanted := map[string]bool{
|
||||||
|
"GET /api/public/appearance": false,
|
||||||
|
"GET /api/public/appearance/assets/:slot": false,
|
||||||
|
"GET /api/admin/settings/appearance": false,
|
||||||
|
"PATCH /api/admin/settings/appearance": false,
|
||||||
|
"DELETE /api/admin/settings/appearance": false,
|
||||||
|
"POST /api/admin/settings/appearance/assets/:slot": false,
|
||||||
|
}
|
||||||
|
for _, route := range router.Routes() {
|
||||||
|
key := route.Method + " " + route.Path
|
||||||
|
if _, exists := wanted[key]; exists {
|
||||||
|
wanted[key] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for route, found := range wanted {
|
||||||
|
if !found {
|
||||||
|
t.Errorf("route %s is not registered", route)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -83,6 +83,15 @@ func (s *Service) DeleteAdminResources(actor *model.User, req AdminResourceDelet
|
|||||||
blocked.References = appendUniqueAdminResourceReference(blocked.References, AdminResourceReferenceView{Kind: reference.Kind, ID: reference.ID, Title: reference.Title})
|
blocked.References = appendUniqueAdminResourceReference(blocked.References, AdminResourceReferenceView{Kind: reference.Kind, ID: reference.ID, Title: reference.Title})
|
||||||
blockedByID[reference.ResourceID] = blocked
|
blockedByID[reference.ResourceID] = blocked
|
||||||
}
|
}
|
||||||
|
for resourceID, references := range s.appearanceResourceReferences(resourceIDs) {
|
||||||
|
for _, reference := range references {
|
||||||
|
blocked := blockedByID[resourceID]
|
||||||
|
blocked.ID = resourceID
|
||||||
|
blocked.Reason = "资源仍被业务数据引用"
|
||||||
|
blocked.References = appendUniqueAdminResourceReference(blocked.References, reference)
|
||||||
|
blockedByID[resourceID] = blocked
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
deletable := make([]model.Resource, 0, len(resources))
|
deletable := make([]model.Resource, 0, len(resources))
|
||||||
deletableIDs := make([]string, 0, len(resources))
|
deletableIDs := make([]string, 0, len(resources))
|
||||||
|
|||||||
@@ -69,6 +69,26 @@ func TestDeleteAdminResourcesBlocksAnnouncementImage(t *testing.T) {
|
|||||||
assertModelCount(t, db, &model.Resource{}, "id = ?", 1, resource.ID)
|
assertModelCount(t, db, &model.Resource{}, "id = ?", 1, resource.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDeleteAdminResourcesBlocksDarkAppearanceLogo(t *testing.T) {
|
||||||
|
svc, db, _, admin := newAdminStorageDeleteTestService(t)
|
||||||
|
resource := model.Resource{ID: "appearance-logo", UserID: admin.ID, Kind: "image", Status: model.ResourceStatusReady, Provider: "local", ObjectKey: "appearance/logo.png", MimeType: "image/png"}
|
||||||
|
if err := db.Create(&resource).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := svc.UpdateAppearance(admin, AppearanceSetting{BrandName: "HIMA Studio", BrandSlug: "hima-studio", AuthHeroTitle: defaultAppearanceHeroTitle, DarkLogoResourceID: resource.ID, LogoFrameEnabled: true, SkinID: defaultAppearanceSkinID}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := svc.DeleteAdminResources(admin, AdminResourceDeleteRequest{ResourceIDs: []string{resource.ID}})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if len(result.Deleted) != 0 || len(result.Blocked) != 1 || len(result.Blocked[0].References) != 1 || result.Blocked[0].References[0].Kind != "外观" {
|
||||||
|
t.Fatalf("result = %#v", result)
|
||||||
|
}
|
||||||
|
assertModelCount(t, db, &model.Resource{}, "id = ?", 1, resource.ID)
|
||||||
|
}
|
||||||
|
|
||||||
func TestDeleteAdminResourcesKeepsSharedPhysicalObject(t *testing.T) {
|
func TestDeleteAdminResourcesKeepsSharedPhysicalObject(t *testing.T) {
|
||||||
svc, db, _, admin := newAdminStorageDeleteTestService(t)
|
svc, db, _, admin := newAdminStorageDeleteTestService(t)
|
||||||
resources := []model.Resource{
|
resources := []model.Resource{
|
||||||
|
|||||||
@@ -0,0 +1,561 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/binary"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"mime/multipart"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
"unicode"
|
||||||
|
"unicode/utf8"
|
||||||
|
|
||||||
|
"infinite-canvas/backend/internal/model"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
const appearanceSettingKey = "appearance"
|
||||||
|
|
||||||
|
const (
|
||||||
|
AppearanceAssetLogo = "logo"
|
||||||
|
AppearanceAssetDarkLogo = "logo-dark"
|
||||||
|
AppearanceAssetVideo = "video"
|
||||||
|
AppearanceAssetPoster = "poster"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
appearanceSchemaVersion = 3
|
||||||
|
appearanceLogoMaxBytes int64 = 5 << 20
|
||||||
|
appearancePosterMaxBytes int64 = 10 << 20
|
||||||
|
appearanceVideoMaxBytes int64 = 256 << 20
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
defaultAppearanceBrandName = "影策"
|
||||||
|
defaultAppearanceBrandSlug = "open-ai-canvas"
|
||||||
|
defaultAppearanceSkinID = "classic"
|
||||||
|
defaultAppearanceLogoURL = "/logo.svg"
|
||||||
|
defaultAppearanceVideoURL = "https://boss-shjd.biliapi.net/updream/aniforge/video/video_bbcb00bd-650d-4249-9346-5cd21fd2484c_m1hc-u0-1pu13x-3v1s.mp4"
|
||||||
|
defaultAppearancePosterURL = "https://i0.hdslb.com/bfs/aitool/aniforge/image/02933f26-5f1b-49ff-a811-b7f95ee5e5b8_m1hc-u0-sau.jpg"
|
||||||
|
defaultAppearanceHeroTitle = "让一个故事,\n从文字走向银幕。"
|
||||||
|
)
|
||||||
|
|
||||||
|
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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type AdminAppearanceSetting struct {
|
||||||
|
AppearanceSetting
|
||||||
|
Public PublicAppearanceSetting `json:"public"`
|
||||||
|
Configured bool `json:"configured"`
|
||||||
|
UpdatedBy string `json:"updatedBy,omitempty"`
|
||||||
|
CreatedAt time.Time `json:"createdAt,omitempty"`
|
||||||
|
UpdatedAt time.Time `json:"updatedAt,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func defaultAppearanceSetting() AppearanceSetting {
|
||||||
|
return AppearanceSetting{
|
||||||
|
SchemaVersion: appearanceSchemaVersion,
|
||||||
|
BrandName: defaultAppearanceBrandName,
|
||||||
|
BrandSlug: defaultAppearanceBrandSlug,
|
||||||
|
AuthHeroTitle: defaultAppearanceHeroTitle,
|
||||||
|
LogoFrameEnabled: true,
|
||||||
|
SkinID: defaultAppearanceSkinID,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func AppearanceAssetMaxBytes(slot string) (int64, error) {
|
||||||
|
switch strings.TrimSpace(slot) {
|
||||||
|
case AppearanceAssetLogo, AppearanceAssetDarkLogo:
|
||||||
|
return appearanceLogoMaxBytes, nil
|
||||||
|
case AppearanceAssetPoster:
|
||||||
|
return appearancePosterMaxBytes, nil
|
||||||
|
case AppearanceAssetVideo:
|
||||||
|
return appearanceVideoMaxBytes, nil
|
||||||
|
default:
|
||||||
|
return 0, BadAuthRequest("外观资源类型无效")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Service) Appearance() (*PublicAppearanceSetting, error) {
|
||||||
|
setting, value, err := s.readAppearance()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return publicAppearanceSetting(setting, value), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Service) AdminAppearance(actor *model.User) (*AdminAppearanceSetting, error) {
|
||||||
|
if err := s.RequireAdmin(actor); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
setting, value, err := s.readAppearance()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
result := &AdminAppearanceSetting{
|
||||||
|
AppearanceSetting: value,
|
||||||
|
Public: *publicAppearanceSetting(setting, value),
|
||||||
|
Configured: setting != nil,
|
||||||
|
}
|
||||||
|
if setting != nil {
|
||||||
|
result.UpdatedBy = setting.UpdatedBy
|
||||||
|
result.CreatedAt = setting.CreatedAt
|
||||||
|
result.UpdatedAt = setting.UpdatedAt
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Service) UpdateAppearance(actor *model.User, value AppearanceSetting) (*AdminAppearanceSetting, error) {
|
||||||
|
if err := s.RequireAdmin(actor); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
value.SchemaVersion = appearanceSchemaVersion
|
||||||
|
value.BrandName = strings.TrimSpace(value.BrandName)
|
||||||
|
value.BrandSlug = strings.ToLower(strings.TrimSpace(value.BrandSlug))
|
||||||
|
value.AuthHeroTitle = normalizeAppearanceCopy(value.AuthHeroTitle)
|
||||||
|
value.AuthHeroDescription = normalizeAppearanceCopy(value.AuthHeroDescription)
|
||||||
|
value.LogoResourceID = strings.TrimSpace(value.LogoResourceID)
|
||||||
|
value.DarkLogoResourceID = strings.TrimSpace(value.DarkLogoResourceID)
|
||||||
|
value.AuthVideoResourceID = strings.TrimSpace(value.AuthVideoResourceID)
|
||||||
|
value.AuthVideoPosterResourceID = strings.TrimSpace(value.AuthVideoPosterResourceID)
|
||||||
|
value.SkinID = strings.TrimSpace(value.SkinID)
|
||||||
|
if err := validateAppearanceSetting(value); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
s.storageMu.Lock()
|
||||||
|
defer s.storageMu.Unlock()
|
||||||
|
current, before, err := s.readAppearance()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, candidate := range []struct {
|
||||||
|
slot string
|
||||||
|
resourceID string
|
||||||
|
currentID string
|
||||||
|
}{
|
||||||
|
{slot: AppearanceAssetLogo, resourceID: value.LogoResourceID, currentID: before.LogoResourceID},
|
||||||
|
{slot: AppearanceAssetDarkLogo, resourceID: value.DarkLogoResourceID, currentID: before.DarkLogoResourceID},
|
||||||
|
{slot: AppearanceAssetVideo, resourceID: value.AuthVideoResourceID, currentID: before.AuthVideoResourceID},
|
||||||
|
{slot: AppearanceAssetPoster, resourceID: value.AuthVideoPosterResourceID, currentID: before.AuthVideoPosterResourceID},
|
||||||
|
} {
|
||||||
|
if err := s.validateAppearanceResource(actor, candidate.slot, candidate.resourceID, candidate.currentID); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
encoded, err := json.Marshal(value)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
setting := model.SystemSetting{Key: appearanceSettingKey, ValueJSON: string(encoded), UpdatedBy: actor.ID}
|
||||||
|
if current != nil {
|
||||||
|
setting.CreatedAt = current.CreatedAt
|
||||||
|
}
|
||||||
|
if err := s.repo.SaveSystemSetting(&setting); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := s.appendAdminAudit(actor, "appearance.update", "system_setting", appearanceSettingKey, "更新外观配置", map[string]any{"before": before, "after": value}); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return s.AdminAppearance(actor)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Service) ResetAppearance(actor *model.User) (*AdminAppearanceSetting, error) {
|
||||||
|
if err := s.RequireAdmin(actor); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
s.storageMu.Lock()
|
||||||
|
defer s.storageMu.Unlock()
|
||||||
|
_, before, err := s.readAppearance()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := s.repo.DeleteSystemSetting(appearanceSettingKey); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
after := defaultAppearanceSetting()
|
||||||
|
if err := s.appendAdminAudit(actor, "appearance.reset", "system_setting", appearanceSettingKey, "恢复影策默认品牌标识", map[string]any{"before": before, "after": after}); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return s.AdminAppearance(actor)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Service) UploadAppearanceAsset(actor *model.User, slot string, header *multipart.FileHeader) (*model.Resource, error) {
|
||||||
|
if err := s.RequireAdmin(actor); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
mimeType, err := validateAppearanceUpload(slot, header)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// UploadResource otherwise trusts a non-empty declared MIME. Replace it with
|
||||||
|
// the sniffed value so the persisted resource contract matches the bytes.
|
||||||
|
header.Header.Set("Content-Type", mimeType)
|
||||||
|
kind := "image"
|
||||||
|
if slot == AppearanceAssetVideo {
|
||||||
|
kind = "video"
|
||||||
|
}
|
||||||
|
resource, err := s.UploadResource(actor.ID, header, kind, 0, 0, 0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
resource.PublicURL = ""
|
||||||
|
return resource, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Service) OpenAppearanceAsset(slot string, rangeHeader string) (*ResourceStream, error) {
|
||||||
|
_, value, err := s.readAppearance()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
resourceID := appearanceResourceID(value, slot)
|
||||||
|
if resourceID == "" {
|
||||||
|
return nil, NotFound("未配置该外观资源")
|
||||||
|
}
|
||||||
|
resource, err := s.repo.Resource(resourceID)
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
return nil, NotFound("外观资源不存在")
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := validateAppearanceResourceType(slot, resource); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return s.openResourceRange(resource.UserID, resource, rangeHeader)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Service) appearanceResourceReferences(resourceIDs []string) map[string][]AdminResourceReferenceView {
|
||||||
|
result := make(map[string][]AdminResourceReferenceView)
|
||||||
|
_, value, err := s.readAppearance()
|
||||||
|
if err != nil {
|
||||||
|
// Invalid appearance JSON must fail closed for deletion. The caller turns
|
||||||
|
// this sentinel into a visible blocked reference instead of deleting files.
|
||||||
|
for _, resourceID := range resourceIDs {
|
||||||
|
result[resourceID] = []AdminResourceReferenceView{{Kind: "外观", ID: appearanceSettingKey, Title: "外观配置无法读取"}}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
candidates := []struct {
|
||||||
|
resourceID string
|
||||||
|
title string
|
||||||
|
}{
|
||||||
|
{resourceID: value.LogoResourceID, title: "浅色模式品牌 Logo"},
|
||||||
|
{resourceID: value.DarkLogoResourceID, title: "深色模式品牌 Logo"},
|
||||||
|
{resourceID: value.AuthVideoResourceID, title: "登录页品牌视频"},
|
||||||
|
{resourceID: value.AuthVideoPosterResourceID, title: "登录页视频封面"},
|
||||||
|
}
|
||||||
|
wanted := make(map[string]struct{}, len(resourceIDs))
|
||||||
|
for _, resourceID := range resourceIDs {
|
||||||
|
wanted[resourceID] = struct{}{}
|
||||||
|
}
|
||||||
|
for _, candidate := range candidates {
|
||||||
|
if candidate.resourceID == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if _, exists := wanted[candidate.resourceID]; exists {
|
||||||
|
result[candidate.resourceID] = appendUniqueAdminResourceReference(result[candidate.resourceID], AdminResourceReferenceView{Kind: "外观", ID: appearanceSettingKey, Title: candidate.title})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Service) readAppearance() (*model.SystemSetting, AppearanceSetting, error) {
|
||||||
|
setting, err := s.repo.SystemSetting(appearanceSettingKey)
|
||||||
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
return nil, defaultAppearanceSetting(), nil
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, AppearanceSetting{}, err
|
||||||
|
}
|
||||||
|
value := defaultAppearanceSetting()
|
||||||
|
if strings.TrimSpace(setting.ValueJSON) == "" || json.Unmarshal([]byte(setting.ValueJSON), &value) != nil {
|
||||||
|
return nil, AppearanceSetting{}, errors.New("外观配置格式无效")
|
||||||
|
}
|
||||||
|
value.SchemaVersion = appearanceSchemaVersion
|
||||||
|
value.BrandName = strings.TrimSpace(value.BrandName)
|
||||||
|
if value.BrandName == "" {
|
||||||
|
value.BrandName = defaultAppearanceBrandName
|
||||||
|
}
|
||||||
|
value.BrandSlug = strings.ToLower(strings.TrimSpace(value.BrandSlug))
|
||||||
|
if value.BrandSlug == "" {
|
||||||
|
value.BrandSlug = defaultAppearanceBrandSlug
|
||||||
|
}
|
||||||
|
value.AuthHeroTitle = normalizeAppearanceCopy(value.AuthHeroTitle)
|
||||||
|
if value.AuthHeroTitle == "" {
|
||||||
|
value.AuthHeroTitle = defaultAppearanceHeroTitle
|
||||||
|
}
|
||||||
|
value.AuthHeroDescription = normalizeAppearanceCopy(value.AuthHeroDescription)
|
||||||
|
value.SkinID = strings.TrimSpace(value.SkinID)
|
||||||
|
if value.SkinID == "" {
|
||||||
|
value.SkinID = defaultAppearanceSkinID
|
||||||
|
}
|
||||||
|
return setting, value, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func validateAppearanceSetting(value AppearanceSetting) error {
|
||||||
|
if value.BrandName == "" || utf8.RuneCountInString(value.BrandName) > 40 {
|
||||||
|
return BadAuthRequest("品牌名称必须为 1 到 40 个字符")
|
||||||
|
}
|
||||||
|
for _, char := range value.BrandName {
|
||||||
|
if unicode.IsControl(char) {
|
||||||
|
return BadAuthRequest("品牌名称不能包含控制字符")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !validAppearanceBrandSlug(value.BrandSlug) {
|
||||||
|
return BadAuthRequest("英文品牌标识须为 1 到 48 位小写字母、数字或连字符,且不能以连字符开头或结尾")
|
||||||
|
}
|
||||||
|
if err := validateAppearanceCopy(value.AuthHeroTitle, "登录页主标题", 80, true); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := validateAppearanceCopy(value.AuthHeroDescription, "登录页说明文案", 160, false); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if value.SkinID != defaultAppearanceSkinID {
|
||||||
|
return BadAuthRequest("当前版本仅支持经典皮肤")
|
||||||
|
}
|
||||||
|
for _, resourceID := range []string{value.LogoResourceID, value.DarkLogoResourceID, value.AuthVideoResourceID, value.AuthVideoPosterResourceID} {
|
||||||
|
if len(resourceID) > 80 {
|
||||||
|
return BadAuthRequest("外观资源 ID 无效")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func normalizeAppearanceCopy(value string) string {
|
||||||
|
return strings.TrimSpace(strings.ReplaceAll(strings.ReplaceAll(value, "\r\n", "\n"), "\r", "\n"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func validAppearanceBrandSlug(value string) bool {
|
||||||
|
if len(value) == 0 || len(value) > 48 || value[0] == '-' || value[len(value)-1] == '-' {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, char := range value {
|
||||||
|
if (char < 'a' || char > 'z') && (char < '0' || char > '9') && char != '-' {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func validateAppearanceCopy(value string, 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) && char != '\n' {
|
||||||
|
return BadAuthRequest(label + "不能包含控制字符")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Service) validateAppearanceResource(actor *model.User, slot string, resourceID string, currentID string) error {
|
||||||
|
if resourceID == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
resource, err := s.repo.Resource(resourceID)
|
||||||
|
if err != nil {
|
||||||
|
return BadAuthRequest("选择的外观资源不存在")
|
||||||
|
}
|
||||||
|
if resourceID != currentID && resource.UserID != actor.ID {
|
||||||
|
return Forbidden("只能使用当前管理员上传的外观资源")
|
||||||
|
}
|
||||||
|
return validateAppearanceResourceType(slot, resource)
|
||||||
|
}
|
||||||
|
|
||||||
|
func validateAppearanceResourceType(slot string, resource *model.Resource) error {
|
||||||
|
if resource == nil || resource.Status != model.ResourceStatusReady {
|
||||||
|
return BadAuthRequest("外观资源尚未上传完成")
|
||||||
|
}
|
||||||
|
mimeType := strings.ToLower(strings.TrimSpace(strings.Split(resource.MimeType, ";")[0]))
|
||||||
|
allowed := appearanceAllowedMIMETypes(slot)
|
||||||
|
if _, exists := allowed[mimeType]; !exists {
|
||||||
|
return BadAuthRequest("外观资源文件类型不受支持")
|
||||||
|
}
|
||||||
|
if slot == AppearanceAssetVideo && resource.Kind != "video" {
|
||||||
|
return BadAuthRequest("登录页品牌视频必须是视频资源")
|
||||||
|
}
|
||||||
|
if slot != AppearanceAssetVideo && resource.Kind != "image" {
|
||||||
|
return BadAuthRequest("Logo 和视频封面必须是图片资源")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func validateAppearanceUpload(slot string, header *multipart.FileHeader) (string, error) {
|
||||||
|
maxBytes, err := AppearanceAssetMaxBytes(slot)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if header == nil || header.Size <= 0 || header.Size > maxBytes {
|
||||||
|
return "", BadAuthRequest(fmt.Sprintf("%s大小必须在 %dMB 以内", appearanceAssetLabel(slot), maxBytes>>20))
|
||||||
|
}
|
||||||
|
file, err := header.Open()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
buffer := make([]byte, 512)
|
||||||
|
read, readErr := file.Read(buffer)
|
||||||
|
if readErr != nil && read == 0 {
|
||||||
|
return "", BadAuthRequest("外观资源内容无法读取")
|
||||||
|
}
|
||||||
|
mimeType := detectAppearanceMIME(slot, buffer[:read], header.Size)
|
||||||
|
if _, exists := appearanceAllowedMIMETypes(slot)[mimeType]; !exists {
|
||||||
|
return "", BadAuthRequest(appearanceAssetLabel(slot) + "文件类型不受支持")
|
||||||
|
}
|
||||||
|
return mimeType, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func detectAppearanceMIME(slot string, data []byte, fileSize int64) string {
|
||||||
|
mimeType := strings.ToLower(strings.TrimSpace(strings.Split(http.DetectContentType(data), ";")[0]))
|
||||||
|
if slot != AppearanceAssetVideo || mimeType == "video/mp4" || len(data) < 12 {
|
||||||
|
return mimeType
|
||||||
|
}
|
||||||
|
// Go's generic sniffer only recognises a subset of MP4 compatible brands.
|
||||||
|
// Accept a structurally valid ISO Base Media File Format `ftyp` first box,
|
||||||
|
// which covers common `isom`, `iso2`, `avc1`, `M4V ` and similar MP4 files.
|
||||||
|
boxSize := int64(binary.BigEndian.Uint32(data[:4]))
|
||||||
|
if string(data[4:8]) == "ftyp" && boxSize >= 12 && boxSize%4 == 0 && boxSize <= fileSize {
|
||||||
|
return "video/mp4"
|
||||||
|
}
|
||||||
|
return mimeType
|
||||||
|
}
|
||||||
|
|
||||||
|
func appearanceAllowedMIMETypes(slot string) map[string]struct{} {
|
||||||
|
if slot == AppearanceAssetVideo {
|
||||||
|
return map[string]struct{}{"video/mp4": {}, "video/webm": {}}
|
||||||
|
}
|
||||||
|
return map[string]struct{}{"image/png": {}, "image/jpeg": {}, "image/webp": {}}
|
||||||
|
}
|
||||||
|
|
||||||
|
func appearanceAssetLabel(slot string) string {
|
||||||
|
switch slot {
|
||||||
|
case AppearanceAssetLogo:
|
||||||
|
return "浅色模式品牌 Logo"
|
||||||
|
case AppearanceAssetDarkLogo:
|
||||||
|
return "深色模式品牌 Logo"
|
||||||
|
case AppearanceAssetPoster:
|
||||||
|
return "视频封面"
|
||||||
|
case AppearanceAssetVideo:
|
||||||
|
return "品牌视频"
|
||||||
|
default:
|
||||||
|
return "外观资源"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func appearanceResourceID(value AppearanceSetting, slot string) string {
|
||||||
|
switch slot {
|
||||||
|
case AppearanceAssetLogo:
|
||||||
|
return value.LogoResourceID
|
||||||
|
case AppearanceAssetDarkLogo:
|
||||||
|
return value.DarkLogoResourceID
|
||||||
|
case AppearanceAssetVideo:
|
||||||
|
return value.AuthVideoResourceID
|
||||||
|
case AppearanceAssetPoster:
|
||||||
|
return value.AuthVideoPosterResourceID
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func publicAppearanceSetting(setting *model.SystemSetting, value AppearanceSetting) *PublicAppearanceSetting {
|
||||||
|
revision := "builtin"
|
||||||
|
if setting != nil {
|
||||||
|
revision = strconv.FormatInt(setting.UpdatedAt.UTC().UnixNano(), 36)
|
||||||
|
}
|
||||||
|
result := &PublicAppearanceSetting{
|
||||||
|
SchemaVersion: appearanceSchemaVersion,
|
||||||
|
BrandName: value.BrandName,
|
||||||
|
BrandSlug: value.BrandSlug,
|
||||||
|
AuthHeroTitle: value.AuthHeroTitle,
|
||||||
|
AuthHeroDescription: value.AuthHeroDescription,
|
||||||
|
LogoURL: defaultAppearanceLogoURL,
|
||||||
|
DarkLogoURL: defaultAppearanceLogoURL,
|
||||||
|
LogoFrameEnabled: value.LogoFrameEnabled,
|
||||||
|
AuthVideoURL: defaultAppearanceVideoURL,
|
||||||
|
AuthVideoPosterURL: defaultAppearancePosterURL,
|
||||||
|
SkinID: value.SkinID,
|
||||||
|
Configured: setting != nil,
|
||||||
|
Revision: revision,
|
||||||
|
}
|
||||||
|
if setting != nil {
|
||||||
|
result.UpdatedAt = setting.UpdatedAt
|
||||||
|
}
|
||||||
|
if value.LogoResourceID != "" || value.DarkLogoResourceID != "" {
|
||||||
|
result.LogoConfigured = true
|
||||||
|
if value.LogoResourceID != "" {
|
||||||
|
result.LogoURL = appearanceAssetURL(AppearanceAssetLogo, revision)
|
||||||
|
} else {
|
||||||
|
result.LogoURL = appearanceAssetURL(AppearanceAssetDarkLogo, revision)
|
||||||
|
}
|
||||||
|
if value.DarkLogoResourceID != "" {
|
||||||
|
result.DarkLogoConfigured = true
|
||||||
|
result.DarkLogoURL = appearanceAssetURL(AppearanceAssetDarkLogo, revision)
|
||||||
|
} else {
|
||||||
|
result.DarkLogoURL = result.LogoURL
|
||||||
|
}
|
||||||
|
if value.LogoResourceID == "" {
|
||||||
|
result.LogoURL = result.DarkLogoURL
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value.AuthVideoResourceID != "" {
|
||||||
|
result.AuthVideoConfigured = true
|
||||||
|
result.AuthVideoURL = appearanceAssetURL(AppearanceAssetVideo, revision)
|
||||||
|
if value.AuthVideoPosterResourceID == "" {
|
||||||
|
// A custom video must not briefly reveal the built-in poster while its
|
||||||
|
// first frame loads. An optional custom poster may be configured below.
|
||||||
|
result.AuthVideoPosterURL = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value.AuthVideoPosterResourceID != "" {
|
||||||
|
result.AuthVideoPosterConfigured = true
|
||||||
|
result.AuthVideoPosterURL = appearanceAssetURL(AppearanceAssetPoster, revision)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func appearanceAssetURL(slot string, revision string) string {
|
||||||
|
return "/api/public/appearance/assets/" + url.PathEscape(slot) + "?v=" + url.QueryEscape(revision)
|
||||||
|
}
|
||||||
@@ -0,0 +1,299 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"mime/multipart"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"net/textproto"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"infinite-canvas/backend/internal/database"
|
||||||
|
"infinite-canvas/backend/internal/model"
|
||||||
|
"infinite-canvas/backend/internal/repository"
|
||||||
|
|
||||||
|
"gorm.io/driver/sqlite"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAppearanceDefaultsPreserveBuiltInBrand(t *testing.T) {
|
||||||
|
svc, _, _, _ := newAppearanceTestService(t)
|
||||||
|
|
||||||
|
appearance, err := svc.Appearance()
|
||||||
|
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 {
|
||||||
|
t.Fatalf("Appearance() = %#v", appearance)
|
||||||
|
}
|
||||||
|
if appearance.LogoConfigured || appearance.DarkLogoConfigured || appearance.AuthVideoConfigured || appearance.AuthVideoPosterConfigured || appearance.Revision != "builtin" {
|
||||||
|
t.Fatalf("Appearance() configured state = %#v", appearance)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAppearanceBackfillsVersionThreeFieldsForExistingSetting(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 {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
appearance, err := svc.Appearance()
|
||||||
|
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 {
|
||||||
|
t.Fatalf("legacy appearance = %#v", appearance)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUpdateAppearancePersistsAuditsAndUsesVersionedPublicAssets(t *testing.T) {
|
||||||
|
svc, db, _, admin := newAppearanceTestService(t)
|
||||||
|
resources := []model.Resource{
|
||||||
|
{ID: "brand-logo", UserID: admin.ID, Kind: "image", Status: model.ResourceStatusReady, Provider: "local", ObjectKey: "brand/logo.png", MimeType: "image/png"},
|
||||||
|
{ID: "brand-logo-dark", UserID: admin.ID, Kind: "image", Status: model.ResourceStatusReady, Provider: "local", ObjectKey: "brand/logo-dark.png", MimeType: "image/png"},
|
||||||
|
{ID: "brand-video", UserID: admin.ID, Kind: "video", Status: model.ResourceStatusReady, Provider: "local", ObjectKey: "brand/video.mp4", MimeType: "video/mp4"},
|
||||||
|
{ID: "brand-poster", UserID: admin.ID, Kind: "image", Status: model.ResourceStatusReady, Provider: "local", ObjectKey: "brand/poster.jpg", MimeType: "image/jpeg"},
|
||||||
|
}
|
||||||
|
if err := db.Create(&resources).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
updated, err := svc.UpdateAppearance(admin, AppearanceSetting{
|
||||||
|
BrandName: "HIMA Studio",
|
||||||
|
BrandSlug: "hima-studio",
|
||||||
|
AuthHeroTitle: "把灵感,\n变成可见的故事。",
|
||||||
|
AuthHeroDescription: "从画布开始,持续推进你的创作。",
|
||||||
|
LogoResourceID: "brand-logo",
|
||||||
|
DarkLogoResourceID: "brand-logo-dark",
|
||||||
|
LogoFrameEnabled: false,
|
||||||
|
AuthVideoResourceID: "brand-video",
|
||||||
|
AuthVideoPosterResourceID: "brand-poster",
|
||||||
|
SkinID: defaultAppearanceSkinID,
|
||||||
|
})
|
||||||
|
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 {
|
||||||
|
t.Fatalf("UpdateAppearance() = %#v", updated)
|
||||||
|
}
|
||||||
|
for _, assetURL := range []string{updated.Public.LogoURL, updated.Public.DarkLogoURL, updated.Public.AuthVideoURL, updated.Public.AuthVideoPosterURL} {
|
||||||
|
if !strings.HasPrefix(assetURL, "/api/public/appearance/assets/") || !strings.Contains(assetURL, "?v=") {
|
||||||
|
t.Fatalf("versioned asset URL = %q", assetURL)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
encodedPublic, err := json.Marshal(updated.Public)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
var auditCount int64
|
||||||
|
if err := db.Model(&model.AdminAuditEvent{}).Where("action = ?", "appearance.update").Count(&auditCount).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if auditCount != 1 {
|
||||||
|
t.Fatalf("audit count = %d, want 1", auditCount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAppearanceReusesSingleLogoAcrossThemes(t *testing.T) {
|
||||||
|
svc, db, _, admin := newAppearanceTestService(t)
|
||||||
|
resources := []model.Resource{
|
||||||
|
{ID: "only-light", UserID: admin.ID, Kind: "image", Status: model.ResourceStatusReady, Provider: "local", ObjectKey: "brand/light.png", MimeType: "image/png"},
|
||||||
|
{ID: "only-dark", UserID: admin.ID, Kind: "image", Status: model.ResourceStatusReady, Provider: "local", ObjectKey: "brand/dark.png", MimeType: "image/png"},
|
||||||
|
}
|
||||||
|
if err := db.Create(&resources).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
lightOnly, err := svc.UpdateAppearance(admin, AppearanceSetting{BrandName: "HIMA Studio", BrandSlug: "hima-studio", AuthHeroTitle: defaultAppearanceHeroTitle, LogoResourceID: "only-light", LogoFrameEnabled: true, SkinID: defaultAppearanceSkinID})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if lightOnly.Public.LogoURL != lightOnly.Public.DarkLogoURL || !lightOnly.Public.LogoConfigured || lightOnly.Public.DarkLogoConfigured {
|
||||||
|
t.Fatalf("light-only appearance = %#v", lightOnly.Public)
|
||||||
|
}
|
||||||
|
|
||||||
|
darkOnly, err := svc.UpdateAppearance(admin, AppearanceSetting{BrandName: "HIMA Studio", BrandSlug: "hima-studio", AuthHeroTitle: defaultAppearanceHeroTitle, DarkLogoResourceID: "only-dark", LogoFrameEnabled: true, SkinID: defaultAppearanceSkinID})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if darkOnly.Public.LogoURL != darkOnly.Public.DarkLogoURL || !darkOnly.Public.LogoConfigured || !darkOnly.Public.DarkLogoConfigured {
|
||||||
|
t.Fatalf("dark-only appearance = %#v", darkOnly.Public)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestResetAppearanceRestoresBuiltInBrandWithoutDeletingResources(t *testing.T) {
|
||||||
|
svc, db, _, admin := newAppearanceTestService(t)
|
||||||
|
resource := model.Resource{ID: "brand-logo", UserID: admin.ID, Kind: "image", Status: model.ResourceStatusReady, Provider: "local", ObjectKey: "brand/logo.png", MimeType: "image/png"}
|
||||||
|
if err := db.Create(&resource).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := svc.UpdateAppearance(admin, AppearanceSetting{
|
||||||
|
BrandName: "HIMA Studio",
|
||||||
|
BrandSlug: "hima-studio",
|
||||||
|
AuthHeroTitle: "把灵感变成故事",
|
||||||
|
LogoResourceID: resource.ID,
|
||||||
|
SkinID: defaultAppearanceSkinID,
|
||||||
|
}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
reset, err := svc.ResetAppearance(admin)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if reset.Configured || reset.BrandName != defaultAppearanceBrandName || reset.BrandSlug != defaultAppearanceBrandSlug || reset.AuthHeroTitle != defaultAppearanceHeroTitle || reset.LogoResourceID != "" || reset.DarkLogoResourceID != "" || !reset.LogoFrameEnabled || reset.Public.Revision != "builtin" || reset.Public.LogoConfigured || reset.Public.DarkLogoConfigured {
|
||||||
|
t.Fatalf("ResetAppearance() = %#v", reset)
|
||||||
|
}
|
||||||
|
var resourceCount int64
|
||||||
|
if err := db.Model(&model.Resource{}).Where("id = ?", resource.ID).Count(&resourceCount).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if resourceCount != 1 {
|
||||||
|
t.Fatalf("resource count = %d, want 1", resourceCount)
|
||||||
|
}
|
||||||
|
var auditCount int64
|
||||||
|
if err := db.Model(&model.AdminAuditEvent{}).Where("action = ?", "appearance.reset").Count(&auditCount).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if auditCount != 1 {
|
||||||
|
t.Fatalf("reset audit count = %d, want 1", auditCount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUpdateAppearanceRejectsAnotherUsersNewResource(t *testing.T) {
|
||||||
|
svc, db, _, admin := newAppearanceTestService(t)
|
||||||
|
resource := model.Resource{ID: "foreign-logo", UserID: "another-admin", Kind: "image", Status: model.ResourceStatusReady, Provider: "local", ObjectKey: "brand/logo.png", MimeType: "image/png"}
|
||||||
|
if err := db.Create(&resource).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := svc.UpdateAppearance(admin, AppearanceSetting{BrandName: "HIMA Studio", BrandSlug: "hima-studio", AuthHeroTitle: defaultAppearanceHeroTitle, LogoResourceID: resource.ID, SkinID: defaultAppearanceSkinID})
|
||||||
|
if err == nil || !strings.Contains(err.Error(), "当前管理员上传") {
|
||||||
|
t.Fatalf("UpdateAppearance() error = %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOpenAppearanceAssetOnlyServesConfiguredSlot(t *testing.T) {
|
||||||
|
svc, db, dataDir, admin := newAppearanceTestService(t)
|
||||||
|
resource := model.Resource{ID: "brand-logo", UserID: admin.ID, Kind: "image", Status: model.ResourceStatusReady, Provider: "local", ObjectKey: "brand/logo.png", MimeType: "image/png"}
|
||||||
|
if err := db.Create(&resource).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
filePath := filepath.Join(dataDir, "resources", filepath.FromSlash(resource.ObjectKey))
|
||||||
|
if err := os.MkdirAll(filepath.Dir(filePath), 0o750); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := os.WriteFile(filePath, []byte("brand-bytes"), 0o640); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := svc.UpdateAppearance(admin, AppearanceSetting{BrandName: "HIMA Studio", BrandSlug: "hima-studio", AuthHeroTitle: defaultAppearanceHeroTitle, LogoResourceID: resource.ID, SkinID: defaultAppearanceSkinID}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
stream, err := svc.OpenAppearanceAsset(AppearanceAssetLogo, "")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
stream.Body.Close()
|
||||||
|
if stream.Resource.ID != resource.ID {
|
||||||
|
t.Fatalf("served resource = %q", stream.Resource.ID)
|
||||||
|
}
|
||||||
|
if _, err := svc.OpenAppearanceAsset(AppearanceAssetVideo, ""); err == nil {
|
||||||
|
t.Fatal("unconfigured video slot unexpectedly served a resource")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUpdateAppearanceValidatesLoginCopy(t *testing.T) {
|
||||||
|
svc, _, _, admin := newAppearanceTestService(t)
|
||||||
|
|
||||||
|
_, err := svc.UpdateAppearance(admin, AppearanceSetting{BrandName: "HIMA Studio", BrandSlug: "hima-studio", AuthHeroTitle: "", SkinID: defaultAppearanceSkinID})
|
||||||
|
if err == nil || !strings.Contains(err.Error(), "主标题") {
|
||||||
|
t.Fatalf("empty title error = %v", err)
|
||||||
|
}
|
||||||
|
_, err = svc.UpdateAppearance(admin, AppearanceSetting{BrandName: "HIMA Studio", BrandSlug: "hima-studio", AuthHeroTitle: defaultAppearanceHeroTitle, AuthHeroDescription: strings.Repeat("文", 161), SkinID: defaultAppearanceSkinID})
|
||||||
|
if err == nil || !strings.Contains(err.Error(), "160") {
|
||||||
|
t.Fatalf("long description error = %v", err)
|
||||||
|
}
|
||||||
|
_, err = svc.UpdateAppearance(admin, AppearanceSetting{BrandName: "HIMA Studio", BrandSlug: "hima-studio", AuthHeroTitle: "标题\t注入", SkinID: defaultAppearanceSkinID})
|
||||||
|
if err == nil || !strings.Contains(err.Error(), "控制字符") {
|
||||||
|
t.Fatalf("control character error = %v", err)
|
||||||
|
}
|
||||||
|
_, err = svc.UpdateAppearance(admin, AppearanceSetting{BrandName: "HIMA Studio", BrandSlug: "HIMA Studio", AuthHeroTitle: defaultAppearanceHeroTitle, SkinID: defaultAppearanceSkinID})
|
||||||
|
if err == nil || !strings.Contains(err.Error(), "英文品牌标识") {
|
||||||
|
t.Fatalf("invalid slug error = %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestValidateAppearanceUploadSniffsBytesInsteadOfDeclaredMIME(t *testing.T) {
|
||||||
|
pngHeader := multipartFileHeader(t, "logo.png", "text/plain", append([]byte{0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a}, bytes.Repeat([]byte{0}, 32)...))
|
||||||
|
if mimeType, err := validateAppearanceUpload(AppearanceAssetLogo, pngHeader); err != nil || mimeType != "image/png" {
|
||||||
|
t.Fatalf("validateAppearanceUpload(png) = %q, %v", mimeType, err)
|
||||||
|
}
|
||||||
|
darkPNGHeader := multipartFileHeader(t, "logo-dark.png", "text/plain", append([]byte{0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a}, bytes.Repeat([]byte{0}, 32)...))
|
||||||
|
if mimeType, err := validateAppearanceUpload(AppearanceAssetDarkLogo, darkPNGHeader); err != nil || mimeType != "image/png" {
|
||||||
|
t.Fatalf("validateAppearanceUpload(dark png) = %q, %v", mimeType, err)
|
||||||
|
}
|
||||||
|
fakeImage := multipartFileHeader(t, "fake.png", "image/png", []byte("not an image"))
|
||||||
|
if _, err := validateAppearanceUpload(AppearanceAssetLogo, fakeImage); err == nil {
|
||||||
|
t.Fatal("declared image MIME accepted non-image bytes")
|
||||||
|
}
|
||||||
|
mp4Bytes := append([]byte{0x00, 0x00, 0x00, 0x14}, []byte("ftypisom\x00\x00\x00\x00isom")...)
|
||||||
|
mp4Header := multipartFileHeader(t, "hero.mp4", "application/octet-stream", mp4Bytes)
|
||||||
|
if mimeType, err := validateAppearanceUpload(AppearanceAssetVideo, mp4Header); err != nil || mimeType != "video/mp4" {
|
||||||
|
t.Fatalf("validateAppearanceUpload(mp4) = %q, %v", mimeType, err)
|
||||||
|
}
|
||||||
|
fakeMP4 := multipartFileHeader(t, "fake.mp4", "video/mp4", append([]byte{0x00, 0x00, 0x10, 0x00}, []byte("ftypisom")...))
|
||||||
|
if _, err := validateAppearanceUpload(AppearanceAssetVideo, fakeMP4); err == nil {
|
||||||
|
t.Fatal("invalid MP4 box size accepted")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func multipartFileHeader(t *testing.T, name string, contentType string, data []byte) *multipart.FileHeader {
|
||||||
|
t.Helper()
|
||||||
|
var body bytes.Buffer
|
||||||
|
writer := multipart.NewWriter(&body)
|
||||||
|
header := make(textproto.MIMEHeader)
|
||||||
|
header.Set("Content-Disposition", `form-data; name="file"; filename="`+name+`"`)
|
||||||
|
header.Set("Content-Type", contentType)
|
||||||
|
part, err := writer.CreatePart(header)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := part.Write(data); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := writer.Close(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
req := httptest.NewRequest(http.MethodPost, "/", &body)
|
||||||
|
req.Header.Set("Content-Type", writer.FormDataContentType())
|
||||||
|
if err := req.ParseMultipartForm(int64(body.Len()) + 1024); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
return req.MultipartForm.File["file"][0]
|
||||||
|
}
|
||||||
|
|
||||||
|
func newAppearanceTestService(t *testing.T) (*Service, *gorm.DB, string, *model.User) {
|
||||||
|
t.Helper()
|
||||||
|
db, err := gorm.Open(sqlite.Open("file:"+newID()+"?mode=memory&cache=shared"), &gorm.Config{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := database.MigrateSchema(db); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
admin := &model.User{ID: "appearance-admin", Username: "appearance-admin", Role: model.UserRoleAdmin, Status: model.UserStatusActive}
|
||||||
|
if err := db.Create(admin).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
dataDir := t.TempDir()
|
||||||
|
return New(repository.New(db), dataDir), db, dataDir, admin
|
||||||
|
}
|
||||||
@@ -19,6 +19,12 @@ description: 影策后端核心持久化表与状态边界
|
|||||||
|
|
||||||
版本 3 会将 `wardrobe`、`weapon`、`accessory` 迁移为 `prop`,将 `style` 迁移为 `material`,并把原先归入 `other` 的图片、视频、音频和 3D 模型迁移为 `material`。迁移只合并重复的待确认候选:保留最早记录,其余标记为 `ignored`;已经确认的资产不会被自动删除或归并。
|
版本 3 会将 `wardrobe`、`weapon`、`accessory` 迁移为 `prop`,将 `style` 迁移为 `material`,并把原先归入 `other` 的图片、视频、音频和 3D 模型迁移为 `material`。迁移只合并重复的待确认候选:保留最早记录,其余标记为 `ignored`;已经确认的资产不会被自动删除或归并。
|
||||||
|
|
||||||
|
## 平台外观配置
|
||||||
|
|
||||||
|
平台外观复用既有 `system_settings` 表,不新增结构迁移。键 `appearance` 的 JSON 值使用版本化合同;版本 3 保存品牌名称、英文品牌标识、登录页主标题与可选说明文案、浅色与可选深色 Logo 资源 ID、Logo 外框开关、登录页视频资源 ID、可选封面资源 ID 和预留皮肤 ID。只配置一套 Logo 时,公开投影会在浅色和深色主题复用同一资源;旧版本缺少深色 Logo 与外框字段时分别回退到单 Logo 和启用外框,不改变既有视觉。资源元数据和文件仍分别由 `resources` 表与当前资源存储承担。恢复默认外观时删除这条设置记录并回到内置值,不级联删除已经上传的资源。
|
||||||
|
|
||||||
|
公开接口只投影品牌名、英文品牌标识、登录页公开文案、深浅主题使用的稳定 slot 资源 URL、Logo 外框状态、配置状态和修订标识,不返回内部资源 ID、对象路径或存储凭据。管理员保存新配置前,服务层会校验文本长度与安全字符、资源为就绪状态、类型与 slot 匹配,且新绑定资源由当前管理员上传;两套 Logo、视频和封面中任何正在使用的资源都会进入管理员删除保护。品牌变更同时写入 `admin_audit_events`。
|
||||||
|
|
||||||
## 账号认证与密码找回
|
## 账号认证与密码找回
|
||||||
|
|
||||||
| 表 | 用途 | 关键边界 |
|
| 表 | 用途 | 关键边界 |
|
||||||
|
|||||||
@@ -5,6 +5,21 @@ description: 影策当前已实现的核心工作台能力与使用入口
|
|||||||
|
|
||||||
# 功能清单
|
# 功能清单
|
||||||
|
|
||||||
|
## 平台外观管理
|
||||||
|
|
||||||
|
管理员可以在“系统配置 → 外观管理”统一设置平台品牌名称、英文品牌标识、浅色与深色 Logo、Logo 外框、登录页主标题、可选说明文案、品牌视频和可选视频封面。Logo 可以只上传任意一套并自动复用,也可以分别为浅色与深色界面上传;工作台和管理后台导航中的圆角矩形外框可以通过统一开关单独禁用,禁用后 Logo 会等比放大到原外框的可用区域,但导航占位不变。品牌名称和对应主题 Logo 会应用到登录页、工作台导航、管理后台、浏览器标题以及创作与素材库的主要品牌文案;登录、注册和找回密码共享同一套左侧品牌文案与影片。
|
||||||
|
|
||||||
|
前端入口在加载 React 应用之前先读取 `GET /api/public/appearance`。初始 HTML 不包含内置品牌名、Logo 或默认 favicon;只有公开配置成功或明确回退到内置外观后才渲染应用,避免自定义品牌访问时先闪现“影策”。自定义视频未设置封面时保持纯色背景直至视频首帧就绪,不复用内置视频封面。
|
||||||
|
|
||||||
|
浅色 Logo、深色 Logo、视频和封面通过后台专用上传接口进入现有资源存储,并由稳定的公开 slot URL 读取;公开响应不暴露资源 ID。正在使用的外观资源会阻止管理员从资源管理页直接删除。英文品牌标识可作为对象存储路径前缀建议,但不会自动覆盖已经保存的前缀或改写历史资源。“恢复影策默认”会删除外观配置记录并立即恢复全部内置品牌值和默认 Logo 外框,同时保留已经上传的素材文件。配置保留 `schemaVersion` 和 `skinId`,当前只开放 `classic`,后续皮肤库可在同一边界增加颜色、字体、圆角和组件密度包。
|
||||||
|
|
||||||
|
### 相关实现
|
||||||
|
|
||||||
|
- `backend/internal/service/appearance.go`:外观配置校验、公开投影、资源绑定与媒体类型校验。
|
||||||
|
- `backend/internal/handler/appearance.go`:公开读取、公开资源流和管理员读写/上传接口。
|
||||||
|
- `web/src/services/appearance-bootstrap.ts`:应用渲染前的公开外观解析与安全回退。
|
||||||
|
- `web/src/pages/admin/settings/appearance-settings-page.tsx`:外观管理、草稿预览与原子保存流程。
|
||||||
|
|
||||||
## 邮箱找回密码
|
## 邮箱找回密码
|
||||||
|
|
||||||
登录页在密码字段标题行提供“忘记密码?”入口。已配置账户邮件服务时,本地密码账号可以通过绑定邮箱获取 6 位验证码,并在 10 分钟内设置新密码;发送接口对存在和不存在的邮箱返回相同结果,避免公开账号状态。
|
登录页在密码字段标题行提供“忘记密码?”入口。已配置账户邮件服务时,本地密码账号可以通过绑定邮箱获取 6 位验证码,并在 10 分钟内设置新密码;发送接口对存在和不存在的邮箱返回相同结果,避免公开账号状态。
|
||||||
|
|||||||
@@ -5,6 +5,21 @@ description: 影策已实现功能的手工验证清单与未确认边界
|
|||||||
|
|
||||||
# 待测试
|
# 待测试
|
||||||
|
|
||||||
|
## 平台外观管理
|
||||||
|
|
||||||
|
管理后台已新增“系统配置 → 外观管理”,并让公开品牌配置在应用渲染前完成解析;以下真实浏览器与媒体场景需要持续确认:
|
||||||
|
|
||||||
|
- [x] 后端专项与全量测试通过,覆盖内置默认值、管理员权限、资源类型/归属、公开 URL 不泄漏资源 ID、媒体字节嗅探、删除保护与路由注册。
|
||||||
|
- [x] 前端专项测试、后台回归测试、TypeScript 检查和生产构建通过,覆盖初始 HTML 品牌中立、自定义视频不回退内置封面、不安全 URL 回退、单 Logo 深浅主题复用、双 Logo 主题选择、外框关闭与登录场景固定使用深色 Logo。
|
||||||
|
- [ ] 使用管理员账号依次保存品牌名、英文品牌标识、登录页标题/说明、浅色 PNG/WebP Logo、可选深色 Logo、外框开关、MP4/WebM 视频与封面,确认工作台和登录页立即更新,刷新后保持一致。
|
||||||
|
- [ ] 分别只上传浅色 Logo、只上传深色 Logo、同时上传两套 Logo,并切换浅色/深色主题,确认单图自动复用、双图按主题选择;开启“禁用 Logo 后面的圆角矩形外框”后确认工作台和管理后台导航只显示等比放大到原外框可用区域的 Logo,布局不跳动。
|
||||||
|
- [ ] 在“对象存储”中点击“使用品牌标识”,确认只更新当前路径前缀草稿;未点击或未保存时保留服务端已有前缀,历史资源读取不受影响。
|
||||||
|
- [ ] 保存一套自定义品牌后点击“恢复影策默认”,确认品牌名称、英文标识、Logo、登录页文案和媒体立即恢复内置值,自定义素材文件仍保留在存储资源中。
|
||||||
|
- [ ] 清空浏览器缓存并以慢速网络打开 `/login`、`/register` 和 `/forgot-password`,确认加载阶段不出现内置品牌名、Logo、favicon 或视频封面闪烁。
|
||||||
|
- [ ] 更换品牌视频但不上传封面,确认首帧出现前只显示中性深色背景;再配置封面,确认只显示当前自定义封面。
|
||||||
|
- [ ] 在存储资源页尝试删除当前浅色 Logo、深色 Logo、视频和封面,确认显示“外观”引用并保留文件;解除绑定后可正常删除。
|
||||||
|
- [ ] 将公开配置接口模拟为超时或 5xx,确认 4 秒内结束等待并完整回退内置外观,应用仍可进入。
|
||||||
|
|
||||||
## 画布导入同步、素材回收站与历史
|
## 画布导入同步、素材回收站与历史
|
||||||
|
|
||||||
- [x] 画布压缩包导入会先校验媒体完整性,并统一通过远端同步入口上传资源;失败时保持脏状态和自动重试,不再把浏览器本地 storage key 误报为已同步。
|
- [x] 画布压缩包导入会先校验媒体完整性,并统一通过远端同步入口上传资源;失败时保持脏状态和自动重试,不再把浏览器本地 storage key 误报为已同步。
|
||||||
|
|||||||
@@ -1140,3 +1140,15 @@
|
|||||||
- 验证结果:八个目标源码/样式/记录文件通过定向 Prettier;全量 `npx tsc --noEmit` 为 0 错误;Vite 8.1.5 生产构建成功转换 12,695 个模块并在约 4.63 秒完成,仅保留项目既有的大分块提示。使用现有已登录 Chrome 会话访问当前源码开发服务;账号真实项目数为 0,未创建或修改测试项目。五个详情 URL 均以不存在项目做只读错误态检查,稳定显示“项目不可用”和返回操作;亮色与暗色分别覆盖 1280×800、1440×900、1920×1080 三档真实 CSS 视口,文档和 main 横向溢出均为 0,错误表面宽 760px,亮色为 `rgb(255,255,255)`、暗色为 `rgb(26,29,32)`。有数据态、归档态、章节编辑态和五页业务动作因真实账号无项目且禁止写业务数据,以完整 JSX/CSS 结构检查、历史状态机核对、全量类型和生产构建作为验证边界;没有伪造接口或业务记录。控制台仅出现批次 132 已记录的 Ant `App cssVar` 与 `Modal maskClosable` 既有警告,没有本批运行错误。
|
- 验证结果:八个目标源码/样式/记录文件通过定向 Prettier;全量 `npx tsc --noEmit` 为 0 错误;Vite 8.1.5 生产构建成功转换 12,695 个模块并在约 4.63 秒完成,仅保留项目既有的大分块提示。使用现有已登录 Chrome 会话访问当前源码开发服务;账号真实项目数为 0,未创建或修改测试项目。五个详情 URL 均以不存在项目做只读错误态检查,稳定显示“项目不可用”和返回操作;亮色与暗色分别覆盖 1280×800、1440×900、1920×1080 三档真实 CSS 视口,文档和 main 横向溢出均为 0,错误表面宽 760px,亮色为 `rgb(255,255,255)`、暗色为 `rgb(26,29,32)`。有数据态、归档态、章节编辑态和五页业务动作因真实账号无项目且禁止写业务数据,以完整 JSX/CSS 结构检查、历史状态机核对、全量类型和生产构建作为验证边界;没有伪造接口或业务记录。控制台仅出现批次 132 已记录的 Ant `App cssVar` 与 `Modal maskClosable` 既有警告,没有本批运行错误。
|
||||||
- 潜在影响:项目详情首屏增加约 76~86px 当前视图身份层,章节编辑区可用高度相应减少但仍由单一 flex 区域内部滚动;设置和资产页新增一级表面与细边界,1920px 下内容不再无限拉伸。顶部项目状态与当前 view 更醒目,页面 h1→h2→说明顺序稳定。接口请求、业务状态、路由、数据、权限和移动端均不变。
|
- 潜在影响:项目详情首屏增加约 76~86px 当前视图身份层,章节编辑区可用高度相应减少但仍由单一 flex 区域内部滚动;设置和资产页新增一级表面与细边界,1920px 下内容不再无限拉伸。顶部项目状态与当前 view 更醒目,页面 h1→h2→说明顺序稳定。接口请求、业务状态、路由、数据、权限和移动端均不变。
|
||||||
- 逐项回滚:修改前八个原件、SHA-256、校验文件和恢复步骤位于 `.local/ui-change-backups/batch-133/MANIFEST.md` 与 `MANIFEST.sha256`。回滚前先保留后续修改,再按原相对路径逐项恢复并运行 `shasum -a 256 -c MANIFEST.sha256`;完整回滚最后恢复本记录。不需要初始化、提交或依赖 Git。
|
- 逐项回滚:修改前八个原件、SHA-256、校验文件和恢复步骤位于 `.local/ui-change-backups/batch-133/MANIFEST.md` 与 `MANIFEST.sha256`。回滚前先保留后续修改,再按原相对路径逐项恢复并运行 `shasum -a 256 -c MANIFEST.sha256`;完整回滚最后恢复本记录。不需要初始化、提交或依赖 Git。
|
||||||
|
|
||||||
|
## 批次 134:外观管理 Logo 外框开关与无框尺寸统一
|
||||||
|
|
||||||
|
- 日期时间:2026-09-02 17:04:34 +0800
|
||||||
|
- 目的:修复“禁用 Logo 后面的圆角矩形外框”复选框与后台现有布尔设置视觉不一致的问题,并让关闭外框后的品牌 Logo 等比放大到原外框可用区域;保持原导航占位、深浅 Logo 选择、品牌加载时序、接口和保存方式不变。
|
||||||
|
- 修改前状况:外观管理单独使用 Ant Checkbox,而登录注册、功能开放等后台布尔设置已经统一使用主题化 Ant Switch;页面只给 Checkbox 外层文字加样式,控件自身状态与其他模块不一致。关闭外框仅清除容器背景、边框、圆角和阴影,实际 Logo 仍保持 `size-5`,因此在 32~38px 导航容器内显得偏小;44px 预览容器也仍固定显示 28px Logo。
|
||||||
|
- 涉及文件:`web/src/pages/admin/settings/appearance-settings-page.tsx`、`web/src/styles/admin-ui.css`、`web/src/styles/globals.css`、`web/test/appearance-bootstrap.test.ts`、`docs/content/docs/overview/features.mdx`、`docs/content/docs/progress/pending-test.mdx`、`docs/design/admin-ui-change-log.md`。未修改后端、外观 schema、API、数据库、上传与重置逻辑、导航容器尺寸或操作人现有品牌配置。
|
||||||
|
- 具体改动:外框选项复用后台已有 Ant Switch 和集中主题 token,采用“说明文案 + 当前状态文字 + 右侧开关”的现有设置行方向,开启表示禁用外框,`checked` 与 `logoFrameEnabled` 继续按反向关系转换;补充 `aria-label` 和说明关联。关闭外框时,共享 `BrandLogoFrame` 的直接图片或 SVG 子元素宽高提升到容器 `100%`,继续由 `object-fit: contain` 等比适配,因此工作台 32px、管理后台 32~38px 及折叠态均复用各自原容器,不发生布局跳动;深浅模式预览同步由 28px 放大到完整 44px 可用区域。窄屏选项行改为上下排列,状态与开关仍保持两端对齐。
|
||||||
|
- 修改前基线:`appearance-settings-page.tsx` 为 `a9e133fb76e046b8775f284279f054e78d86fda8f1bfa08f73bb54a9c9c82447`,`admin-ui.css` 为 `c0fa61947300287f059ae3b0f987d685c4ab9b52f620923ee8f8713d0dbdcd88`,`globals.css` 为 `7c6cdba67750029ee959055a8d70e013c0cadfd05aaaf7dd398b42ea6f83ac48`,`appearance-bootstrap.test.ts` 为 `23f02b574541bd09c31785bf72d80d9968f9d14e70a7cfc6ecf643dcc7866ff9`,两份功能文档分别为 `7d7b0b46252a9c7a9787d99e7b6018b14ef8df189f7a0332f66f00804d89f537` 与 `4d58b9eb3db6110c30e12a6e41d371c6680fd51655bd11525c679b7cf03fbf10`;原件保存在 `.local/ui-change-backups/batch-134/`。
|
||||||
|
- 验证结果:目标文件定向 Prettier 与 `git diff --check` 通过;固定 Bun 1.3.13、提交的 `bun.lock` 和干净依赖环境运行外观、后台、对象存储与找回密码四组专项测试,23 项全部通过、194 个断言无失败,TypeScript `tsc --noEmit` 为 0 错误。生产 Docker 多阶段构建转换 13,499 个模块并成功生成镜像,只保留项目既有的大分块提示。独立前端烟测返回 200,确认初始 HTML 不含内置品牌与 `/logo.svg`,新尺寸选择器已进入打包 CSS;真实管理员页面的深浅主题截图仍按 `docs/content/docs/progress/pending-test.mdx` 保留为人工验证项,不伪造登录态或业务配置。
|
||||||
|
- 潜在影响:关闭外框后,宽或高较小、透明留白较多的 Logo 会在原容器范围内明显变大,但仍保持自身比例且不会溢出;如素材文件本身带有透明边距,视觉内容不会强制裁切到满边。开关仍属于外观页面草稿,需要点击原有“保存修改”才写入服务端;没有改成即时保存。
|
||||||
|
- 逐项回滚:先使用 `.local/ui-change-backups/batch-134/` 中对应原件逐项恢复本批六个源码/文档文件,再恢复本台账并执行其 `MANIFEST.sha256` 校验;恢复前如文件已包含后续批次,先复制当前版本。本批不依赖 Git 历史做本地回滚。
|
||||||
+35
-3
@@ -3,9 +3,41 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<meta name="description" content="影策,让一个故事从文字走向银幕。面向 AI 影视与短剧创作的开源工作台。" />
|
<meta name="description" content="AI 影视与短剧创作工作台" />
|
||||||
<link rel="icon" href="/logo.svg" />
|
<title>正在加载</title>
|
||||||
<title>影策</title>
|
<style>
|
||||||
|
html,
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
background: #0b0c10;
|
||||||
|
}
|
||||||
|
#root:empty {
|
||||||
|
min-height: 100vh;
|
||||||
|
}
|
||||||
|
#root:empty::after {
|
||||||
|
content: "";
|
||||||
|
position: fixed;
|
||||||
|
left: 50%;
|
||||||
|
top: 50%;
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
margin: -10px 0 0 -10px;
|
||||||
|
border: 2px solid rgba(255, 255, 255, 0.16);
|
||||||
|
border-top-color: rgba(255, 255, 255, 0.72);
|
||||||
|
border-radius: 999px;
|
||||||
|
animation: appearance-bootstrap-spin 0.8s linear infinite;
|
||||||
|
}
|
||||||
|
@keyframes appearance-bootstrap-spin {
|
||||||
|
to {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
#root:empty::after {
|
||||||
|
animation: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
<script>
|
<script>
|
||||||
try {
|
try {
|
||||||
var s = JSON.parse(localStorage.getItem("infinite-canvas:theme_store") || "{}");
|
var s = JSON.parse(localStorage.getItem("infinite-canvas:theme_store") || "{}");
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import type { CSSProperties, ReactNode } from "react";
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { appearanceLogoURL, useAppearanceStore } from "@/stores/use-appearance-store";
|
||||||
|
import { useThemeStore, type ThemeName } from "@/stores/use-theme-store";
|
||||||
|
|
||||||
|
type BrandLogoProps = {
|
||||||
|
className?: string;
|
||||||
|
fallback: ReactNode;
|
||||||
|
alt?: string;
|
||||||
|
theme?: ThemeName | "auto";
|
||||||
|
};
|
||||||
|
|
||||||
|
export function BrandLogo({ className, fallback, alt = "", theme = "auto" }: BrandLogoProps) {
|
||||||
|
const appearance = useAppearanceStore((state) => state.appearance);
|
||||||
|
const currentTheme = useThemeStore((state) => state.theme);
|
||||||
|
if (!appearance.logoConfigured) return <>{fallback}</>;
|
||||||
|
return <img src={appearanceLogoURL(appearance, theme === "auto" ? currentTheme : theme)} alt={alt} className={cn("block object-contain", className)} draggable={false} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function BrandLogoFrame({ className, logoClassName, fallback, alt = "", theme = "auto" }: BrandLogoProps & { logoClassName?: string }) {
|
||||||
|
const frameEnabled = useAppearanceStore((state) => state.appearance.logoFrameEnabled);
|
||||||
|
const unframedStyle: CSSProperties | undefined = frameEnabled
|
||||||
|
? undefined
|
||||||
|
: {
|
||||||
|
background: "transparent",
|
||||||
|
borderColor: "transparent",
|
||||||
|
borderRadius: 0,
|
||||||
|
boxShadow: "none",
|
||||||
|
color: "inherit",
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<span className={cn("brand-logo-frame", className)} data-logo-frame-enabled={frameEnabled} style={unframedStyle}>
|
||||||
|
<BrandLogo className={logoClassName} fallback={fallback} alt={alt} theme={theme} />
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ import { ClientRootInit } from "@/components/layout/client-root-init";
|
|||||||
import { getAntThemeConfig } from "@/lib/app-theme";
|
import { getAntThemeConfig } from "@/lib/app-theme";
|
||||||
import { appQueryClient } from "@/lib/query-client";
|
import { appQueryClient } from "@/lib/query-client";
|
||||||
import { useThemeStore } from "@/stores/use-theme-store";
|
import { useThemeStore } from "@/stores/use-theme-store";
|
||||||
|
import { applyAppearanceMetadata, useAppearanceStore } from "@/stores/use-appearance-store";
|
||||||
import { listRegisteredPlugins } from "@/lib/plugins/plugin-registry";
|
import { listRegisteredPlugins } from "@/lib/plugins/plugin-registry";
|
||||||
import { usePluginStore } from "@/stores/use-plugin-store";
|
import { usePluginStore } from "@/stores/use-plugin-store";
|
||||||
import { fetchPluginRuntimeState, setUserPluginEnabled } from "@/services/api/plugins";
|
import { fetchPluginRuntimeState, setUserPluginEnabled } from "@/services/api/plugins";
|
||||||
@@ -17,6 +18,7 @@ import { useUserStore } from "@/stores/use-user-store";
|
|||||||
export function AppProviders({ children }: { children: ReactNode }) {
|
export function AppProviders({ children }: { children: ReactNode }) {
|
||||||
const theme = useThemeStore((state) => state.theme);
|
const theme = useThemeStore((state) => state.theme);
|
||||||
const dark = theme === "dark";
|
const dark = theme === "dark";
|
||||||
|
const appearance = useAppearanceStore((state) => state.appearance);
|
||||||
const ensurePlugin = usePluginStore((state) => state.ensurePlugin);
|
const ensurePlugin = usePluginStore((state) => state.ensurePlugin);
|
||||||
const setRuntimeStatuses = usePluginStore((state) => state.setRuntimeStatuses);
|
const setRuntimeStatuses = usePluginStore((state) => state.setRuntimeStatuses);
|
||||||
const setPluginStates = usePluginStore((state) => state.setPluginStates);
|
const setPluginStates = usePluginStore((state) => state.setPluginStates);
|
||||||
@@ -38,8 +40,9 @@ export function AppProviders({ children }: { children: ReactNode }) {
|
|||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
void fetchPluginRuntimeState()
|
void fetchPluginRuntimeState()
|
||||||
.then(async ({ statuses, states }) => {
|
.then(async ({ statuses, states }) => {
|
||||||
const legacyEnabledIds = usePluginStore.getState().installations
|
const legacyEnabledIds = usePluginStore
|
||||||
.filter((installation) => installation.enabled && states[installation.manifest.id]?.canToggle && !states[installation.manifest.id]?.userConfigured)
|
.getState()
|
||||||
|
.installations.filter((installation) => installation.enabled && states[installation.manifest.id]?.canToggle && !states[installation.manifest.id]?.userConfigured)
|
||||||
.map((installation) => installation.manifest.id);
|
.map((installation) => installation.manifest.id);
|
||||||
if (legacyEnabledIds.length) {
|
if (legacyEnabledIds.length) {
|
||||||
try {
|
try {
|
||||||
@@ -69,7 +72,8 @@ export function AppProviders({ children }: { children: ReactNode }) {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
document.documentElement.classList.toggle("dark", dark);
|
document.documentElement.classList.toggle("dark", dark);
|
||||||
document.documentElement.style.colorScheme = theme;
|
document.documentElement.style.colorScheme = theme;
|
||||||
}, [dark, theme]);
|
applyAppearanceMetadata(appearance);
|
||||||
|
}, [appearance, dark, theme]);
|
||||||
|
|
||||||
// DEV 复现台必须是同源本地确定性场景:AuthSessionHydrator 会打 /api/auth/session,
|
// DEV 复现台必须是同源本地确定性场景:AuthSessionHydrator 会打 /api/auth/session,
|
||||||
// ClientRootInit 会打 /api/model-catalog,没有后端时产生真实 502,与导演台无关却会污染判据。
|
// ClientRootInit 会打 /api/model-catalog,没有后端时产生真实 502,与导演台无关却会污染判据。
|
||||||
|
|||||||
@@ -2,12 +2,14 @@ import { ChevronDown, ChevronRight, Home, Infinity as InfinityIcon, LogOut, Pane
|
|||||||
import { useEffect, useMemo, useRef, useState, type ComponentType, type CSSProperties } from "react";
|
import { useEffect, useMemo, useRef, useState, type ComponentType, type CSSProperties } from "react";
|
||||||
import { Link, useLocation, useNavigate, useSearchParams } from "react-router";
|
import { Link, useLocation, useNavigate, useSearchParams } from "react-router";
|
||||||
|
|
||||||
|
import { BrandLogoFrame } from "@/components/brand/brand-logo";
|
||||||
import { navigationTools, type NavigationToolSlug } from "@/constant/navigation-tools";
|
import { navigationTools, type NavigationToolSlug } from "@/constant/navigation-tools";
|
||||||
import { useWalletBalance } from "@/hooks/use-wallet-balance";
|
import { useWalletBalance } from "@/hooks/use-wallet-balance";
|
||||||
import { useWorkspaceLogout } from "@/hooks/use-workspace-logout";
|
import { useWorkspaceLogout } from "@/hooks/use-workspace-logout";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { preloadWorkspaceRoute } from "@/lib/workspace-route-modules";
|
import { preloadWorkspaceRoute } from "@/lib/workspace-route-modules";
|
||||||
import { useUserStore, type FeatureAvailability } from "@/stores/use-user-store";
|
import { useUserStore, type FeatureAvailability } from "@/stores/use-user-store";
|
||||||
|
import { useAppearanceStore } from "@/stores/use-appearance-store";
|
||||||
|
|
||||||
export type WorkspaceNavItem = {
|
export type WorkspaceNavItem = {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -53,11 +55,7 @@ function buildNav(features: FeatureAvailability, balance: string, isAdmin: boole
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
heading: "工作台管理",
|
heading: "工作台管理",
|
||||||
items: [
|
items: [toolItem("skills", "/skills"), ...(features.pluginCenterEnabled || isAdmin ? [toolItem("plugins", "/plugins")] : []), ...(features.creditsEnabled ? [{ ...toolItem("wallet", "/wallet"), badge: balance }] : [])],
|
||||||
toolItem("skills", "/skills"),
|
|
||||||
...(features.pluginCenterEnabled || isAdmin ? [toolItem("plugins", "/plugins")] : []),
|
|
||||||
...(features.creditsEnabled ? [{ ...toolItem("wallet", "/wallet"), badge: balance }] : []),
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -79,6 +77,7 @@ function buildNav(features: FeatureAvailability, balance: string, isAdmin: boole
|
|||||||
}
|
}
|
||||||
|
|
||||||
function WorkspaceSwitcher({ collapsed, onNavigate, onExpand }: { collapsed: boolean; onNavigate: () => void; onExpand: () => void }) {
|
function WorkspaceSwitcher({ collapsed, onNavigate, onExpand }: { collapsed: boolean; onNavigate: () => void; onExpand: () => void }) {
|
||||||
|
const appearance = useAppearanceStore((state) => state.appearance);
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
@@ -91,13 +90,7 @@ function WorkspaceSwitcher({ collapsed, onNavigate, onExpand }: { collapsed: boo
|
|||||||
if (collapsed) {
|
if (collapsed) {
|
||||||
return (
|
return (
|
||||||
<div className="app-workspace-sidebar-rail-header shrink-0">
|
<div className="app-workspace-sidebar-rail-header shrink-0">
|
||||||
<button
|
<button type="button" className="app-workspace-sidebar-rail-button" aria-label="展开侧栏菜单" title="展开侧栏菜单" onClick={onExpand}>
|
||||||
type="button"
|
|
||||||
className="app-workspace-sidebar-rail-button"
|
|
||||||
aria-label="展开侧栏菜单"
|
|
||||||
title="展开侧栏菜单"
|
|
||||||
onClick={onExpand}
|
|
||||||
>
|
|
||||||
<PanelLeftOpen className="size-4" strokeWidth={1.7} />
|
<PanelLeftOpen className="size-4" strokeWidth={1.7} />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -114,11 +107,9 @@ function WorkspaceSwitcher({ collapsed, onNavigate, onExpand }: { collapsed: boo
|
|||||||
className="group flex w-full items-center justify-between rounded-[var(--r-sm)] px-2 py-2 text-left transition-colors select-none hover:bg-surface-hover"
|
className="group flex w-full items-center justify-between rounded-[var(--r-sm)] px-2 py-2 text-left transition-colors select-none hover:bg-surface-hover"
|
||||||
>
|
>
|
||||||
<span className="flex min-w-0 items-center gap-3">
|
<span className="flex min-w-0 items-center gap-3">
|
||||||
<span className="app-workspace-brand-mark grid size-8 shrink-0 place-items-center rounded-[var(--r-sm)] shadow-sm">
|
<BrandLogoFrame className="app-workspace-brand-mark grid size-8 shrink-0 place-items-center rounded-[var(--r-sm)] shadow-sm" logoClassName="size-5 object-contain" alt="" fallback={<InfinityIcon className="size-4" strokeWidth={2} />} />
|
||||||
<InfinityIcon className="size-4" strokeWidth={2} />
|
|
||||||
</span>
|
|
||||||
<span className="flex min-w-0 flex-col">
|
<span className="flex min-w-0 flex-col">
|
||||||
<span className="app-workspace-brand-wordmark truncate text-[var(--fs-body)] leading-none font-medium">影策</span>
|
<span className="app-workspace-brand-wordmark truncate text-[var(--fs-body)] leading-none font-medium">{appearance.brandName}</span>
|
||||||
<span className="mt-1 truncate text-[var(--fs-label)] leading-none text-foreground/42">创作工作台</span>
|
<span className="mt-1 truncate text-[var(--fs-label)] leading-none text-foreground/42">创作工作台</span>
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
@@ -130,7 +121,7 @@ function WorkspaceSwitcher({ collapsed, onNavigate, onExpand }: { collapsed: boo
|
|||||||
<div className="fixed inset-0 z-40" onClick={() => setIsOpen(false)} />
|
<div className="fixed inset-0 z-40" onClick={() => setIsOpen(false)} />
|
||||||
<div className="app-workspace-nav-popover absolute left-3 right-3 top-full z-50 mt-1 overflow-hidden rounded-lg border border-[var(--workspace-border)] bg-[var(--workspace-surface-strong)] py-1 animate-in fade-in zoom-in-95 duration-100">
|
<div className="app-workspace-nav-popover absolute left-3 right-3 top-full z-50 mt-1 overflow-hidden rounded-lg border border-[var(--workspace-border)] bg-[var(--workspace-surface-strong)] py-1 animate-in fade-in zoom-in-95 duration-100">
|
||||||
<div className="px-3 py-2.5">
|
<div className="px-3 py-2.5">
|
||||||
<div className="truncate text-[var(--fs-body)] font-semibold">影策</div>
|
<div className="truncate text-[var(--fs-body)] font-semibold">{appearance.brandName}</div>
|
||||||
<div className="mt-0.5 truncate text-[var(--fs-label)] text-foreground/45">创作工作台</div>
|
<div className="mt-0.5 truncate text-[var(--fs-label)] text-foreground/45">创作工作台</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="mx-2 my-1 h-px bg-[var(--workspace-border)]" />
|
<div className="mx-2 my-1 h-px bg-[var(--workspace-border)]" />
|
||||||
@@ -139,21 +130,12 @@ function WorkspaceSwitcher({ collapsed, onNavigate, onExpand }: { collapsed: boo
|
|||||||
{ label: "画布", to: "/canvas" },
|
{ label: "画布", to: "/canvas" },
|
||||||
{ label: "设置", to: "/settings" },
|
{ label: "设置", to: "/settings" },
|
||||||
].map((entry) => (
|
].map((entry) => (
|
||||||
<button
|
<button key={entry.to} type="button" onClick={() => go(entry.to)} className="flex w-full items-center gap-2 px-3 py-2 text-[var(--fs-body)] text-foreground/80 transition-colors hover:bg-surface-hover hover:text-foreground">
|
||||||
key={entry.to}
|
|
||||||
type="button"
|
|
||||||
onClick={() => go(entry.to)}
|
|
||||||
className="flex w-full items-center gap-2 px-3 py-2 text-[var(--fs-body)] text-foreground/80 transition-colors hover:bg-surface-hover hover:text-foreground"
|
|
||||||
>
|
|
||||||
{entry.label}
|
{entry.label}
|
||||||
</button>
|
</button>
|
||||||
))}
|
))}
|
||||||
<div className="mx-2 my-1 h-px bg-[var(--workspace-border)]" />
|
<div className="mx-2 my-1 h-px bg-[var(--workspace-border)]" />
|
||||||
<button
|
<button type="button" onClick={() => go("/canvas?mode=new")} className="flex w-full items-center gap-2 px-3 py-2 text-[var(--fs-body)] text-foreground/45 transition-colors hover:bg-surface-hover hover:text-foreground">
|
||||||
type="button"
|
|
||||||
onClick={() => go("/canvas?mode=new")}
|
|
||||||
className="flex w-full items-center gap-2 px-3 py-2 text-[var(--fs-body)] text-foreground/45 transition-colors hover:bg-surface-hover hover:text-foreground"
|
|
||||||
>
|
|
||||||
<Plus className="size-3.5" /> 新建画布
|
<Plus className="size-3.5" /> 新建画布
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -163,7 +145,15 @@ function WorkspaceSwitcher({ collapsed, onNavigate, onExpand }: { collapsed: boo
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function NavItem({ item, activeId, onSelect, onOpenSearch, onLogout, level = 0, collapsed = false }: {
|
function NavItem({
|
||||||
|
item,
|
||||||
|
activeId,
|
||||||
|
onSelect,
|
||||||
|
onOpenSearch,
|
||||||
|
onLogout,
|
||||||
|
level = 0,
|
||||||
|
collapsed = false,
|
||||||
|
}: {
|
||||||
item: WorkspaceNavItem;
|
item: WorkspaceNavItem;
|
||||||
activeId: string;
|
activeId: string;
|
||||||
onSelect: (id: string) => void;
|
onSelect: (id: string) => void;
|
||||||
@@ -200,14 +190,8 @@ function NavItem({ item, activeId, onSelect, onOpenSearch, onLogout, level = 0,
|
|||||||
{item.shortcut}
|
{item.shortcut}
|
||||||
</kbd>
|
</kbd>
|
||||||
) : null}
|
) : null}
|
||||||
{item.badge !== undefined ? (
|
{item.badge !== undefined ? <span className="flex min-w-5 items-center justify-center rounded-full bg-primary/10 px-1.5 py-0.5 text-[var(--fs-tiny)] font-medium tabular-nums text-primary">{item.badge}</span> : null}
|
||||||
<span className="flex min-w-5 items-center justify-center rounded-full bg-primary/10 px-1.5 py-0.5 text-[var(--fs-tiny)] font-medium tabular-nums text-primary">
|
{hasChildren ? <ChevronRight className={cn("size-3.5 shrink-0 text-foreground/40 transition-transform duration-200", isOpen && "rotate-90")} strokeWidth={2} /> : null}
|
||||||
{item.badge}
|
|
||||||
</span>
|
|
||||||
) : null}
|
|
||||||
{hasChildren ? (
|
|
||||||
<ChevronRight className={cn("size-3.5 shrink-0 text-foreground/40 transition-transform duration-200", isOpen && "rotate-90")} strokeWidth={2} />
|
|
||||||
) : null}
|
|
||||||
</span>
|
</span>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
@@ -254,15 +238,7 @@ function NavItem({ item, activeId, onSelect, onOpenSearch, onLogout, level = 0,
|
|||||||
{rowContent}
|
{rowContent}
|
||||||
</Link>
|
</Link>
|
||||||
) : (
|
) : (
|
||||||
<button
|
<button type="button" className={rowClassName} style={rowStyle} aria-label={collapsed ? item.title : undefined} title={collapsed ? item.title : undefined} onClick={handleClick} aria-expanded={hasChildren ? isOpen : undefined}>
|
||||||
type="button"
|
|
||||||
className={rowClassName}
|
|
||||||
style={rowStyle}
|
|
||||||
aria-label={collapsed ? item.title : undefined}
|
|
||||||
title={collapsed ? item.title : undefined}
|
|
||||||
onClick={handleClick}
|
|
||||||
aria-expanded={hasChildren ? isOpen : undefined}
|
|
||||||
>
|
|
||||||
{rowContent}
|
{rowContent}
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
@@ -272,16 +248,7 @@ function NavItem({ item, activeId, onSelect, onOpenSearch, onLogout, level = 0,
|
|||||||
<div className="relative flex min-h-0 flex-col gap-0.5 overflow-hidden pt-0.5">
|
<div className="relative flex min-h-0 flex-col gap-0.5 overflow-hidden pt-0.5">
|
||||||
<span className="app-workspace-nav-guide-line" style={{ left: `${(level + 1) * 12 + 12.5}px` }} />
|
<span className="app-workspace-nav-guide-line" style={{ left: `${(level + 1) * 12 + 12.5}px` }} />
|
||||||
{item.children!.map((child) => (
|
{item.children!.map((child) => (
|
||||||
<NavItem
|
<NavItem key={child.id} item={child} activeId={activeId} onSelect={onSelect} onOpenSearch={onOpenSearch} onLogout={onLogout} level={level + 1} collapsed={false} />
|
||||||
key={child.id}
|
|
||||||
item={child}
|
|
||||||
activeId={activeId}
|
|
||||||
onSelect={onSelect}
|
|
||||||
onOpenSearch={onOpenSearch}
|
|
||||||
onLogout={onLogout}
|
|
||||||
level={level + 1}
|
|
||||||
collapsed={false}
|
|
||||||
/>
|
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -290,14 +257,7 @@ function NavItem({ item, activeId, onSelect, onOpenSearch, onLogout, level = 0,
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function NavGroup({ group, activeId, onNavigate, onOpenSearch, onLogout, collapsed }: {
|
function NavGroup({ group, activeId, onNavigate, onOpenSearch, onLogout, collapsed }: { group: WorkspaceNavGroup; activeId: string; onNavigate: () => void; onOpenSearch: () => void; onLogout: () => void; collapsed: boolean }) {
|
||||||
group: WorkspaceNavGroup;
|
|
||||||
activeId: string;
|
|
||||||
onNavigate: () => void;
|
|
||||||
onOpenSearch: () => void;
|
|
||||||
onLogout: () => void;
|
|
||||||
collapsed: boolean;
|
|
||||||
}) {
|
|
||||||
const [isOpen, setIsOpen] = useState(true);
|
const [isOpen, setIsOpen] = useState(true);
|
||||||
const hasActive = group.items.some((item) => item.id === activeId || (item.id === "settings" && activeId.startsWith("settings:")));
|
const hasActive = group.items.some((item) => item.id === activeId || (item.id === "settings" && activeId.startsWith("settings:")));
|
||||||
|
|
||||||
@@ -309,15 +269,7 @@ function NavGroup({ group, activeId, onNavigate, onOpenSearch, onLogout, collaps
|
|||||||
const content = (
|
const content = (
|
||||||
<div className="flex flex-col gap-0.5">
|
<div className="flex flex-col gap-0.5">
|
||||||
{group.items.map((item) => (
|
{group.items.map((item) => (
|
||||||
<NavItem
|
<NavItem key={item.id} item={item} activeId={activeId} onSelect={onNavigate} onOpenSearch={onOpenSearch} onLogout={onLogout} collapsed={collapsed} />
|
||||||
key={item.id}
|
|
||||||
item={item}
|
|
||||||
activeId={activeId}
|
|
||||||
onSelect={onNavigate}
|
|
||||||
onOpenSearch={onOpenSearch}
|
|
||||||
onLogout={onLogout}
|
|
||||||
collapsed={collapsed}
|
|
||||||
/>
|
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -329,17 +281,9 @@ function NavGroup({ group, activeId, onNavigate, onOpenSearch, onLogout, collaps
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex shrink-0 flex-col">
|
<div className="flex shrink-0 flex-col">
|
||||||
<button
|
<button type="button" onClick={() => setIsOpen((open) => !open)} aria-expanded={isOpen} className="app-workspace-nav-group-toggle select-none">
|
||||||
type="button"
|
|
||||||
onClick={() => setIsOpen((open) => !open)}
|
|
||||||
aria-expanded={isOpen}
|
|
||||||
className="app-workspace-nav-group-toggle select-none"
|
|
||||||
>
|
|
||||||
<span className="app-workspace-nav-group-label">{group.heading}</span>
|
<span className="app-workspace-nav-group-label">{group.heading}</span>
|
||||||
<ChevronRight
|
<ChevronRight className={cn("size-3.5 shrink-0 text-foreground/35 transition-transform duration-200", isOpen && "rotate-90")} strokeWidth={2} />
|
||||||
className={cn("size-3.5 shrink-0 text-foreground/35 transition-transform duration-200", isOpen && "rotate-90")}
|
|
||||||
strokeWidth={2}
|
|
||||||
/>
|
|
||||||
</button>
|
</button>
|
||||||
<div className={cn("grid transition-[grid-template-rows,opacity] duration-300 ease-in-out", isOpen ? "grid-rows-[1fr] opacity-100" : "grid-rows-[0fr] opacity-0")}>
|
<div className={cn("grid transition-[grid-template-rows,opacity] duration-300 ease-in-out", isOpen ? "grid-rows-[1fr] opacity-100" : "grid-rows-[0fr] opacity-0")}>
|
||||||
<div className="min-h-0 overflow-hidden pt-0.5">{content}</div>
|
<div className="min-h-0 overflow-hidden pt-0.5">{content}</div>
|
||||||
@@ -357,9 +301,7 @@ export function WorkspaceSidebarNav({ collapsed, onNavigate, onOpenSearch, onExp
|
|||||||
const { availableMicrocredits } = useWalletBalance(user?.id, creditsEnabled);
|
const { availableMicrocredits } = useWalletBalance(user?.id, creditsEnabled);
|
||||||
const { handleLogout } = useWorkspaceLogout();
|
const { handleLogout } = useWorkspaceLogout();
|
||||||
|
|
||||||
const balance = availableMicrocredits === null
|
const balance = availableMicrocredits === null ? "--" : (availableMicrocredits / 1_000_000).toLocaleString("zh-CN", { maximumFractionDigits: 2 });
|
||||||
? "--"
|
|
||||||
: (availableMicrocredits / 1_000_000).toLocaleString("zh-CN", { maximumFractionDigits: 2 });
|
|
||||||
|
|
||||||
const { groups, footer } = useMemo(() => buildNav(features, balance, user?.role === "admin"), [features, balance, user?.role]);
|
const { groups, footer } = useMemo(() => buildNav(features, balance, user?.role === "admin"), [features, balance, user?.role]);
|
||||||
|
|
||||||
@@ -405,38 +347,17 @@ export function WorkspaceSidebarNav({ collapsed, onNavigate, onOpenSearch, onExp
|
|||||||
<div
|
<div
|
||||||
ref={scrollRef}
|
ref={scrollRef}
|
||||||
onScroll={handleScroll}
|
onScroll={handleScroll}
|
||||||
className={cn(
|
className={cn("app-workspace-sidebar-scroll-area flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto px-3 pb-3 pt-2", collapsed && "is-collapsed", scrollState.hasTopFade && "has-top-fade", scrollState.hasBottomFade && "has-bottom-fade")}
|
||||||
"app-workspace-sidebar-scroll-area flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto px-3 pb-3 pt-2",
|
|
||||||
collapsed && "is-collapsed",
|
|
||||||
scrollState.hasTopFade && "has-top-fade",
|
|
||||||
scrollState.hasBottomFade && "has-bottom-fade",
|
|
||||||
)}
|
|
||||||
>
|
>
|
||||||
{groups.map((group, index) => (
|
{groups.map((group, index) => (
|
||||||
<NavGroup
|
<NavGroup key={index} group={group} activeId={activeId} onNavigate={onNavigate} onOpenSearch={onOpenSearch} onLogout={() => void handleLogout()} collapsed={collapsed} />
|
||||||
key={index}
|
|
||||||
group={group}
|
|
||||||
activeId={activeId}
|
|
||||||
onNavigate={onNavigate}
|
|
||||||
onOpenSearch={onOpenSearch}
|
|
||||||
onLogout={() => void handleLogout()}
|
|
||||||
collapsed={collapsed}
|
|
||||||
/>
|
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="app-workspace-sidebar-footer shrink-0 px-3 py-3">
|
<div className="app-workspace-sidebar-footer shrink-0 px-3 py-3">
|
||||||
<div className="flex flex-col gap-0.5">
|
<div className="flex flex-col gap-0.5">
|
||||||
{footer.map((item) => (
|
{footer.map((item) => (
|
||||||
<NavItem
|
<NavItem key={item.id} item={item} activeId={activeId} onSelect={onNavigate} onOpenSearch={onOpenSearch} onLogout={() => void handleLogout()} collapsed={collapsed} />
|
||||||
key={item.id}
|
|
||||||
item={item}
|
|
||||||
activeId={activeId}
|
|
||||||
onSelect={onNavigate}
|
|
||||||
onOpenSearch={onOpenSearch}
|
|
||||||
onLogout={() => void handleLogout()}
|
|
||||||
collapsed={collapsed}
|
|
||||||
/>
|
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { useWorkspaceTopBarContent } from "@/components/layout/workspace-top-bar
|
|||||||
import { AnimatedThemeToggler } from "@/components/ui/animated-theme-toggler";
|
import { AnimatedThemeToggler } from "@/components/ui/animated-theme-toggler";
|
||||||
import { useThemeStore } from "@/stores/use-theme-store";
|
import { useThemeStore } from "@/stores/use-theme-store";
|
||||||
import { useUserStore } from "@/stores/use-user-store";
|
import { useUserStore } from "@/stores/use-user-store";
|
||||||
|
import { useAppearanceStore } from "@/stores/use-appearance-store";
|
||||||
|
|
||||||
const PAGE_TITLES: Record<string, string> = {
|
const PAGE_TITLES: Record<string, string> = {
|
||||||
home: "首页",
|
home: "首页",
|
||||||
@@ -21,6 +22,7 @@ const PAGE_TITLES: Record<string, string> = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function WorkspaceTopBar({ sidebarOpen, onToggleSidebar }: { sidebarOpen: boolean; onToggleSidebar: () => void }) {
|
export function WorkspaceTopBar({ sidebarOpen, onToggleSidebar }: { sidebarOpen: boolean; onToggleSidebar: () => void }) {
|
||||||
|
const brandName = useAppearanceStore((state) => state.appearance.brandName);
|
||||||
const theme = useThemeStore((state) => state.theme);
|
const theme = useThemeStore((state) => state.theme);
|
||||||
const setTheme = useThemeStore((state) => state.setTheme);
|
const setTheme = useThemeStore((state) => state.setTheme);
|
||||||
const user = useUserStore((state) => state.user);
|
const user = useUserStore((state) => state.user);
|
||||||
@@ -28,7 +30,7 @@ export function WorkspaceTopBar({ sidebarOpen, onToggleSidebar }: { sidebarOpen:
|
|||||||
const extension = useWorkspaceTopBarContent();
|
const extension = useWorkspaceTopBarContent();
|
||||||
|
|
||||||
const slug = pathname.split("/").filter(Boolean)[0];
|
const slug = pathname.split("/").filter(Boolean)[0];
|
||||||
const pageTitle = (slug && PAGE_TITLES[slug]) || "影策";
|
const pageTitle = (slug && PAGE_TITLES[slug]) || brandName;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<header className={`app-workspace-topbar flex shrink-0 items-center justify-between gap-2 px-3 sm:px-4 ${extension ? "has-extension" : ""}`}>
|
<header className={`app-workspace-topbar flex shrink-0 items-center justify-between gap-2 px-3 sm:px-4 ${extension ? "has-extension" : ""}`}>
|
||||||
@@ -37,7 +39,7 @@ export function WorkspaceTopBar({ sidebarOpen, onToggleSidebar }: { sidebarOpen:
|
|||||||
{sidebarOpen ? <PanelLeftClose className="size-4" /> : <PanelLeftOpen className="size-4" />}
|
{sidebarOpen ? <PanelLeftClose className="size-4" /> : <PanelLeftOpen className="size-4" />}
|
||||||
</button>
|
</button>
|
||||||
<nav className={`${extension ? "hidden 2xl:flex" : "flex"} min-w-0 items-center gap-2 text-[var(--fs-caption)] text-foreground/50`} aria-label="当前位置">
|
<nav className={`${extension ? "hidden 2xl:flex" : "flex"} min-w-0 items-center gap-2 text-[var(--fs-caption)] text-foreground/50`} aria-label="当前位置">
|
||||||
<Link to="/" className="shrink-0 font-medium text-foreground/70 transition-colors hover:text-foreground">影策</Link>
|
<Link to="/" className="shrink-0 font-medium text-foreground/70 transition-colors hover:text-foreground">{brandName}</Link>
|
||||||
<span className="shrink-0 text-foreground/30">/</span>
|
<span className="shrink-0 text-foreground/30">/</span>
|
||||||
<span className="truncate font-medium text-foreground">{pageTitle}</span>
|
<span className="truncate font-medium text-foreground">{pageTitle}</span>
|
||||||
</nav>
|
</nav>
|
||||||
|
|||||||
+2
-1
@@ -1,4 +1,5 @@
|
|||||||
import { runLocalRuntimeBootstrap } from "@/services/local-runtime-bootstrap";
|
import { runLocalRuntimeBootstrap } from "@/services/local-runtime-bootstrap";
|
||||||
|
import { bootstrapAppearance } from "@/services/appearance-bootstrap";
|
||||||
|
|
||||||
runLocalRuntimeBootstrap(
|
runLocalRuntimeBootstrap(
|
||||||
{
|
{
|
||||||
@@ -13,6 +14,6 @@ runLocalRuntimeBootstrap(
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
void import("./application");
|
void bootstrapAppearance().finally(() => import("./application"));
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -20,6 +20,7 @@ import {
|
|||||||
Mail,
|
Mail,
|
||||||
MessageSquareText,
|
MessageSquareText,
|
||||||
Moon,
|
Moon,
|
||||||
|
Palette,
|
||||||
Paintbrush,
|
Paintbrush,
|
||||||
PlugZap,
|
PlugZap,
|
||||||
RadioTower,
|
RadioTower,
|
||||||
@@ -36,6 +37,7 @@ import { useEffect, useState, type ReactNode } from "react";
|
|||||||
import { Link, NavLink, Outlet, useLocation } from "react-router";
|
import { Link, NavLink, Outlet, useLocation } from "react-router";
|
||||||
|
|
||||||
import { AppChangelogButton } from "@/components/layout/app-changelog-modal";
|
import { AppChangelogButton } from "@/components/layout/app-changelog-modal";
|
||||||
|
import { BrandLogoFrame } from "@/components/brand/brand-logo";
|
||||||
import { WorkspacePage } from "@/components/layout/workspace-page";
|
import { WorkspacePage } from "@/components/layout/workspace-page";
|
||||||
import { publishWorkspaceSidebarCollapsed, readWorkspaceSidebarCollapsed, subscribeWorkspaceSidebarCollapsed } from "@/components/layout/workspace-sidebar-state";
|
import { publishWorkspaceSidebarCollapsed, readWorkspaceSidebarCollapsed, subscribeWorkspaceSidebarCollapsed } from "@/components/layout/workspace-sidebar-state";
|
||||||
import { getAdminAntThemeConfig } from "@/lib/app-theme";
|
import { getAdminAntThemeConfig } from "@/lib/app-theme";
|
||||||
@@ -43,6 +45,7 @@ import { cn } from "@/lib/utils";
|
|||||||
import "@/styles/admin-ui.css";
|
import "@/styles/admin-ui.css";
|
||||||
import { useThemeStore } from "@/stores/use-theme-store";
|
import { useThemeStore } from "@/stores/use-theme-store";
|
||||||
import { useUserStore } from "@/stores/use-user-store";
|
import { useUserStore } from "@/stores/use-user-store";
|
||||||
|
import { useAppearanceStore } from "@/stores/use-appearance-store";
|
||||||
|
|
||||||
type AdminNavigationItem = {
|
type AdminNavigationItem = {
|
||||||
path: string;
|
path: string;
|
||||||
@@ -81,6 +84,7 @@ const adminNavigation: Array<{ label: string; items: AdminNavigationItem[] }> =
|
|||||||
{
|
{
|
||||||
label: "系统配置",
|
label: "系统配置",
|
||||||
items: [
|
items: [
|
||||||
|
{ path: "/admin/settings/appearance", label: "外观管理", description: "品牌、Logo 与登录影片", icon: <Palette className="size-4" /> },
|
||||||
{ path: "/admin/settings/features", label: "功能开放", description: "工作台、插件与模型能力", icon: <ToggleLeft className="size-4" /> },
|
{ path: "/admin/settings/features", label: "功能开放", description: "工作台、插件与模型能力", icon: <ToggleLeft className="size-4" /> },
|
||||||
{ path: "/admin/settings/drawing-engine", label: "绘图工具", description: "画布绘图节点默认引擎", icon: <Paintbrush className="size-4" /> },
|
{ path: "/admin/settings/drawing-engine", label: "绘图工具", description: "画布绘图节点默认引擎", icon: <Paintbrush className="size-4" /> },
|
||||||
{ path: "/admin/settings/runtime-policy", label: "资源与策略", description: "配额、并发、频控与超时", icon: <Settings2 className="size-4" /> },
|
{ path: "/admin/settings/runtime-policy", label: "资源与策略", description: "配额、并发、频控与超时", icon: <Settings2 className="size-4" /> },
|
||||||
@@ -103,6 +107,7 @@ function isAdminNavigationPath(pathname: string, navigationPath: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function AdminShell() {
|
export function AdminShell() {
|
||||||
|
const appearance = useAppearanceStore((state) => state.appearance);
|
||||||
const [collapsed, setCollapsed] = useState(readWorkspaceSidebarCollapsed);
|
const [collapsed, setCollapsed] = useState(readWorkspaceSidebarCollapsed);
|
||||||
const dark = useThemeStore((state) => state.theme === "dark");
|
const dark = useThemeStore((state) => state.theme === "dark");
|
||||||
|
|
||||||
@@ -129,12 +134,8 @@ export function AdminShell() {
|
|||||||
<Tooltip mouseEnterDelay={0.1} title={collapsed ? "查看更新日志" : undefined} placement="right" rootClassName="app-workspace-sidebar-tooltip">
|
<Tooltip mouseEnterDelay={0.1} title={collapsed ? "查看更新日志" : undefined} placement="right" rootClassName="app-workspace-sidebar-tooltip">
|
||||||
<AppChangelogButton
|
<AppChangelogButton
|
||||||
className={cn("admin-sidebar-brand-button", collapsed && "is-collapsed")}
|
className={cn("admin-sidebar-brand-button", collapsed && "is-collapsed")}
|
||||||
icon={
|
icon={<BrandLogoFrame className="admin-sidebar-brand-mark grid shrink-0 place-items-center bg-foreground text-background" logoClassName="size-5 object-contain" alt="" fallback={<InfinityIcon className="size-4" />} />}
|
||||||
<span className="admin-sidebar-brand-mark grid shrink-0 place-items-center bg-foreground text-background">
|
label={appearance.brandName}
|
||||||
<InfinityIcon className="size-4" />
|
|
||||||
</span>
|
|
||||||
}
|
|
||||||
label="影策"
|
|
||||||
showLabel={!collapsed}
|
showLabel={!collapsed}
|
||||||
showVersion={!collapsed}
|
showVersion={!collapsed}
|
||||||
labelClassName="admin-sidebar-brand-title"
|
labelClassName="admin-sidebar-brand-title"
|
||||||
|
|||||||
@@ -0,0 +1,633 @@
|
|||||||
|
import { App, Button, Form, Input, Skeleton, Switch } from "antd";
|
||||||
|
import { Image as ImageIcon, MonitorPlay, Moon, Palette, RefreshCw, RotateCcw, Save, Sun, Type, Undo2, Upload } from "lucide-react";
|
||||||
|
import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode, type RefObject } from "react";
|
||||||
|
import { useBlocker } from "react-router";
|
||||||
|
|
||||||
|
import { AdminPageFrame } from "@/pages/admin/components/admin-shell";
|
||||||
|
import { AdminStatusBadge, SettingsSectionCard } from "@/pages/admin/components/admin-ui";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { deleteAdminResources } from "@/services/api/admin-storage";
|
||||||
|
import { getAdminAppearance, resetAdminAppearance, updateAdminAppearance, uploadAppearanceAsset, type AdminAppearance, type AppearanceAssetSlot } from "@/services/api/appearance";
|
||||||
|
import { commitPublicAppearance, DEFAULT_PUBLIC_APPEARANCE } from "@/stores/use-appearance-store";
|
||||||
|
|
||||||
|
type DraftFiles = Record<AppearanceAssetSlot, File | null>;
|
||||||
|
type ResetState = Record<AppearanceAssetSlot, boolean>;
|
||||||
|
|
||||||
|
const EMPTY_FILES: DraftFiles = { logo: null, "logo-dark": null, video: null, poster: null };
|
||||||
|
const EMPTY_RESETS: ResetState = { logo: false, "logo-dark": false, video: false, poster: false };
|
||||||
|
const FILE_RULES: Record<AppearanceAssetSlot, { accept: string; maxBytes: number; label: string }> = {
|
||||||
|
logo: { accept: "image/png,image/jpeg,image/webp", maxBytes: 5 << 20, label: "浅色模式 Logo" },
|
||||||
|
"logo-dark": { accept: "image/png,image/jpeg,image/webp", maxBytes: 5 << 20, label: "深色模式 Logo" },
|
||||||
|
poster: { accept: "image/png,image/jpeg,image/webp", maxBytes: 10 << 20, label: "视频封面" },
|
||||||
|
video: { accept: "video/mp4,video/webm", maxBytes: 256 << 20, label: "品牌视频" },
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function AppearanceSettingsPage() {
|
||||||
|
const { message, modal } = App.useApp();
|
||||||
|
const [setting, setSetting] = useState<AdminAppearance | null>(null);
|
||||||
|
const [brandName, setBrandName] = useState("");
|
||||||
|
const [brandSlug, setBrandSlug] = useState("");
|
||||||
|
const [authHeroTitle, setAuthHeroTitle] = useState("");
|
||||||
|
const [authHeroDescription, setAuthHeroDescription] = useState("");
|
||||||
|
const [logoFrameEnabled, setLogoFrameEnabled] = useState(true);
|
||||||
|
const [files, setFiles] = useState<DraftFiles>(EMPTY_FILES);
|
||||||
|
const [resets, setResets] = useState<ResetState>(EMPTY_RESETS);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [refreshing, setRefreshing] = useState(false);
|
||||||
|
const [saving, setSaving] = useState(false);
|
||||||
|
const [restoring, setRestoring] = useState(false);
|
||||||
|
const [loadError, setLoadError] = useState("");
|
||||||
|
const requestVersionRef = useRef(0);
|
||||||
|
const inputRefs = {
|
||||||
|
logo: useRef<HTMLInputElement>(null),
|
||||||
|
"logo-dark": useRef<HTMLInputElement>(null),
|
||||||
|
video: useRef<HTMLInputElement>(null),
|
||||||
|
poster: useRef<HTMLInputElement>(null),
|
||||||
|
};
|
||||||
|
|
||||||
|
const dirty =
|
||||||
|
Boolean(setting) &&
|
||||||
|
(brandName.trim() !== setting?.brandName ||
|
||||||
|
brandSlug.trim().toLocaleLowerCase() !== setting?.brandSlug ||
|
||||||
|
normalizeDraftCopy(authHeroTitle) !== setting?.authHeroTitle ||
|
||||||
|
normalizeDraftCopy(authHeroDescription) !== setting?.authHeroDescription ||
|
||||||
|
logoFrameEnabled !== setting?.logoFrameEnabled ||
|
||||||
|
Object.values(files).some(Boolean) ||
|
||||||
|
Object.values(resets).some(Boolean));
|
||||||
|
const blocker = useBlocker(dirty && !saving && !restoring);
|
||||||
|
|
||||||
|
const applySetting = useCallback((value: AdminAppearance) => {
|
||||||
|
setSetting(value);
|
||||||
|
setBrandName(value.brandName);
|
||||||
|
setBrandSlug(value.brandSlug);
|
||||||
|
setAuthHeroTitle(value.authHeroTitle);
|
||||||
|
setAuthHeroDescription(value.authHeroDescription);
|
||||||
|
setLogoFrameEnabled(value.logoFrameEnabled);
|
||||||
|
setFiles(EMPTY_FILES);
|
||||||
|
setResets(EMPTY_RESETS);
|
||||||
|
setLoadError("");
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const load = useCallback(
|
||||||
|
async (initial = false) => {
|
||||||
|
const requestVersion = ++requestVersionRef.current;
|
||||||
|
if (initial) setLoading(true);
|
||||||
|
else setRefreshing(true);
|
||||||
|
try {
|
||||||
|
const value = await getAdminAppearance();
|
||||||
|
if (requestVersion === requestVersionRef.current) applySetting(value);
|
||||||
|
} catch (error) {
|
||||||
|
if (requestVersion !== requestVersionRef.current) return;
|
||||||
|
const detail = error instanceof Error ? error.message : "读取外观配置失败";
|
||||||
|
setLoadError(detail);
|
||||||
|
if (!initial) message.error(detail);
|
||||||
|
} finally {
|
||||||
|
if (requestVersion === requestVersionRef.current) {
|
||||||
|
setLoading(false);
|
||||||
|
setRefreshing(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[applySetting, message],
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void load(true);
|
||||||
|
return () => {
|
||||||
|
requestVersionRef.current += 1;
|
||||||
|
};
|
||||||
|
}, [load]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (blocker.state !== "blocked") return;
|
||||||
|
modal.confirm({
|
||||||
|
title: "放弃外观调整?",
|
||||||
|
content: "当前品牌信息、登录页文案或媒体文件尚未保存,离开后草稿会丢失。线上外观不会改变。",
|
||||||
|
okText: "放弃并离开",
|
||||||
|
cancelText: "继续编辑",
|
||||||
|
okButtonProps: { danger: true },
|
||||||
|
onOk: () => blocker.proceed(),
|
||||||
|
onCancel: () => blocker.reset(),
|
||||||
|
});
|
||||||
|
}, [blocker, modal]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const beforeUnload = (event: BeforeUnloadEvent) => {
|
||||||
|
if (!dirty || saving || restoring) return;
|
||||||
|
event.preventDefault();
|
||||||
|
};
|
||||||
|
window.addEventListener("beforeunload", beforeUnload);
|
||||||
|
return () => window.removeEventListener("beforeunload", beforeUnload);
|
||||||
|
}, [dirty, restoring, saving]);
|
||||||
|
|
||||||
|
const selectFile = (slot: AppearanceAssetSlot, file?: File) => {
|
||||||
|
if (!file) return;
|
||||||
|
const rule = FILE_RULES[slot];
|
||||||
|
if (!rule.accept.split(",").includes(file.type) || file.size <= 0 || file.size > rule.maxBytes) {
|
||||||
|
message.error(`${rule.label}须使用支持的格式,且不超过 ${rule.maxBytes >> 20}MB`);
|
||||||
|
if (inputRefs[slot].current) inputRefs[slot].current.value = "";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setFiles((current) => ({
|
||||||
|
...current,
|
||||||
|
[slot]: file,
|
||||||
|
...(slot === "video" ? { poster: null } : {}),
|
||||||
|
}));
|
||||||
|
setResets((current) => ({
|
||||||
|
...current,
|
||||||
|
[slot]: false,
|
||||||
|
...(slot === "video" ? { poster: true } : {}),
|
||||||
|
}));
|
||||||
|
if (slot === "video" && inputRefs.poster.current) inputRefs.poster.current.value = "";
|
||||||
|
};
|
||||||
|
|
||||||
|
const resetAsset = (slot: AppearanceAssetSlot) => {
|
||||||
|
setFiles((current) => ({
|
||||||
|
...current,
|
||||||
|
[slot]: null,
|
||||||
|
...(slot === "video" ? { poster: null } : {}),
|
||||||
|
}));
|
||||||
|
setResets((current) => ({
|
||||||
|
...current,
|
||||||
|
[slot]: true,
|
||||||
|
...(slot === "video" ? { poster: true } : {}),
|
||||||
|
}));
|
||||||
|
if (inputRefs[slot].current) inputRefs[slot].current.value = "";
|
||||||
|
if (slot === "video" && inputRefs.poster.current) inputRefs.poster.current.value = "";
|
||||||
|
};
|
||||||
|
|
||||||
|
const discardDraft = () => {
|
||||||
|
if (!setting || saving || restoring) return;
|
||||||
|
setBrandName(setting.brandName);
|
||||||
|
setBrandSlug(setting.brandSlug);
|
||||||
|
setAuthHeroTitle(setting.authHeroTitle);
|
||||||
|
setAuthHeroDescription(setting.authHeroDescription);
|
||||||
|
setLogoFrameEnabled(setting.logoFrameEnabled);
|
||||||
|
setFiles(EMPTY_FILES);
|
||||||
|
setResets(EMPTY_RESETS);
|
||||||
|
Object.values(inputRefs).forEach((ref) => {
|
||||||
|
if (ref.current) ref.current.value = "";
|
||||||
|
});
|
||||||
|
message.info("已撤销未保存的外观调整");
|
||||||
|
};
|
||||||
|
|
||||||
|
const requestRefresh = () => {
|
||||||
|
if (!dirty) {
|
||||||
|
void load(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
modal.confirm({
|
||||||
|
title: "放弃调整并重新读取?",
|
||||||
|
content: "重新读取会丢弃当前品牌信息、登录页文案和待上传文件。",
|
||||||
|
okText: "放弃并刷新",
|
||||||
|
cancelText: "继续编辑",
|
||||||
|
okButtonProps: { danger: true },
|
||||||
|
onOk: () => load(false),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const restoreBuiltInAppearance = () => {
|
||||||
|
if (!setting?.configured || saving || refreshing || restoring) return;
|
||||||
|
modal.confirm({
|
||||||
|
title: "恢复影策默认品牌标识?",
|
||||||
|
content: "品牌名称、英文标识、Logo、登录页文案、视频、封面和皮肤配置会立即恢复为项目内置值。已上传文件仍保留在存储资源中,不会被删除。",
|
||||||
|
okText: "恢复默认",
|
||||||
|
cancelText: "取消",
|
||||||
|
okButtonProps: { danger: true },
|
||||||
|
onOk: async () => {
|
||||||
|
setRestoring(true);
|
||||||
|
requestVersionRef.current += 1;
|
||||||
|
try {
|
||||||
|
const restored = await resetAdminAppearance();
|
||||||
|
applySetting(restored);
|
||||||
|
commitPublicAppearance(restored.public);
|
||||||
|
Object.values(inputRefs).forEach((ref) => {
|
||||||
|
if (ref.current) ref.current.value = "";
|
||||||
|
});
|
||||||
|
message.success("已恢复影策默认品牌标识");
|
||||||
|
} catch (error) {
|
||||||
|
message.error(error instanceof Error ? error.message : "恢复默认外观失败");
|
||||||
|
throw error;
|
||||||
|
} finally {
|
||||||
|
setRestoring(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const save = async () => {
|
||||||
|
if (!setting || saving || restoring) return;
|
||||||
|
const nextBrandName = brandName.trim();
|
||||||
|
const nextBrandSlug = brandSlug.trim().toLocaleLowerCase();
|
||||||
|
const nextAuthHeroTitle = normalizeDraftCopy(authHeroTitle);
|
||||||
|
const nextAuthHeroDescription = normalizeDraftCopy(authHeroDescription);
|
||||||
|
if (!nextBrandName || Array.from(nextBrandName).length > 40) {
|
||||||
|
message.error("品牌名称必须为 1 到 40 个字符");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!/^[a-z0-9](?:[a-z0-9-]{0,46}[a-z0-9])?$/.test(nextBrandSlug)) {
|
||||||
|
message.error("英文品牌标识须为 1 到 48 位小写字母、数字或连字符");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!nextAuthHeroTitle || Array.from(nextAuthHeroTitle).length > 80 || hasUnsupportedControlCharacter(nextAuthHeroTitle)) {
|
||||||
|
message.error("登录页主标题必须为 1 到 80 个字符,可使用换行");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Array.from(nextAuthHeroDescription).length > 160 || hasUnsupportedControlCharacter(nextAuthHeroDescription)) {
|
||||||
|
message.error("登录页说明文案不能超过 160 个字符,可使用换行");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setSaving(true);
|
||||||
|
const uploadedIDs: string[] = [];
|
||||||
|
try {
|
||||||
|
const ids: Record<AppearanceAssetSlot, string> = {
|
||||||
|
logo: resets.logo ? "" : setting.logoResourceId,
|
||||||
|
"logo-dark": resets["logo-dark"] ? "" : setting.darkLogoResourceId,
|
||||||
|
video: resets.video ? "" : setting.authVideoResourceId,
|
||||||
|
poster: resets.poster ? "" : setting.authVideoPosterResourceId,
|
||||||
|
};
|
||||||
|
for (const slot of ["logo", "logo-dark", "video", "poster"] as AppearanceAssetSlot[]) {
|
||||||
|
const file = files[slot];
|
||||||
|
if (!file) continue;
|
||||||
|
const resource = await uploadAppearanceAsset(slot, file);
|
||||||
|
uploadedIDs.push(resource.id);
|
||||||
|
ids[slot] = resource.id;
|
||||||
|
}
|
||||||
|
const updated = await updateAdminAppearance({
|
||||||
|
brandName: nextBrandName,
|
||||||
|
brandSlug: nextBrandSlug,
|
||||||
|
authHeroTitle: nextAuthHeroTitle,
|
||||||
|
authHeroDescription: nextAuthHeroDescription,
|
||||||
|
logoResourceId: ids.logo,
|
||||||
|
darkLogoResourceId: ids["logo-dark"],
|
||||||
|
logoFrameEnabled,
|
||||||
|
authVideoResourceId: ids.video,
|
||||||
|
authVideoPosterResourceId: ids.poster,
|
||||||
|
skinId: setting.skinId,
|
||||||
|
});
|
||||||
|
applySetting(updated);
|
||||||
|
commitPublicAppearance(updated.public);
|
||||||
|
Object.values(inputRefs).forEach((ref) => {
|
||||||
|
if (ref.current) ref.current.value = "";
|
||||||
|
});
|
||||||
|
message.success("外观配置已保存并立即生效");
|
||||||
|
} catch (error) {
|
||||||
|
const detail = error instanceof Error ? error.message : "保存外观配置失败";
|
||||||
|
if (uploadedIDs.length) {
|
||||||
|
try {
|
||||||
|
await deleteAdminResources(uploadedIDs);
|
||||||
|
} catch {
|
||||||
|
message.warning("保存失败,且临时上传文件未能自动清理;可在存储资源中检查");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
message.error(detail);
|
||||||
|
} finally {
|
||||||
|
setSaving(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const previews = useAppearancePreviews(setting, files, resets);
|
||||||
|
const lightLogoSelected = Boolean(files.logo || (!resets.logo && setting?.logoResourceId));
|
||||||
|
const darkLogoSelected = Boolean(files["logo-dark"] || (!resets["logo-dark"] && setting?.darkLogoResourceId));
|
||||||
|
const status = setting?.configured ? <AdminStatusBadge label="已自定义" tone="success" /> : <AdminStatusBadge label="使用原始外观" tone="neutral" />;
|
||||||
|
const copyCustomized = normalizeDraftCopy(authHeroTitle) !== DEFAULT_PUBLIC_APPEARANCE.authHeroTitle || normalizeDraftCopy(authHeroDescription) !== DEFAULT_PUBLIC_APPEARANCE.authHeroDescription;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AdminPageFrame title="外观管理" description="统一设置平台品牌、登录页内容与媒体,并为后续皮肤库保留扩展入口" scroll>
|
||||||
|
{loading ? (
|
||||||
|
<AppearanceSkeleton />
|
||||||
|
) : loadError || !setting ? (
|
||||||
|
<div className="admin-settings-stack admin-appearance-settings">
|
||||||
|
<div className="admin-appearance-load-error" role="alert">
|
||||||
|
<span className="admin-appearance-load-error-icon">
|
||||||
|
<Palette className="size-5" aria-hidden="true" />
|
||||||
|
</span>
|
||||||
|
<div>
|
||||||
|
<h2>无法读取外观配置</h2>
|
||||||
|
<p>{loadError || "当前没有可显示的配置,请稍后重试。"}</p>
|
||||||
|
</div>
|
||||||
|
<Button icon={<RefreshCw className="size-4" />} onClick={() => void load(true)}>
|
||||||
|
重新读取
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="admin-settings-stack admin-appearance-settings">
|
||||||
|
<div className={cn("admin-appearance-command-bar", dirty && "is-dirty")}>
|
||||||
|
<div className="admin-appearance-command-copy" aria-live="polite">
|
||||||
|
<div>
|
||||||
|
<div className="flex flex-wrap items-center gap-2">
|
||||||
|
<strong>{dirty ? "外观配置有调整待保存" : "外观配置已与服务端同步"}</strong>
|
||||||
|
<AdminStatusBadge label={dirty ? "尚未生效" : "服务端当前值"} tone={dirty ? "warning" : "neutral"} />
|
||||||
|
</div>
|
||||||
|
<p>{dirty ? "品牌、文案和媒体只在本页预览;保存后才会应用到公开页面。" : "保存后公开页面会在应用渲染前读取新配置,不会先闪现旧品牌。"}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="admin-appearance-command-actions">
|
||||||
|
{dirty ? (
|
||||||
|
<Button icon={<Undo2 className="size-4" />} disabled={saving || restoring} onClick={discardDraft}>
|
||||||
|
撤销调整
|
||||||
|
</Button>
|
||||||
|
) : null}
|
||||||
|
<Button icon={<RotateCcw className="size-4" />} loading={restoring} disabled={!setting.configured || saving || refreshing} onClick={restoreBuiltInAppearance}>
|
||||||
|
恢复影策默认
|
||||||
|
</Button>
|
||||||
|
<Button icon={<RefreshCw className="size-4" />} loading={refreshing} disabled={saving || restoring} onClick={requestRefresh}>
|
||||||
|
刷新状态
|
||||||
|
</Button>
|
||||||
|
<Button type="primary" icon={<Save className="size-4" />} loading={saving} disabled={!dirty || refreshing || restoring} onClick={() => void save()}>
|
||||||
|
保存修改
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<SettingsSectionCard
|
||||||
|
className="admin-appearance-section admin-appearance-brand-section"
|
||||||
|
icon={<Palette className="size-4" aria-hidden="true" />}
|
||||||
|
title="1. 设置品牌识别"
|
||||||
|
description="中文品牌名用于主要界面,英文品牌标识用于英文角标和可安全品牌化的路径建议;不会改动代码包、数据库或部署标识。"
|
||||||
|
status={status}
|
||||||
|
>
|
||||||
|
<div className="admin-appearance-brand-layout">
|
||||||
|
<Form className="admin-appearance-form" layout="vertical" requiredMark={false} disabled={saving || refreshing || restoring}>
|
||||||
|
<Form.Item label="品牌名称" extra="1–40 个字符。保存后同步到登录页、工作台、管理后台与浏览器标题。">
|
||||||
|
<Input value={brandName} maxLength={40} showCount placeholder="输入品牌名称" onChange={(event) => setBrandName(event.target.value)} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item label="英文品牌标识" extra="1–48 位小写字母、数字或连字符,例如 hima-studio。对象存储可一键采用该值作为路径前缀。">
|
||||||
|
<Input
|
||||||
|
value={brandSlug}
|
||||||
|
maxLength={48}
|
||||||
|
showCount
|
||||||
|
autoCapitalize="none"
|
||||||
|
autoCorrect="off"
|
||||||
|
spellCheck={false}
|
||||||
|
placeholder="例如:hima-studio"
|
||||||
|
onChange={(event) => setBrandSlug(event.target.value.toLocaleLowerCase().replace(/[^a-z0-9-]/g, ""))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
<div className="admin-appearance-brand-logo admin-appearance-logo-stack">
|
||||||
|
<AssetPicker
|
||||||
|
slot="logo"
|
||||||
|
title="浅色模式 Logo"
|
||||||
|
description="用于浅色界面;建议透明背景 PNG 或 WebP。"
|
||||||
|
configured={Boolean(setting.logoResourceId) && !resets.logo}
|
||||||
|
file={files.logo}
|
||||||
|
inputRef={inputRefs.logo}
|
||||||
|
onSelect={selectFile}
|
||||||
|
onReset={resetAsset}
|
||||||
|
disabled={saving || refreshing || restoring}
|
||||||
|
emptyLabel={darkLogoSelected ? "将自动复用深色模式 Logo" : "未上传时使用项目原始 Logo"}
|
||||||
|
/>
|
||||||
|
<AssetPicker
|
||||||
|
slot="logo-dark"
|
||||||
|
title="深色模式 Logo(可选)"
|
||||||
|
description="用于深色界面;不上传时自动复用浅色模式 Logo。"
|
||||||
|
configured={Boolean(setting.darkLogoResourceId) && !resets["logo-dark"]}
|
||||||
|
file={files["logo-dark"]}
|
||||||
|
inputRef={inputRefs["logo-dark"]}
|
||||||
|
onSelect={selectFile}
|
||||||
|
onReset={resetAsset}
|
||||||
|
disabled={saving || refreshing || restoring}
|
||||||
|
emptyLabel={lightLogoSelected ? "将自动复用浅色模式 Logo" : "未上传时使用项目原始 Logo"}
|
||||||
|
/>
|
||||||
|
<div className="admin-appearance-logo-frame-option">
|
||||||
|
<div className="admin-appearance-logo-frame-copy">
|
||||||
|
<strong>禁用 Logo 后面的圆角矩形外框</strong>
|
||||||
|
<p id="appearance-logo-frame-help">开启后,工作台和管理后台导航只显示 Logo 本身;Logo 会等比放大到原外框的可用区域,导航占位保持不变。</p>
|
||||||
|
</div>
|
||||||
|
<div className="admin-appearance-logo-frame-control">
|
||||||
|
<span>{logoFrameEnabled ? "保留外框" : "已禁用外框"}</span>
|
||||||
|
<Switch
|
||||||
|
checked={!logoFrameEnabled}
|
||||||
|
disabled={saving || refreshing || restoring}
|
||||||
|
aria-label="禁用 Logo 后面的圆角矩形外框"
|
||||||
|
aria-describedby="appearance-logo-frame-help"
|
||||||
|
onChange={(checked) => setLogoFrameEnabled(!checked)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="admin-appearance-logo-preview-grid" aria-label="深浅模式 Logo 预览">
|
||||||
|
<LogoThemePreview label="浅色界面" icon={<Sun />} src={previews.logoLight} dark={false} frameEnabled={logoFrameEnabled} />
|
||||||
|
<LogoThemePreview label="深色界面" icon={<Moon />} src={previews.logoDark} dark frameEnabled={logoFrameEnabled} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</SettingsSectionCard>
|
||||||
|
|
||||||
|
<SettingsSectionCard
|
||||||
|
className="admin-appearance-section admin-appearance-auth-section"
|
||||||
|
icon={<MonitorPlay className="size-4" aria-hidden="true" />}
|
||||||
|
title="2. 设置登录页内容与媒体"
|
||||||
|
description="登录、注册与找回密码共享左侧品牌文案和影片;更换视频会同时取消旧封面,避免品牌串帧。"
|
||||||
|
status={
|
||||||
|
<AdminStatusBadge
|
||||||
|
label={copyCustomized || setting.authVideoResourceId || setting.authVideoPosterResourceId ? "已配置" : "使用原始内容"}
|
||||||
|
tone={copyCustomized || setting.authVideoResourceId || setting.authVideoPosterResourceId ? "success" : "neutral"}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<div className="admin-appearance-auth-layout">
|
||||||
|
<div className="admin-appearance-auth-controls">
|
||||||
|
<Form className="admin-appearance-form" layout="vertical" requiredMark={false} disabled={saving || refreshing || restoring}>
|
||||||
|
<Form.Item label="登录页主标题" extra="1–80 个字符,可换行;登录、注册和找回密码页面共用。">
|
||||||
|
<Input.TextArea value={authHeroTitle} maxLength={80} showCount autoSize={{ minRows: 2, maxRows: 4 }} placeholder="输入登录页主标题" onChange={(event) => setAuthHeroTitle(event.target.value)} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item label="登录页说明文案(可选)" extra="最多 160 个字符,可换行;留空时不显示说明。">
|
||||||
|
<Input.TextArea
|
||||||
|
value={authHeroDescription}
|
||||||
|
maxLength={160}
|
||||||
|
showCount
|
||||||
|
autoSize={{ minRows: 2, maxRows: 5 }}
|
||||||
|
placeholder="补充一句品牌介绍或产品定位"
|
||||||
|
onChange={(event) => setAuthHeroDescription(event.target.value)}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
<div className="admin-appearance-media-list">
|
||||||
|
<AssetPicker
|
||||||
|
slot="video"
|
||||||
|
title="品牌视频"
|
||||||
|
description="支持 MP4 或 WebM,最多 256MB;服务器运行时上传配额仍会同时生效。"
|
||||||
|
configured={Boolean(setting.authVideoResourceId) && !resets.video}
|
||||||
|
file={files.video}
|
||||||
|
inputRef={inputRefs.video}
|
||||||
|
onSelect={selectFile}
|
||||||
|
onReset={resetAsset}
|
||||||
|
disabled={saving || refreshing || restoring}
|
||||||
|
/>
|
||||||
|
<AssetPicker
|
||||||
|
slot="poster"
|
||||||
|
title="视频封面(可选)"
|
||||||
|
description="自定义视频未设置封面时保持中性背景,不显示原品牌封面。"
|
||||||
|
configured={Boolean(setting.authVideoPosterResourceId) && !resets.poster}
|
||||||
|
file={files.poster}
|
||||||
|
inputRef={inputRefs.poster}
|
||||||
|
onSelect={selectFile}
|
||||||
|
onReset={resetAsset}
|
||||||
|
disabled={saving || refreshing || restoring}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="admin-appearance-preview" aria-label="登录页实时预览">
|
||||||
|
<div className="admin-appearance-preview-heading">
|
||||||
|
<div>
|
||||||
|
<span>登录页实时预览</span>
|
||||||
|
<strong>{brandName.trim() || "未命名品牌"}</strong>
|
||||||
|
</div>
|
||||||
|
<AdminStatusBadge label={dirty ? "未保存" : "线上版本"} tone={dirty ? "warning" : "success"} />
|
||||||
|
</div>
|
||||||
|
<div className="admin-appearance-preview-stage">
|
||||||
|
<video key={previews.video} src={previews.video} poster={previews.poster || undefined} muted loop playsInline autoPlay preload="metadata" />
|
||||||
|
<span className="admin-appearance-preview-shade" />
|
||||||
|
<span className="admin-appearance-preview-brand">
|
||||||
|
<img src={previews.logoDark} alt="" />
|
||||||
|
<strong>{brandName.trim() || "未命名品牌"}</strong>
|
||||||
|
</span>
|
||||||
|
<span className="admin-appearance-preview-copy">
|
||||||
|
<small>{(brandSlug.trim() || "brand-studio").replace(/-+/g, " ").toLocaleUpperCase()}</small>
|
||||||
|
<strong>{normalizeDraftCopy(authHeroTitle) || "请输入登录页主标题"}</strong>
|
||||||
|
{normalizeDraftCopy(authHeroDescription) ? <span>{normalizeDraftCopy(authHeroDescription)}</span> : null}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<p>预览与正式登录页使用同一文案和媒体。正式页面会先解析公开配置,再渲染品牌内容。</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</SettingsSectionCard>
|
||||||
|
|
||||||
|
<SettingsSectionCard
|
||||||
|
className="admin-appearance-section"
|
||||||
|
icon={<Type className="size-4" aria-hidden="true" />}
|
||||||
|
title="3. 皮肤方案"
|
||||||
|
description="当前版本先统一使用经典皮肤;后续颜色、字体、圆角和组件密度会作为独立皮肤包管理。"
|
||||||
|
status={<AdminStatusBadge label="经典皮肤" tone="info" />}
|
||||||
|
>
|
||||||
|
<div className="admin-appearance-skin-note">
|
||||||
|
<span>当前皮肤</span>
|
||||||
|
<strong>{setting.skinId === "classic" ? "经典皮肤(Classic)" : setting.skinId}</strong>
|
||||||
|
<small>皮肤方案与品牌内容分离,后续切换皮肤时不会覆盖品牌名、英文标识、Logo、登录页文案或媒体。</small>
|
||||||
|
</div>
|
||||||
|
</SettingsSectionCard>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</AdminPageFrame>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function AssetPicker({
|
||||||
|
slot,
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
configured,
|
||||||
|
file,
|
||||||
|
inputRef,
|
||||||
|
onSelect,
|
||||||
|
onReset,
|
||||||
|
disabled,
|
||||||
|
emptyLabel,
|
||||||
|
}: {
|
||||||
|
slot: AppearanceAssetSlot;
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
configured: boolean;
|
||||||
|
file: File | null;
|
||||||
|
inputRef: RefObject<HTMLInputElement | null>;
|
||||||
|
onSelect: (slot: AppearanceAssetSlot, file?: File) => void;
|
||||||
|
onReset: (slot: AppearanceAssetSlot) => void;
|
||||||
|
disabled: boolean;
|
||||||
|
emptyLabel?: string;
|
||||||
|
}) {
|
||||||
|
const rule = FILE_RULES[slot];
|
||||||
|
return (
|
||||||
|
<div className="admin-appearance-asset-row">
|
||||||
|
<span className="admin-appearance-asset-icon">{slot === "video" ? <MonitorPlay /> : <ImageIcon />}</span>
|
||||||
|
<span className="admin-appearance-asset-copy">
|
||||||
|
<strong>{title}</strong>
|
||||||
|
<small>{description}</small>
|
||||||
|
<em>{file ? `${file.name} · ${formatBytes(file.size)}` : configured ? "已配置自定义文件" : emptyLabel || "使用项目原始文件"}</em>
|
||||||
|
</span>
|
||||||
|
<span className="admin-appearance-asset-actions">
|
||||||
|
<input ref={inputRef} type="file" accept={rule.accept} onChange={(event) => onSelect(slot, event.target.files?.[0])} />
|
||||||
|
<Button icon={<Upload className="size-3.5" />} disabled={disabled} onClick={() => inputRef.current?.click()}>
|
||||||
|
选择文件
|
||||||
|
</Button>
|
||||||
|
<Button type="text" danger={configured || Boolean(file)} disabled={disabled || (!configured && !file)} onClick={() => onReset(slot)}>
|
||||||
|
恢复原始
|
||||||
|
</Button>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function useAppearancePreviews(setting: AdminAppearance | null, files: DraftFiles, resets: ResetState) {
|
||||||
|
const logoObjectURL = useObjectURL(files.logo);
|
||||||
|
const darkLogoObjectURL = useObjectURL(files["logo-dark"]);
|
||||||
|
const videoObjectURL = useObjectURL(files.video);
|
||||||
|
const posterObjectURL = useObjectURL(files.poster);
|
||||||
|
return useMemo(() => {
|
||||||
|
if (!setting) return { logoLight: DEFAULT_PUBLIC_APPEARANCE.logoUrl, logoDark: DEFAULT_PUBLIC_APPEARANCE.darkLogoUrl, video: DEFAULT_PUBLIC_APPEARANCE.authVideoUrl, poster: DEFAULT_PUBLIC_APPEARANCE.authVideoPosterUrl };
|
||||||
|
const customVideo = Boolean(files.video || (!resets.video && setting.authVideoResourceId));
|
||||||
|
const lightLogo = logoObjectURL || (!resets.logo && setting.logoResourceId ? setting.public.logoUrl : "");
|
||||||
|
const darkLogo = darkLogoObjectURL || (!resets["logo-dark"] && setting.darkLogoResourceId ? setting.public.darkLogoUrl : "");
|
||||||
|
return {
|
||||||
|
logoLight: lightLogo || darkLogo || DEFAULT_PUBLIC_APPEARANCE.logoUrl,
|
||||||
|
logoDark: darkLogo || lightLogo || DEFAULT_PUBLIC_APPEARANCE.darkLogoUrl,
|
||||||
|
video: videoObjectURL || (resets.video ? DEFAULT_PUBLIC_APPEARANCE.authVideoUrl : setting.public.authVideoUrl),
|
||||||
|
poster: posterObjectURL || (resets.poster ? (customVideo ? "" : DEFAULT_PUBLIC_APPEARANCE.authVideoPosterUrl) : setting.public.authVideoPosterUrl),
|
||||||
|
};
|
||||||
|
}, [darkLogoObjectURL, files.video, logoObjectURL, posterObjectURL, resets, setting, videoObjectURL]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function LogoThemePreview({ label, icon, src, dark, frameEnabled }: { label: string; icon: ReactNode; src: string; dark: boolean; frameEnabled: boolean }) {
|
||||||
|
return (
|
||||||
|
<div className={cn("admin-appearance-logo-preview", dark ? "is-dark" : "is-light")}>
|
||||||
|
<span className={cn("admin-appearance-logo-preview-mark", !frameEnabled && "is-unframed")}>
|
||||||
|
<img src={src} alt="" />
|
||||||
|
</span>
|
||||||
|
<span className="admin-appearance-logo-preview-label">
|
||||||
|
{icon}
|
||||||
|
{label}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function useObjectURL(file: File | null) {
|
||||||
|
const url = useMemo(() => (file ? URL.createObjectURL(file) : ""), [file]);
|
||||||
|
useEffect(
|
||||||
|
() => () => {
|
||||||
|
if (url) URL.revokeObjectURL(url);
|
||||||
|
},
|
||||||
|
[url],
|
||||||
|
);
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
function AppearanceSkeleton() {
|
||||||
|
return (
|
||||||
|
<div className="admin-settings-stack admin-appearance-settings" aria-label="正在读取外观配置" role="status">
|
||||||
|
<div className="admin-appearance-command-bar">
|
||||||
|
<Skeleton active title={{ width: 190 }} paragraph={false} />
|
||||||
|
</div>
|
||||||
|
<div className="admin-appearance-loading-card">
|
||||||
|
<Skeleton active paragraph={{ rows: 8 }} />
|
||||||
|
</div>
|
||||||
|
<div className="admin-appearance-loading-card">
|
||||||
|
<Skeleton active paragraph={{ rows: 10 }} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeDraftCopy(value: string) {
|
||||||
|
return value.replace(/\r\n?/g, "\n").trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
function hasUnsupportedControlCharacter(value: string) {
|
||||||
|
return Array.from(value).some((character) => character !== "\n" && /[\u0000-\u001f\u007f]/.test(character));
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatBytes(bytes: number) {
|
||||||
|
if (bytes < 1024 * 1024) return `${Math.max(1, Math.round(bytes / 1024))}KB`;
|
||||||
|
return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import { useBlocker } from "react-router";
|
|||||||
import { changesRequireOSSRetest, DEFAULT_OSS_PATH_PREFIX, getS3PresetHints, normalizeOSSConnectionTestInput, S3_PRESET_OPTIONS, type OSSConnectionTestResult, type S3Preset } from "@/lib/oss-settings";
|
import { changesRequireOSSRetest, DEFAULT_OSS_PATH_PREFIX, getS3PresetHints, normalizeOSSConnectionTestInput, S3_PRESET_OPTIONS, type OSSConnectionTestResult, type S3Preset } from "@/lib/oss-settings";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { getAdminOSSSetting, testAdminOSSConnection, updateAdminOSSSetting, type AdminOSSSetting } from "@/services/api/auth";
|
import { getAdminOSSSetting, testAdminOSSConnection, updateAdminOSSSetting, type AdminOSSSetting } from "@/services/api/auth";
|
||||||
|
import { useAppearanceStore } from "@/stores/use-appearance-store";
|
||||||
import { AdminPageFrame } from "../components/admin-shell";
|
import { AdminPageFrame } from "../components/admin-shell";
|
||||||
import { AdminStatusBadge, configuredSecretText, SettingsSectionCard } from "../components/admin-ui";
|
import { AdminStatusBadge, configuredSecretText, SettingsSectionCard } from "../components/admin-ui";
|
||||||
|
|
||||||
@@ -38,6 +39,7 @@ const STORAGE_MODES: Array<{ mode: StorageMode; label: string; short: string; de
|
|||||||
|
|
||||||
export default function StorageSettingsPage() {
|
export default function StorageSettingsPage() {
|
||||||
const { message, modal } = App.useApp();
|
const { message, modal } = App.useApp();
|
||||||
|
const brandSlug = useAppearanceStore((state) => state.appearance.brandSlug);
|
||||||
const [setting, setSetting] = useState<AdminOSSSetting | null>(null);
|
const [setting, setSetting] = useState<AdminOSSSetting | null>(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [refreshing, setRefreshing] = useState(false);
|
const [refreshing, setRefreshing] = useState(false);
|
||||||
@@ -187,6 +189,15 @@ export default function StorageSettingsPage() {
|
|||||||
applyMode(nextMode);
|
applyMode(nextMode);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const useBrandPathPrefix = () => {
|
||||||
|
if (!setting || saving || refreshing) return;
|
||||||
|
const current = form.getFieldsValue(true);
|
||||||
|
form.setFieldValue("pathPrefix", brandSlug);
|
||||||
|
setDirty(hasStorageChanges({ ...current, pathPrefix: brandSlug }, setting));
|
||||||
|
setTestStale(true);
|
||||||
|
setSaveError("");
|
||||||
|
};
|
||||||
|
|
||||||
const save = async (values: OSSFormValues) => {
|
const save = async (values: OSSFormValues) => {
|
||||||
if (!setting) return;
|
if (!setting) return;
|
||||||
const expected = normalizeStoragePayload(values, setting);
|
const expected = normalizeStoragePayload(values, setting);
|
||||||
@@ -483,8 +494,15 @@ export default function StorageSettingsPage() {
|
|||||||
<Form.Item name="bucket" label="Bucket">
|
<Form.Item name="bucket" label="Bucket">
|
||||||
<Input autoComplete="off" placeholder={draftMode === "qiniu" ? "七牛云存储空间名称" : "对象存储 Bucket"} />
|
<Input autoComplete="off" placeholder={draftMode === "qiniu" ? "七牛云存储空间名称" : "对象存储 Bucket"} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="pathPrefix" label="路径前缀" extra="可留空;保存时自动去除首尾斜杠。">
|
<Form.Item label="路径前缀" extra={`可自行填写;也可采用外观管理中的英文品牌标识 ${brandSlug}。保存时自动去除首尾斜杠。`}>
|
||||||
<Input autoComplete="off" placeholder="例如:canvas" />
|
<div className="admin-storage-address-control">
|
||||||
|
<Form.Item name="pathPrefix" noStyle>
|
||||||
|
<Input autoComplete="off" placeholder={`例如:${brandSlug}`} />
|
||||||
|
</Form.Item>
|
||||||
|
<Button disabled={saving || refreshing || form.getFieldValue("pathPrefix") === brandSlug} onClick={useBrandPathPrefix}>
|
||||||
|
使用品牌标识
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import { exportAssets, readAssetPackage } from "./asset-transfer";
|
|||||||
import { AssetStorageUsage, assetStorageUsageQueryKey } from "./asset-storage-usage";
|
import { AssetStorageUsage, assetStorageUsageQueryKey } from "./asset-storage-usage";
|
||||||
import { deleteAssetWithRemoteSync, saveRemoteUserDataNow } from "@/services/user-data-sync";
|
import { deleteAssetWithRemoteSync, saveRemoteUserDataNow } from "@/services/user-data-sync";
|
||||||
import { useUserStore } from "@/stores/use-user-store";
|
import { useUserStore } from "@/stores/use-user-store";
|
||||||
|
import { useAppearanceStore } from "@/stores/use-appearance-store";
|
||||||
|
|
||||||
type LibraryAsset = Exclude<Asset, { kind: "entity" }>;
|
type LibraryAsset = Exclude<Asset, { kind: "entity" }>;
|
||||||
|
|
||||||
@@ -1058,6 +1059,7 @@ const assetsEmptyBannerFrames = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
function AssetsEmptyState({ onNew, onImport, onGoCanvas }: { onNew: () => void; onImport: () => void; onGoCanvas: () => void }) {
|
function AssetsEmptyState({ onNew, onImport, onGoCanvas }: { onNew: () => void; onImport: () => void; onGoCanvas: () => void }) {
|
||||||
|
const brandName = useAppearanceStore((state) => state.appearance.brandName);
|
||||||
return (
|
return (
|
||||||
<div className="assets-empty">
|
<div className="assets-empty">
|
||||||
<div className="assets-empty-banner" aria-hidden="true">
|
<div className="assets-empty-banner" aria-hidden="true">
|
||||||
@@ -1068,7 +1070,7 @@ function AssetsEmptyState({ onNew, onImport, onGoCanvas }: { onNew: () => void;
|
|||||||
</figure>
|
</figure>
|
||||||
))}
|
))}
|
||||||
<span className="assets-empty-banner-caption">
|
<span className="assets-empty-banner-caption">
|
||||||
<span>影策素材库</span>把每次创作的结果,留档成可复用的资产
|
<span>{brandName}素材库</span>把每次创作的结果,留档成可复用的资产
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="assets-empty-cards">
|
<div className="assets-empty-cards">
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ import { ConfigProvider, Tabs } from "antd";
|
|||||||
import { ArrowLeft, Play } from "lucide-react";
|
import { ArrowLeft, Play } from "lucide-react";
|
||||||
import { Link, Outlet, useLocation, useNavigate } from "react-router";
|
import { Link, Outlet, useLocation, useNavigate } from "react-router";
|
||||||
|
|
||||||
|
import { BrandLogo } from "@/components/brand/brand-logo";
|
||||||
import { aceternityMotion } from "@/lib/aceternity-motion";
|
import { aceternityMotion } from "@/lib/aceternity-motion";
|
||||||
import { getAntThemeConfig } from "@/lib/app-theme";
|
import { getAntThemeConfig } from "@/lib/app-theme";
|
||||||
|
import { brandStudioLabel, useAppearanceStore } from "@/stores/use-appearance-store";
|
||||||
|
|
||||||
const AUTH_VIDEO_URL = "https://boss-shjd.biliapi.net/updream/aniforge/video/video_bbcb00bd-650d-4249-9346-5cd21fd2484c_m1hc-u0-1pu13x-3v1s.mp4";
|
|
||||||
const AUTH_VIDEO_POSTER = "https://i0.hdslb.com/bfs/aitool/aniforge/image/02933f26-5f1b-49ff-a811-b7f95ee5e5b8_m1hc-u0-sau.jpg";
|
|
||||||
const AUTH_TABS = [
|
const AUTH_TABS = [
|
||||||
{ key: "login", label: "登录" },
|
{ key: "login", label: "登录" },
|
||||||
{ key: "register", label: "注册" },
|
{ key: "register", label: "注册" },
|
||||||
@@ -45,6 +45,7 @@ export function LinuxDOIcon() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function AuthScene() {
|
export function AuthScene() {
|
||||||
|
const appearance = useAppearanceStore((state) => state.appearance);
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const reducedMotion = useReducedMotion();
|
const reducedMotion = useReducedMotion();
|
||||||
@@ -55,14 +56,14 @@ export function AuthScene() {
|
|||||||
return (
|
return (
|
||||||
<main className="h-dvh min-h-0 overflow-y-auto bg-[#08090c] text-white lg:overflow-hidden">
|
<main className="h-dvh min-h-0 overflow-y-auto bg-[#08090c] text-white lg:overflow-hidden">
|
||||||
<div className="grid min-h-full lg:h-full lg:grid-cols-[minmax(0,1.32fr)_minmax(520px,1fr)]">
|
<div className="grid min-h-full lg:h-full lg:grid-cols-[minmax(0,1.32fr)_minmax(520px,1fr)]">
|
||||||
<section className="relative min-h-[250px] overflow-hidden sm:min-h-[320px] lg:min-h-0" aria-label="影策品牌影片">
|
<section className="relative min-h-[250px] overflow-hidden sm:min-h-[320px] lg:min-h-0" aria-label={`${appearance.brandName}品牌影片`}>
|
||||||
<video className="absolute inset-0 size-full object-cover" src={AUTH_VIDEO_URL} poster={AUTH_VIDEO_POSTER} autoPlay muted loop playsInline preload="metadata" />
|
<video className="absolute inset-0 size-full object-cover" src={appearance.authVideoUrl} poster={appearance.authVideoPosterUrl || undefined} autoPlay={!reducedMotion} muted loop playsInline preload="metadata" />
|
||||||
<div aria-hidden className="absolute inset-0 bg-[linear-gradient(180deg,rgba(4,5,8,.58),transparent_42%,rgba(4,5,8,.74))]" />
|
<div aria-hidden className="absolute inset-0 bg-[linear-gradient(180deg,rgba(4,5,8,.58),transparent_42%,rgba(4,5,8,.74))]" />
|
||||||
<div aria-hidden className="absolute inset-y-0 right-0 hidden w-[clamp(120px,14vw,240px)] bg-[linear-gradient(90deg,transparent_0%,rgba(11,12,16,.68)_58%,#0b0c10_100%)] lg:block" />
|
<div aria-hidden className="absolute inset-y-0 right-0 hidden w-[clamp(120px,14vw,240px)] bg-[linear-gradient(90deg,transparent_0%,rgba(11,12,16,.68)_58%,#0b0c10_100%)] lg:block" />
|
||||||
<div className="absolute inset-x-0 top-0 flex items-center justify-between gap-4 p-5 sm:p-7 lg:p-9">
|
<div className="absolute inset-x-0 top-0 flex items-center justify-between gap-4 p-5 sm:p-7 lg:p-9">
|
||||||
<Link to="/" className="inline-flex items-center gap-2.5 text-sm font-semibold text-white drop-shadow-sm transition-opacity hover:opacity-80">
|
<Link to="/" className="inline-flex items-center gap-2.5 text-sm font-semibold text-white drop-shadow-sm transition-opacity hover:opacity-80">
|
||||||
<span className="size-7 bg-current" style={{ mask: "url(/logo.svg) center / contain no-repeat", WebkitMask: "url(/logo.svg) center / contain no-repeat" }} />
|
<BrandLogo theme="dark" className="size-7" alt="" fallback={<span className="size-7 bg-current" style={{ mask: "url(/logo.svg) center / contain no-repeat", WebkitMask: "url(/logo.svg) center / contain no-repeat" }} />} />
|
||||||
影策
|
{appearance.brandName}
|
||||||
</Link>
|
</Link>
|
||||||
<span className="inline-flex items-center gap-2 rounded-full border border-white/16 bg-black/20 px-3 py-1.5 text-[var(--fs-label)] text-white/76 backdrop-blur-xl">
|
<span className="inline-flex items-center gap-2 rounded-full border border-white/16 bg-black/20 px-3 py-1.5 text-[var(--fs-label)] text-white/76 backdrop-blur-xl">
|
||||||
<Play className="size-3 fill-current" />
|
<Play className="size-3 fill-current" />
|
||||||
@@ -75,12 +76,9 @@ export function AuthScene() {
|
|||||||
transition={{ duration: aceternityMotion.duration.panel, ease: aceternityMotion.easing.enter }}
|
transition={{ duration: aceternityMotion.duration.panel, ease: aceternityMotion.easing.enter }}
|
||||||
className="absolute inset-x-0 bottom-0 max-w-2xl p-5 sm:p-7 lg:p-10"
|
className="absolute inset-x-0 bottom-0 max-w-2xl p-5 sm:p-7 lg:p-10"
|
||||||
>
|
>
|
||||||
<p className="text-xs font-semibold tracking-[0.18em] text-white/58">YINGCE STUDIO</p>
|
<p className="text-xs font-semibold tracking-[0.18em] text-white/58">{brandStudioLabel(appearance)}</p>
|
||||||
<h1 className="mt-3 max-w-xl text-3xl font-semibold leading-tight sm:text-4xl lg:text-5xl">
|
<h1 className="mt-3 max-w-xl whitespace-pre-line text-3xl font-semibold leading-tight sm:text-4xl lg:text-5xl">{appearance.authHeroTitle}</h1>
|
||||||
让一个故事,
|
{appearance.authHeroDescription ? <p className="mt-4 max-w-xl whitespace-pre-line text-sm leading-6 text-white/62 sm:text-base sm:leading-7">{appearance.authHeroDescription}</p> : null}
|
||||||
<br className="hidden sm:inline" />
|
|
||||||
从文字走向银幕。
|
|
||||||
</h1>
|
|
||||||
</motion.div>
|
</motion.div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ import { loadCreationConversations, pendingCreationTaskIds, pendingCreationTaskK
|
|||||||
import { recoverCreationTextTask } from "@/services/creation-text-task-recovery";
|
import { recoverCreationTextTask } from "@/services/creation-text-task-recovery";
|
||||||
import { modelDisplayName, modelOptionName, resolveModelChannel, selectableModelsByCapability, useConfigStore, useEffectiveConfig } from "@/stores/use-config-store";
|
import { modelDisplayName, modelOptionName, resolveModelChannel, selectableModelsByCapability, useConfigStore, useEffectiveConfig } from "@/stores/use-config-store";
|
||||||
import { useAssetStore, type Asset } from "@/stores/use-asset-store";
|
import { useAssetStore, type Asset } from "@/stores/use-asset-store";
|
||||||
|
import { useAppearanceStore } from "@/stores/use-appearance-store";
|
||||||
import { useUserStore } from "@/stores/use-user-store";
|
import { useUserStore } from "@/stores/use-user-store";
|
||||||
import type { PromptOptimizerProvider } from "@/lib/plugins/plugin-types";
|
import type { PromptOptimizerProvider } from "@/lib/plugins/plugin-types";
|
||||||
import { promptOptimizerPlugin, PROMPT_OPTIMIZER_PLUGIN_ID } from "@/lib/plugins/builtin/prompt-optimizer";
|
import { promptOptimizerPlugin, PROMPT_OPTIMIZER_PLUGIN_ID } from "@/lib/plugins/builtin/prompt-optimizer";
|
||||||
@@ -135,6 +136,7 @@ function completedCreationGenerationTask(input: { taskId: string; task?: Generat
|
|||||||
|
|
||||||
export default function CreatePage() {
|
export default function CreatePage() {
|
||||||
const { message: toast, modal } = App.useApp();
|
const { message: toast, modal } = App.useApp();
|
||||||
|
const brandName = useAppearanceStore((state) => state.appearance.brandName);
|
||||||
const config = useEffectiveConfig();
|
const config = useEffectiveConfig();
|
||||||
const promptOptimizerInstallation = usePluginStore((state) => state.installations.find((item) => item.manifest.id === PROMPT_OPTIMIZER_PLUGIN_ID));
|
const promptOptimizerInstallation = usePluginStore((state) => state.installations.find((item) => item.manifest.id === PROMPT_OPTIMIZER_PLUGIN_ID));
|
||||||
const promptOptimizerEnabled = usePluginStore((state) => state.pluginStates[PROMPT_OPTIMIZER_PLUGIN_ID]?.effectiveEnabled ?? Boolean(state.installations.find((item) => item.manifest.id === PROMPT_OPTIMIZER_PLUGIN_ID)?.enabled));
|
const promptOptimizerEnabled = usePluginStore((state) => state.pluginStates[PROMPT_OPTIMIZER_PLUGIN_ID]?.effectiveEnabled ?? Boolean(state.installations.find((item) => item.manifest.id === PROMPT_OPTIMIZER_PLUGIN_ID)?.enabled));
|
||||||
@@ -902,8 +904,8 @@ export default function CreatePage() {
|
|||||||
<CreationEmptyBanner />
|
<CreationEmptyBanner />
|
||||||
<div className="creation-chat-intro">
|
<div className="creation-chat-intro">
|
||||||
<span className="creation-intro-signal" aria-hidden="true" />
|
<span className="creation-intro-signal" aria-hidden="true" />
|
||||||
<p>影策 · AI 影视创作工作台</p>
|
<p>{brandName} · AI 影视创作工作台</p>
|
||||||
<h1>把脑海里的画面,<span className="creation-intro-emphasis"><span className="is-pink">交给影策</span><span className="is-blue">拍出来</span></span></h1>
|
<h1>把脑海里的画面,<span className="creation-intro-emphasis"><span className="is-pink">交给{brandName}</span><span className="is-blue">拍出来</span></span></h1>
|
||||||
</div>
|
</div>
|
||||||
<div className="creation-empty-composer">
|
<div className="creation-empty-composer">
|
||||||
<CreationComposer {...composerProps} variant="empty" />
|
<CreationComposer {...composerProps} variant="empty" />
|
||||||
@@ -1035,10 +1037,11 @@ function CreationWorkspaceToolbar({ viewMode, onViewModeChange, onNewConversatio
|
|||||||
}
|
}
|
||||||
|
|
||||||
function CreationMessageView({ item, modelName, onRetryFailure, onCreateVariant }: { item: CreationMessage; modelName: string; onRetryFailure: () => void; onCreateVariant: () => void }) {
|
function CreationMessageView({ item, modelName, onRetryFailure, onCreateVariant }: { item: CreationMessage; modelName: string; onRetryFailure: () => void; onCreateVariant: () => void }) {
|
||||||
|
const brandName = useAppearanceStore((state) => state.appearance.brandName);
|
||||||
if (item.role === "user") return <CreationUserMessage item={item} />;
|
if (item.role === "user") return <CreationUserMessage item={item} />;
|
||||||
const mode = item.mode || "text";
|
const mode = item.mode || "text";
|
||||||
const stateLabel = item.status === "pending" ? "生成中" : item.status === "cancelled" ? "已停止" : item.status === "error" ? "生成失败" : "";
|
const stateLabel = item.status === "pending" ? "生成中" : item.status === "cancelled" ? "已停止" : item.status === "error" ? "生成失败" : "";
|
||||||
const heading = <><span className="creation-message-mark"><Sparkles /></span><strong>{mode === "image" ? "图像生成" : mode === "video" ? "视频生成" : "影策 AI"}</strong>{mode !== "text" ? <span className="creation-message-progress-copy">{item.status === "pending" ? `影策正在生成${mode === "video" ? "视频" : "图像"}……` : item.status === "done" ? `你的${mode === "video" ? "视频" : "图像"}已创建` : null}</span> : null}{modelName ? <span className="creation-message-model">{modelName}</span> : null}{item.createdAt ? <time dateTime={item.createdAt}>{formatMessageTime(item.createdAt)}</time> : null}{stateLabel ? <span className={`creation-message-state is-${item.status}`}>{stateLabel}</span> : null}</>;
|
const heading = <><span className="creation-message-mark"><Sparkles /></span><strong>{mode === "image" ? "图像生成" : mode === "video" ? "视频生成" : `${brandName} AI`}</strong>{mode !== "text" ? <span className="creation-message-progress-copy">{item.status === "pending" ? `${brandName}正在生成${mode === "video" ? "视频" : "图像"}……` : item.status === "done" ? `你的${mode === "video" ? "视频" : "图像"}已创建` : null}</span> : null}{modelName ? <span className="creation-message-model">{modelName}</span> : null}{item.createdAt ? <time dateTime={item.createdAt}>{formatMessageTime(item.createdAt)}</time> : null}{stateLabel ? <span className={`creation-message-state is-${item.status}`}>{stateLabel}</span> : null}</>;
|
||||||
const toolStatus: GenerationToolStatus = item.status === "pending" ? "running" : item.status === "error" ? "error" : item.status === "cancelled" ? "cancelled" : "completed";
|
const toolStatus: GenerationToolStatus = item.status === "pending" ? "running" : item.status === "error" ? "error" : item.status === "cancelled" ? "cancelled" : "completed";
|
||||||
return <article className={`creation-assistant-message is-${mode}`}>
|
return <article className={`creation-assistant-message is-${mode}`}>
|
||||||
{mode === "text" ? <><div className="creation-message-heading">{heading}</div>{item.reasoning ? <MessageReasoning reasoning={item.reasoning} isStreaming={item.status === "streaming"} /> : null}<div className="creation-message-content">{item.content ? <AIMessageMarkdown isStreaming={item.status === "streaming"}>{item.content}</AIMessageMarkdown> : <span>正在生成…</span>}</div></> : <GenerationToolCard status={toolStatus} isBulk={(item.resultUrls?.length || Number(item.settings?.count) || 1) > 1} heading={heading}><MediaResult item={item} onRetryFailure={onRetryFailure} onCreateVariant={onCreateVariant} /></GenerationToolCard>}
|
{mode === "text" ? <><div className="creation-message-heading">{heading}</div>{item.reasoning ? <MessageReasoning reasoning={item.reasoning} isStreaming={item.status === "streaming"} /> : null}<div className="creation-message-content">{item.content ? <AIMessageMarkdown isStreaming={item.status === "streaming"}>{item.content}</AIMessageMarkdown> : <span>正在生成…</span>}</div></> : <GenerationToolCard status={toolStatus} isBulk={(item.resultUrls?.length || Number(item.settings?.count) || 1) > 1} heading={heading}><MediaResult item={item} onRetryFailure={onRetryFailure} onCreateVariant={onCreateVariant} /></GenerationToolCard>}
|
||||||
@@ -1086,7 +1089,8 @@ function MediaResult({ item, onRetryFailure, onCreateVariant }: { item: Creation
|
|||||||
}
|
}
|
||||||
|
|
||||||
function CreationMediaPending({ mode, ratio }: { mode: CreationMode; ratio?: string }) {
|
function CreationMediaPending({ mode, ratio }: { mode: CreationMode; ratio?: string }) {
|
||||||
return <div className={`creation-media-pending is-${mode}`} style={{ aspectRatio: creationMediaAspectRatio(ratio, mode) }} aria-live="polite"><span className="creation-media-pending-icon"><Sparkles /></span><span className="sr-only">影策正在生成{mode === "video" ? "视频" : "图像"}</span></div>;
|
const brandName = useAppearanceStore((state) => state.appearance.brandName);
|
||||||
|
return <div className={`creation-media-pending is-${mode}`} style={{ aspectRatio: creationMediaAspectRatio(ratio, mode) }} aria-live="polite"><span className="creation-media-pending-icon"><Sparkles /></span><span className="sr-only">{brandName}正在生成{mode === "video" ? "视频" : "图像"}</span></div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
function CreationMessageReferences({ references }: { references: CreationReference[] }) {
|
function CreationMessageReferences({ references }: { references: CreationReference[] }) {
|
||||||
@@ -1533,12 +1537,13 @@ const creationEmptyBannerFrames = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
function CreationEmptyBanner() {
|
function CreationEmptyBanner() {
|
||||||
|
const brandName = useAppearanceStore((state) => state.appearance.brandName);
|
||||||
return <div className="creation-empty-art" aria-hidden="true">
|
return <div className="creation-empty-art" aria-hidden="true">
|
||||||
{creationEmptyBannerFrames.map((frame, index) => <figure key={frame.caption} className={`creation-empty-art-frame ${index === 1 ? "is-main" : index === 0 ? "is-back" : "is-front"}`}>
|
{creationEmptyBannerFrames.map((frame, index) => <figure key={frame.caption} className={`creation-empty-art-frame ${index === 1 ? "is-main" : index === 0 ? "is-back" : "is-front"}`}>
|
||||||
<img src={frame.src} alt="" />
|
<img src={frame.src} alt="" />
|
||||||
<span>{frame.caption}</span>
|
<span>{frame.caption}</span>
|
||||||
</figure>)}
|
</figure>)}
|
||||||
<span className="creation-empty-art-caption"><span>影策</span>把每一帧,交给镜头导演</span>
|
<span className="creation-empty-art-caption"><span>{brandName}</span>把每一帧,交给镜头导演</span>
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1563,10 +1568,10 @@ function CreationEmptySuggest({ onStartPrompt, onOpenLibrary }: { onStartPrompt:
|
|||||||
|
|
||||||
type CreationThinking = { title: string; hint: string; steps: string[] };
|
type CreationThinking = { title: string; hint: string; steps: string[] };
|
||||||
|
|
||||||
function thinkingFor(mode: CreationMode): CreationThinking {
|
function thinkingFor(mode: CreationMode, brandName: string): CreationThinking {
|
||||||
if (mode === "image") return { title: "正在为你画这一镜", hint: "影策正在理解你的构图意图,并把画面交给模型出图。", steps: ["理解构图", "定调画风", "生成画面"] };
|
if (mode === "image") return { title: "正在为你画这一镜", hint: `${brandName}正在理解你的构图意图,并把画面交给模型出图。`, steps: ["理解构图", "定调画风", "生成画面"] };
|
||||||
if (mode === "text") return { title: "正在为你写这段", hint: "影策正在梳理你的创作脉络,组织语言与结构。", steps: ["梳理脉络", "组织语言", "输出段落"] };
|
if (mode === "text") return { title: "正在为你写这段", hint: `${brandName}正在梳理你的创作脉络,组织语言与结构。`, steps: ["梳理脉络", "组织语言", "输出段落"] };
|
||||||
return { title: "正在为你拍这一镜", hint: "影策正在拆解你的镜头脚本,设计运镜与光线,并交给模型渲染成片。", steps: ["拆解镜头", "设计运镜", "定调布光", "渲染成片"] };
|
return { title: "正在为你拍这一镜", hint: `${brandName}正在拆解你的镜头脚本,设计运镜与光线,并交给模型渲染成片。`, steps: ["拆解镜头", "设计运镜", "定调布光", "渲染成片"] };
|
||||||
}
|
}
|
||||||
|
|
||||||
function directorNoteFor(mode: CreationMode, settings: CreationSettings): string {
|
function directorNoteFor(mode: CreationMode, settings: CreationSettings): string {
|
||||||
@@ -1617,6 +1622,7 @@ function StoryboardToolbar({ shots, activeIndex, composing, onSelect, onBeginCom
|
|||||||
}
|
}
|
||||||
|
|
||||||
function StoryboardShotCard({ shot, shotNumber, modelName, busy, onRetryFailure, onCreateVariant }: { shot: CreationShot; shotNumber: number; modelName: string; busy: boolean; onRetryFailure: () => void; onCreateVariant: () => void }) {
|
function StoryboardShotCard({ shot, shotNumber, modelName, busy, onRetryFailure, onCreateVariant }: { shot: CreationShot; shotNumber: number; modelName: string; busy: boolean; onRetryFailure: () => void; onCreateVariant: () => void }) {
|
||||||
|
const brandName = useAppearanceStore((state) => state.appearance.brandName);
|
||||||
const user = shot.user;
|
const user = shot.user;
|
||||||
const result = shot.result;
|
const result = shot.result;
|
||||||
const status = result?.status || "queued";
|
const status = result?.status || "queued";
|
||||||
@@ -1656,11 +1662,11 @@ function StoryboardShotCard({ shot, shotNumber, modelName, busy, onRetryFailure,
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div> : null}
|
</div> : null}
|
||||||
{briefVisible && user ? <div className="storyboard-workbench-handoff" aria-hidden="true"><span className="storyboard-workbench-handoff-rail" /><span className="storyboard-workbench-handoff-badge"><ArrowDown />交给影策 AI</span><span className="storyboard-workbench-handoff-rail" /></div> : null}
|
{briefVisible && user ? <div className="storyboard-workbench-handoff" aria-hidden="true"><span className="storyboard-workbench-handoff-rail" /><span className="storyboard-workbench-handoff-badge"><ArrowDown />交给{brandName} AI</span><span className="storyboard-workbench-handoff-rail" /></div> : null}
|
||||||
<div className="storyboard-workbench-turn is-ai">
|
<div className="storyboard-workbench-turn is-ai">
|
||||||
<span className="storyboard-workbench-ai-avatar"><Clapperboard /></span>
|
<span className="storyboard-workbench-ai-avatar"><Clapperboard /></span>
|
||||||
<div className="storyboard-workbench-turn-copy">
|
<div className="storyboard-workbench-turn-copy">
|
||||||
<div className="storyboard-workbench-turn-meta"><span className="storyboard-workbench-turn-role is-ai"><Sparkles />影策 AI</span>{modelName ? <span className="storyboard-workbench-turn-model">{modelName}</span> : null}{result?.createdAt ? <time className="storyboard-workbench-turn-time" dateTime={result.createdAt}>{formatMessageTime(result.createdAt)}</time> : null}</div>
|
<div className="storyboard-workbench-turn-meta"><span className="storyboard-workbench-turn-role is-ai"><Sparkles />{brandName} AI</span>{modelName ? <span className="storyboard-workbench-turn-model">{modelName}</span> : null}{result?.createdAt ? <time className="storyboard-workbench-turn-time" dateTime={result.createdAt}>{formatMessageTime(result.createdAt)}</time> : null}</div>
|
||||||
<div className="storyboard-workbench-turn-bubble">
|
<div className="storyboard-workbench-turn-bubble">
|
||||||
<StoryboardShotResult result={result} onRetryFailure={onRetryFailure} onCreateVariant={onCreateVariant} canvasPath={canvasPath} canvasHandoffAvailable={Boolean(canvasHandoffPath)} />
|
<StoryboardShotResult result={result} onRetryFailure={onRetryFailure} onCreateVariant={onCreateVariant} canvasPath={canvasPath} canvasHandoffAvailable={Boolean(canvasHandoffPath)} />
|
||||||
</div>
|
</div>
|
||||||
@@ -1672,6 +1678,7 @@ function StoryboardShotCard({ shot, shotNumber, modelName, busy, onRetryFailure,
|
|||||||
}
|
}
|
||||||
|
|
||||||
function StoryboardNextShotCard({ shotNumber, onCancel }: { shotNumber: number; onCancel: () => void }) {
|
function StoryboardNextShotCard({ shotNumber, onCancel }: { shotNumber: number; onCancel: () => void }) {
|
||||||
|
const brandName = useAppearanceStore((state) => state.appearance.brandName);
|
||||||
return <article className="storyboard-workbench-card is-next">
|
return <article className="storyboard-workbench-card is-next">
|
||||||
<header className="storyboard-workbench-card-head">
|
<header className="storyboard-workbench-card-head">
|
||||||
<div className="storyboard-workbench-card-heading">
|
<div className="storyboard-workbench-card-heading">
|
||||||
@@ -1687,7 +1694,7 @@ function StoryboardNextShotCard({ shotNumber, onCancel }: { shotNumber: number;
|
|||||||
<span className="storyboard-workbench-next-panel-icon"><Clapperboard /></span>
|
<span className="storyboard-workbench-next-panel-icon"><Clapperboard /></span>
|
||||||
<div className="storyboard-workbench-next-panel-copy">
|
<div className="storyboard-workbench-next-panel-copy">
|
||||||
<strong>{formatShotOrdinal(shotNumber - 1)} 等待你的脚本</strong>
|
<strong>{formatShotOrdinal(shotNumber - 1)} 等待你的脚本</strong>
|
||||||
<span>在下方写下这一镜的镜头、画面或故事。影策会拆解脚本、设计运镜并渲染成片,这一镜会作为 {formatShotOrdinal(shotNumber - 1)} 自动加入镜头轨道。</span>
|
<span>在下方写下这一镜的镜头、画面或故事。{brandName}会拆解脚本、设计运镜并渲染成片,这一镜会作为 {formatShotOrdinal(shotNumber - 1)} 自动加入镜头轨道。</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -1707,6 +1714,7 @@ function StoryboardBriefAttachments({ attachments }: { attachments: CreationAtta
|
|||||||
}
|
}
|
||||||
|
|
||||||
function StoryboardShotResult({ result, onRetryFailure, onCreateVariant, canvasPath, canvasHandoffAvailable }: { result?: CreationMessage; onRetryFailure: () => void; onCreateVariant: () => void; canvasPath: string; canvasHandoffAvailable: boolean }) {
|
function StoryboardShotResult({ result, onRetryFailure, onCreateVariant, canvasPath, canvasHandoffAvailable }: { result?: CreationMessage; onRetryFailure: () => void; onCreateVariant: () => void; canvasPath: string; canvasHandoffAvailable: boolean }) {
|
||||||
|
const brandName = useAppearanceStore((state) => state.appearance.brandName);
|
||||||
const [previewUrl, setPreviewUrl] = useState("");
|
const [previewUrl, setPreviewUrl] = useState("");
|
||||||
const [previewType, setPreviewType] = useState<"image" | "video">("image");
|
const [previewType, setPreviewType] = useState<"image" | "video">("image");
|
||||||
const openPreview = (url: string, type: "image" | "video") => { setPreviewType(type); setPreviewUrl(url); };
|
const openPreview = (url: string, type: "image" | "video") => { setPreviewType(type); setPreviewUrl(url); };
|
||||||
@@ -1715,7 +1723,7 @@ function StoryboardShotResult({ result, onRetryFailure, onCreateVariant, canvasP
|
|||||||
const status = result.status || "queued";
|
const status = result.status || "queued";
|
||||||
const resultUrls = result.resultUrls || [];
|
const resultUrls = result.resultUrls || [];
|
||||||
if (status === "pending" || status === "queued") {
|
if (status === "pending" || status === "queued") {
|
||||||
const thinking = thinkingFor(mode);
|
const thinking = thinkingFor(mode, brandName);
|
||||||
return <div className="storyboard-workbench-pending"><div className="storyboard-workbench-thinking">
|
return <div className="storyboard-workbench-pending"><div className="storyboard-workbench-thinking">
|
||||||
<span className="storyboard-workbench-thinking-copy"><strong>{thinking.title}</strong><span>{thinking.hint}</span></span>
|
<span className="storyboard-workbench-thinking-copy"><strong>{thinking.title}</strong><span>{thinking.hint}</span></span>
|
||||||
<span className="storyboard-workbench-pipeline" aria-hidden="true">{thinking.steps.map((step, index) => <em key={step} style={{ "--step": index } as CSSProperties}><i>{String(index + 1).padStart(2, "0")}</i>{step}</em>)}</span>
|
<span className="storyboard-workbench-pipeline" aria-hidden="true">{thinking.steps.map((step, index) => <em key={step} style={{ "--step": index } as CSSProperties}><i>{String(index + 1).padStart(2, "0")}</i>{step}</em>)}</span>
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ const AdminPaymentsPage = lazy(() => import("@/pages/admin/payments/payments-pag
|
|||||||
const LogsPage = lazy(() => import("@/pages/admin/logs/logs-page"));
|
const LogsPage = lazy(() => import("@/pages/admin/logs/logs-page"));
|
||||||
const RedemptionCodesPage = lazy(() => import("@/pages/admin/redemption-codes/redemption-codes-page"));
|
const RedemptionCodesPage = lazy(() => import("@/pages/admin/redemption-codes/redemption-codes-page"));
|
||||||
const RuntimePolicySettingsPage = lazy(() => import("@/pages/admin/settings/runtime-policy-settings-page"));
|
const RuntimePolicySettingsPage = lazy(() => import("@/pages/admin/settings/runtime-policy-settings-page"));
|
||||||
|
const AppearanceSettingsPage = lazy(() => import("@/pages/admin/settings/appearance-settings-page"));
|
||||||
const DrawingEngineSettingsPage = lazy(() => import("@/pages/admin/settings/drawing-engine-settings-page"));
|
const DrawingEngineSettingsPage = lazy(() => import("@/pages/admin/settings/drawing-engine-settings-page"));
|
||||||
const StorageSettingsPage = lazy(() => import("@/pages/admin/settings/storage-settings-page"));
|
const StorageSettingsPage = lazy(() => import("@/pages/admin/settings/storage-settings-page"));
|
||||||
const ArkPrivateAssetsSettingsPage = lazy(() => import("@/pages/admin/settings/ark-private-assets-settings-page"));
|
const ArkPrivateAssetsSettingsPage = lazy(() => import("@/pages/admin/settings/ark-private-assets-settings-page"));
|
||||||
@@ -194,6 +195,7 @@ export const router = createBrowserRouter([
|
|||||||
{ path: "redemption-codes", element: deferred(<RedemptionCodesPage />) },
|
{ path: "redemption-codes", element: deferred(<RedemptionCodesPage />) },
|
||||||
{ path: "logs", element: deferred(<LogsPage />) },
|
{ path: "logs", element: deferred(<LogsPage />) },
|
||||||
{ path: "settings", element: <Navigate to="runtime-policy" replace /> },
|
{ path: "settings", element: <Navigate to="runtime-policy" replace /> },
|
||||||
|
{ path: "settings/appearance", element: deferred(<AppearanceSettingsPage />) },
|
||||||
{ path: "settings/drawing-engine", element: deferred(<DrawingEngineSettingsPage />) },
|
{ path: "settings/drawing-engine", element: deferred(<DrawingEngineSettingsPage />) },
|
||||||
{ path: "settings/concurrency", element: <Navigate to="/admin/settings/runtime-policy" replace /> },
|
{ path: "settings/concurrency", element: <Navigate to="/admin/settings/runtime-policy" replace /> },
|
||||||
{ path: "settings/runtime-policy", element: deferred(<RuntimePolicySettingsPage />) },
|
{ path: "settings/runtime-policy", element: deferred(<RuntimePolicySettingsPage />) },
|
||||||
|
|||||||
@@ -0,0 +1,80 @@
|
|||||||
|
import { apiClient, request } from "@/services/api/request";
|
||||||
|
|
||||||
|
export type PublicAppearance = {
|
||||||
|
schemaVersion: number;
|
||||||
|
brandName: string;
|
||||||
|
brandSlug: string;
|
||||||
|
authHeroTitle: string;
|
||||||
|
authHeroDescription: string;
|
||||||
|
logoUrl: string;
|
||||||
|
darkLogoUrl: string;
|
||||||
|
logoFrameEnabled: boolean;
|
||||||
|
authVideoUrl: string;
|
||||||
|
authVideoPosterUrl: string;
|
||||||
|
skinId: string;
|
||||||
|
logoConfigured: boolean;
|
||||||
|
darkLogoConfigured: boolean;
|
||||||
|
authVideoConfigured: boolean;
|
||||||
|
authVideoPosterConfigured: boolean;
|
||||||
|
configured: boolean;
|
||||||
|
revision: string;
|
||||||
|
updatedAt?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type AdminAppearance = {
|
||||||
|
schemaVersion: number;
|
||||||
|
brandName: string;
|
||||||
|
brandSlug: string;
|
||||||
|
authHeroTitle: string;
|
||||||
|
authHeroDescription: string;
|
||||||
|
logoResourceId: string;
|
||||||
|
darkLogoResourceId: string;
|
||||||
|
logoFrameEnabled: boolean;
|
||||||
|
authVideoResourceId: string;
|
||||||
|
authVideoPosterResourceId: string;
|
||||||
|
skinId: string;
|
||||||
|
public: PublicAppearance;
|
||||||
|
configured: boolean;
|
||||||
|
updatedBy?: string;
|
||||||
|
createdAt?: string;
|
||||||
|
updatedAt?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type AppearanceAssetSlot = "logo" | "logo-dark" | "video" | "poster";
|
||||||
|
|
||||||
|
export type AppearanceResource = {
|
||||||
|
id: string;
|
||||||
|
kind: string;
|
||||||
|
status: string;
|
||||||
|
mimeType: string;
|
||||||
|
size: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function getPublicAppearance(signal?: AbortSignal) {
|
||||||
|
const result = await request<{ appearance: PublicAppearance }>(apiClient.get("/public/appearance", { signal }));
|
||||||
|
return result.appearance;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getAdminAppearance(signal?: AbortSignal) {
|
||||||
|
const result = await request<{ setting: AdminAppearance }>(apiClient.get("/admin/settings/appearance", { signal }));
|
||||||
|
return result.setting;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateAdminAppearance(
|
||||||
|
input: Pick<AdminAppearance, "brandName" | "brandSlug" | "authHeroTitle" | "authHeroDescription" | "logoResourceId" | "darkLogoResourceId" | "logoFrameEnabled" | "authVideoResourceId" | "authVideoPosterResourceId" | "skinId">,
|
||||||
|
) {
|
||||||
|
const result = await request<{ setting: AdminAppearance }>(apiClient.patch("/admin/settings/appearance", input));
|
||||||
|
return result.setting;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function resetAdminAppearance() {
|
||||||
|
const result = await request<{ setting: AdminAppearance }>(apiClient.delete("/admin/settings/appearance"));
|
||||||
|
return result.setting;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function uploadAppearanceAsset(slot: AppearanceAssetSlot, file: File) {
|
||||||
|
const body = new FormData();
|
||||||
|
body.append("file", file);
|
||||||
|
const result = await request<{ resource: AppearanceResource }>(apiClient.post(`/admin/settings/appearance/assets/${slot}`, body));
|
||||||
|
return result.resource;
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import { getPublicAppearance, type PublicAppearance } from "@/services/api/appearance";
|
||||||
|
import { commitPublicAppearance, DEFAULT_PUBLIC_APPEARANCE } from "@/stores/use-appearance-store";
|
||||||
|
|
||||||
|
const APPEARANCE_BOOTSTRAP_TIMEOUT_MS = 4_000;
|
||||||
|
|
||||||
|
export async function resolvePublicAppearance(fetchAppearance: (signal: AbortSignal) => Promise<PublicAppearance> = getPublicAppearance) {
|
||||||
|
const controller = new AbortController();
|
||||||
|
const timer = setTimeout(() => controller.abort(), APPEARANCE_BOOTSTRAP_TIMEOUT_MS);
|
||||||
|
try {
|
||||||
|
return await fetchAppearance(controller.signal);
|
||||||
|
} catch {
|
||||||
|
return DEFAULT_PUBLIC_APPEARANCE;
|
||||||
|
} finally {
|
||||||
|
clearTimeout(timer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function bootstrapAppearance(fetchAppearance?: (signal: AbortSignal) => Promise<PublicAppearance>) {
|
||||||
|
return commitPublicAppearance(await resolvePublicAppearance(fetchAppearance));
|
||||||
|
}
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
import { create } from "zustand";
|
||||||
|
|
||||||
|
import type { PublicAppearance } from "@/services/api/appearance";
|
||||||
|
|
||||||
|
export const DEFAULT_PUBLIC_APPEARANCE: PublicAppearance = {
|
||||||
|
schemaVersion: 3,
|
||||||
|
brandName: "影策",
|
||||||
|
brandSlug: "open-ai-canvas",
|
||||||
|
authHeroTitle: "让一个故事,\n从文字走向银幕。",
|
||||||
|
authHeroDescription: "",
|
||||||
|
logoUrl: "/logo.svg",
|
||||||
|
darkLogoUrl: "/logo.svg",
|
||||||
|
logoFrameEnabled: true,
|
||||||
|
authVideoUrl: "https://boss-shjd.biliapi.net/updream/aniforge/video/video_bbcb00bd-650d-4249-9346-5cd21fd2484c_m1hc-u0-1pu13x-3v1s.mp4",
|
||||||
|
authVideoPosterUrl: "https://i0.hdslb.com/bfs/aitool/aniforge/image/02933f26-5f1b-49ff-a811-b7f95ee5e5b8_m1hc-u0-sau.jpg",
|
||||||
|
skinId: "classic",
|
||||||
|
logoConfigured: false,
|
||||||
|
darkLogoConfigured: false,
|
||||||
|
authVideoConfigured: false,
|
||||||
|
authVideoPosterConfigured: false,
|
||||||
|
configured: false,
|
||||||
|
revision: "builtin",
|
||||||
|
};
|
||||||
|
|
||||||
|
type AppearanceStore = {
|
||||||
|
appearance: PublicAppearance;
|
||||||
|
resolved: boolean;
|
||||||
|
setAppearance: (appearance: PublicAppearance) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useAppearanceStore = create<AppearanceStore>((set) => ({
|
||||||
|
appearance: DEFAULT_PUBLIC_APPEARANCE,
|
||||||
|
resolved: false,
|
||||||
|
setAppearance: (appearance) => set({ appearance, resolved: true }),
|
||||||
|
}));
|
||||||
|
|
||||||
|
export function normalizePublicAppearance(value?: Partial<PublicAppearance> | null): PublicAppearance {
|
||||||
|
const brandName = String(value?.brandName || "").trim();
|
||||||
|
const brandSlug = normalizeBrandSlug(value?.brandSlug);
|
||||||
|
const authHeroTitle = normalizeAppearanceCopy(value?.authHeroTitle, DEFAULT_PUBLIC_APPEARANCE.authHeroTitle);
|
||||||
|
const authHeroDescription = normalizeAppearanceCopy(value?.authHeroDescription, DEFAULT_PUBLIC_APPEARANCE.authHeroDescription, true);
|
||||||
|
const customVideo = Boolean(value?.authVideoConfigured);
|
||||||
|
const logoUrl = safeAppearanceURL(value?.logoUrl, DEFAULT_PUBLIC_APPEARANCE.logoUrl);
|
||||||
|
const darkLogoUrl = safeAppearanceURL(value?.darkLogoUrl, logoUrl);
|
||||||
|
return {
|
||||||
|
...DEFAULT_PUBLIC_APPEARANCE,
|
||||||
|
...value,
|
||||||
|
schemaVersion: 3,
|
||||||
|
brandName: brandName || DEFAULT_PUBLIC_APPEARANCE.brandName,
|
||||||
|
brandSlug,
|
||||||
|
authHeroTitle,
|
||||||
|
authHeroDescription,
|
||||||
|
logoUrl,
|
||||||
|
darkLogoUrl,
|
||||||
|
logoFrameEnabled: value?.logoFrameEnabled !== false,
|
||||||
|
authVideoUrl: safeAppearanceURL(value?.authVideoUrl, DEFAULT_PUBLIC_APPEARANCE.authVideoUrl),
|
||||||
|
authVideoPosterUrl: safeAppearanceURL(value?.authVideoPosterUrl, customVideo ? "" : DEFAULT_PUBLIC_APPEARANCE.authVideoPosterUrl),
|
||||||
|
skinId: value?.skinId === "classic" ? value.skinId : DEFAULT_PUBLIC_APPEARANCE.skinId,
|
||||||
|
logoConfigured: Boolean(value?.logoConfigured),
|
||||||
|
darkLogoConfigured: Boolean(value?.darkLogoConfigured),
|
||||||
|
authVideoConfigured: customVideo,
|
||||||
|
authVideoPosterConfigured: Boolean(value?.authVideoPosterConfigured),
|
||||||
|
configured: Boolean(value?.configured),
|
||||||
|
revision: String(value?.revision || DEFAULT_PUBLIC_APPEARANCE.revision),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeAppearanceCopy(value: unknown, fallback: string, allowEmpty = false) {
|
||||||
|
if (typeof value !== "string") return fallback;
|
||||||
|
const normalized = value.replace(/\r\n?/g, "\n").trim();
|
||||||
|
return normalized || (allowEmpty ? "" : fallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function commitPublicAppearance(value?: Partial<PublicAppearance> | null) {
|
||||||
|
const appearance = normalizePublicAppearance(value);
|
||||||
|
useAppearanceStore.getState().setAppearance(appearance);
|
||||||
|
applyAppearanceMetadata(appearance);
|
||||||
|
return appearance;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function applyAppearanceMetadata(appearance: PublicAppearance, targetDocument: Document | undefined = typeof document === "undefined" ? undefined : document) {
|
||||||
|
if (!targetDocument) return;
|
||||||
|
targetDocument.title = appearance.brandName;
|
||||||
|
const description = targetDocument.querySelector<HTMLMetaElement>('meta[name="description"]');
|
||||||
|
if (description) description.content = `${appearance.brandName},面向 AI 影视与短剧创作的工作台。`;
|
||||||
|
let favicon = targetDocument.querySelector<HTMLLinkElement>('link[rel~="icon"]');
|
||||||
|
if (!favicon) {
|
||||||
|
favicon = targetDocument.createElement("link");
|
||||||
|
favicon.rel = "icon";
|
||||||
|
targetDocument.head.appendChild(favicon);
|
||||||
|
}
|
||||||
|
favicon.href = appearanceLogoURL(appearance, targetDocument.documentElement.classList.contains("dark") ? "dark" : "light");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function appearanceLogoURL(appearance: PublicAppearance, theme: "light" | "dark") {
|
||||||
|
return theme === "dark" ? appearance.darkLogoUrl || appearance.logoUrl : appearance.logoUrl || appearance.darkLogoUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function brandStudioLabel(appearance: PublicAppearance) {
|
||||||
|
if (appearance.brandName === DEFAULT_PUBLIC_APPEARANCE.brandName && appearance.brandSlug === DEFAULT_PUBLIC_APPEARANCE.brandSlug) return "YINGCE STUDIO";
|
||||||
|
return appearance.brandSlug.replace(/-+/g, " ").toLocaleUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeBrandSlug(value: unknown) {
|
||||||
|
const candidate = String(value || "")
|
||||||
|
.trim()
|
||||||
|
.toLocaleLowerCase();
|
||||||
|
return /^[a-z0-9](?:[a-z0-9-]{0,46}[a-z0-9])?$/.test(candidate) ? candidate : DEFAULT_PUBLIC_APPEARANCE.brandSlug;
|
||||||
|
}
|
||||||
|
|
||||||
|
function safeAppearanceURL(value: unknown, fallback: string) {
|
||||||
|
const candidate = String(value || "").trim();
|
||||||
|
if (!candidate) return fallback;
|
||||||
|
if (candidate.startsWith("/") && !candidate.startsWith("//")) return candidate;
|
||||||
|
try {
|
||||||
|
const parsed = new URL(candidate);
|
||||||
|
if (parsed.protocol === "https:") return parsed.toString();
|
||||||
|
} catch {
|
||||||
|
// Invalid or unsafe asset locations fall back to the bundled appearance.
|
||||||
|
}
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
@@ -9,6 +9,537 @@
|
|||||||
padding: 14px 16px;
|
padding: 14px 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Appearance management follows the same full-width settings document used by storage and access pages. */
|
||||||
|
.admin-appearance-settings {
|
||||||
|
padding-bottom: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-settings .admin-settings-section {
|
||||||
|
border: 1px solid var(--admin-card-border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-settings .admin-settings-section-summary,
|
||||||
|
.admin-appearance-settings .admin-settings-section-content {
|
||||||
|
background: var(--admin-layer-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-brand-section {
|
||||||
|
border-color: color-mix(in srgb, var(--foreground) 22%, var(--admin-card-border)) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-brand-section > .admin-settings-section-summary {
|
||||||
|
background: color-mix(in srgb, var(--foreground) 3%, var(--admin-layer-1));
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-brand-section > .admin-settings-section-summary h2 {
|
||||||
|
font-size: 16px;
|
||||||
|
letter-spacing: -0.01em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-command-bar {
|
||||||
|
display: flex;
|
||||||
|
min-height: 42px;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 18px;
|
||||||
|
border-bottom: 1px solid var(--admin-divider);
|
||||||
|
padding: 0 0 10px;
|
||||||
|
transition: border-color 180ms ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-command-bar.is-dirty {
|
||||||
|
border-color: color-mix(in srgb, var(--admin-status-warning) 42%, var(--admin-divider));
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-command-copy,
|
||||||
|
.admin-appearance-command-actions,
|
||||||
|
.admin-appearance-load-error {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-command-copy {
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-command-copy strong {
|
||||||
|
color: var(--admin-text-primary);
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 650;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-command-copy p {
|
||||||
|
margin-top: 1px;
|
||||||
|
color: var(--admin-text-muted);
|
||||||
|
font-size: 10px;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-command-actions {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-brand-layout,
|
||||||
|
.admin-appearance-auth-layout {
|
||||||
|
display: grid;
|
||||||
|
gap: 20px;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-brand-layout {
|
||||||
|
grid-template-columns: minmax(0, 1fr) minmax(360px, 0.8fr);
|
||||||
|
align-items: start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-auth-layout {
|
||||||
|
grid-template-columns: minmax(0, 1fr) minmax(300px, 380px);
|
||||||
|
align-items: start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-form,
|
||||||
|
.admin-appearance-auth-controls,
|
||||||
|
.admin-appearance-media-list,
|
||||||
|
.admin-appearance-brand-logo {
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-form .ant-form-item:last-child {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-brand-logo {
|
||||||
|
display: grid;
|
||||||
|
align-self: stretch;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-logo-stack {
|
||||||
|
align-self: start;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-logo-frame-option {
|
||||||
|
display: flex;
|
||||||
|
min-height: 76px;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 16px;
|
||||||
|
border: 1px solid var(--admin-card-border);
|
||||||
|
border-radius: var(--r-md);
|
||||||
|
background: var(--admin-layer-2);
|
||||||
|
padding: 13px 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-logo-frame-copy {
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-logo-frame-copy strong {
|
||||||
|
color: var(--admin-text-primary);
|
||||||
|
font-size: var(--fs-caption);
|
||||||
|
font-weight: 650;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-logo-frame-copy p {
|
||||||
|
max-width: 520px;
|
||||||
|
margin: 5px 0 0;
|
||||||
|
color: var(--admin-text-muted);
|
||||||
|
font-size: var(--fs-label);
|
||||||
|
line-height: 1.55;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-logo-frame-control {
|
||||||
|
display: flex;
|
||||||
|
flex: 0 0 auto;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-logo-frame-control > span {
|
||||||
|
color: var(--admin-text-muted);
|
||||||
|
font-size: 10px;
|
||||||
|
font-weight: 600;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-logo-frame-option .ant-switch:not(.ant-switch-checked) {
|
||||||
|
box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--foreground) 16%, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-logo-frame-option .ant-switch.ant-switch-checked {
|
||||||
|
box-shadow:
|
||||||
|
inset 0 0 0 1px color-mix(in srgb, var(--admin-status-success) 62%, var(--foreground)),
|
||||||
|
0 0 0 2px color-mix(in srgb, var(--admin-status-success) 13%, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-logo-preview-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-logo-preview {
|
||||||
|
display: grid;
|
||||||
|
min-height: 104px;
|
||||||
|
place-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
border: 1px solid var(--admin-card-border);
|
||||||
|
border-radius: var(--r-md);
|
||||||
|
padding: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-logo-preview.is-light {
|
||||||
|
background: var(--color-neutral-50);
|
||||||
|
color: var(--color-neutral-900);
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-logo-preview.is-dark {
|
||||||
|
background: var(--color-neutral-900);
|
||||||
|
color: var(--color-neutral-50);
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-logo-preview-mark {
|
||||||
|
display: grid;
|
||||||
|
width: 44px;
|
||||||
|
height: 44px;
|
||||||
|
place-items: center;
|
||||||
|
border-radius: var(--r-md);
|
||||||
|
background: currentColor;
|
||||||
|
box-shadow: var(--shadow-sm);
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-logo-preview-mark.is-unframed {
|
||||||
|
border-radius: 0;
|
||||||
|
background: transparent;
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-logo-preview-mark img {
|
||||||
|
width: 28px;
|
||||||
|
height: 28px;
|
||||||
|
object-fit: contain;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-logo-preview-mark.is-unframed img {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-logo-preview-label {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 5px;
|
||||||
|
font-size: var(--fs-label);
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-logo-preview-label svg {
|
||||||
|
width: 13px;
|
||||||
|
height: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-auth-controls,
|
||||||
|
.admin-appearance-media-list {
|
||||||
|
display: grid;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-media-list {
|
||||||
|
margin-top: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-asset-row {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 36px minmax(0, 1fr) auto;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
min-height: 84px;
|
||||||
|
border: 1px solid var(--admin-card-border);
|
||||||
|
border-radius: 8px;
|
||||||
|
background: var(--admin-layer-2);
|
||||||
|
padding: 13px 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-brand-logo .admin-appearance-asset-row {
|
||||||
|
min-height: 96px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-asset-icon,
|
||||||
|
.admin-appearance-load-error-icon {
|
||||||
|
display: grid;
|
||||||
|
flex: 0 0 auto;
|
||||||
|
place-items: center;
|
||||||
|
border: 1px solid color-mix(in srgb, var(--foreground) 10%, transparent);
|
||||||
|
border-radius: 8px;
|
||||||
|
background: var(--admin-layer-1);
|
||||||
|
color: var(--admin-text-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-asset-icon {
|
||||||
|
width: 36px;
|
||||||
|
height: 36px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-asset-icon svg {
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-asset-copy {
|
||||||
|
display: grid;
|
||||||
|
gap: 3px;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-asset-copy strong,
|
||||||
|
.admin-appearance-skin-note > span {
|
||||||
|
color: var(--admin-text-primary);
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 650;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-asset-copy small,
|
||||||
|
.admin-appearance-skin-note small,
|
||||||
|
.admin-appearance-preview > p {
|
||||||
|
color: var(--admin-text-muted);
|
||||||
|
font-size: 11px;
|
||||||
|
line-height: 1.55;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-asset-copy em {
|
||||||
|
overflow: hidden;
|
||||||
|
color: var(--admin-status-info);
|
||||||
|
font-size: 11px;
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 600;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-asset-actions {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: flex-end;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-asset-actions input {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-preview {
|
||||||
|
display: grid;
|
||||||
|
gap: 12px;
|
||||||
|
border: 1px solid var(--admin-card-border);
|
||||||
|
border-radius: 10px;
|
||||||
|
background: var(--admin-layer-2);
|
||||||
|
padding: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-preview-heading {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-preview-heading > div {
|
||||||
|
display: grid;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-preview-heading span {
|
||||||
|
color: var(--admin-text-muted);
|
||||||
|
font-size: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-preview-heading strong {
|
||||||
|
overflow: hidden;
|
||||||
|
color: var(--admin-text-primary);
|
||||||
|
font-size: 12px;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-preview-stage {
|
||||||
|
position: relative;
|
||||||
|
aspect-ratio: 4 / 5;
|
||||||
|
overflow: hidden;
|
||||||
|
border-radius: 8px;
|
||||||
|
background: #08090c;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-preview-stage video,
|
||||||
|
.admin-appearance-preview-shade {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-preview-stage video {
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-preview-shade {
|
||||||
|
background: linear-gradient(180deg, rgb(4 5 8 / 0.52), transparent 42%, rgb(4 5 8 / 0.8));
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-preview-brand {
|
||||||
|
position: absolute;
|
||||||
|
top: 18px;
|
||||||
|
left: 18px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
max-width: calc(100% - 36px);
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-preview-brand img {
|
||||||
|
width: 26px;
|
||||||
|
height: 26px;
|
||||||
|
flex: 0 0 auto;
|
||||||
|
object-fit: contain;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-preview-brand strong {
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-preview-copy {
|
||||||
|
position: absolute;
|
||||||
|
right: 18px;
|
||||||
|
bottom: 22px;
|
||||||
|
left: 18px;
|
||||||
|
display: grid;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-preview-copy small {
|
||||||
|
color: rgb(255 255 255 / 0.58);
|
||||||
|
font-size: 10px;
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: 0.16em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-preview-copy strong,
|
||||||
|
.admin-appearance-preview-copy > span {
|
||||||
|
white-space: pre-line;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-preview-copy strong {
|
||||||
|
font-size: clamp(23px, 2.2vw, 31px);
|
||||||
|
line-height: 1.22;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-preview-copy > span {
|
||||||
|
color: rgb(255 255 255 / 0.66);
|
||||||
|
font-size: 11px;
|
||||||
|
line-height: 1.55;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-preview > p {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-skin-note {
|
||||||
|
display: grid;
|
||||||
|
gap: 6px;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-skin-note strong {
|
||||||
|
color: var(--admin-text-primary);
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-load-error,
|
||||||
|
.admin-appearance-loading-card {
|
||||||
|
min-height: 150px;
|
||||||
|
border: 1px solid var(--admin-card-border);
|
||||||
|
border-radius: 10px;
|
||||||
|
background: var(--admin-layer-1);
|
||||||
|
padding: 20px;
|
||||||
|
box-shadow: var(--admin-card-shadow);
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-load-error {
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-load-error-icon {
|
||||||
|
width: 32px;
|
||||||
|
height: 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-load-error > div {
|
||||||
|
min-width: 0;
|
||||||
|
flex: 1 1 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-load-error h2 {
|
||||||
|
color: var(--admin-text-primary);
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 650;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-load-error p {
|
||||||
|
margin-top: 4px;
|
||||||
|
color: var(--admin-text-muted);
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1.65;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 1120px) {
|
||||||
|
.admin-appearance-brand-layout,
|
||||||
|
.admin-appearance-auth-layout {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-preview {
|
||||||
|
max-width: 480px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 720px) {
|
||||||
|
.admin-appearance-command-bar {
|
||||||
|
align-items: flex-start;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-command-actions {
|
||||||
|
width: 100%;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-asset-row {
|
||||||
|
grid-template-columns: 36px minmax(0, 1fr);
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-logo-preview-grid {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-logo-frame-option {
|
||||||
|
align-items: flex-start;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-logo-frame-control {
|
||||||
|
width: 100%;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-appearance-asset-actions {
|
||||||
|
grid-column: 1 / -1;
|
||||||
|
justify-content: flex-start;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
:is(.admin-drawing-settings, .admin-runtime-policy, .admin-access-settings, .admin-email-settings, .admin-storage-settings, .admin-ark-settings, .admin-intercept-settings, .admin-third-party-settings)
|
:is(.admin-drawing-settings, .admin-runtime-policy, .admin-access-settings, .admin-email-settings, .admin-storage-settings, .admin-ark-settings, .admin-intercept-settings, .admin-third-party-settings)
|
||||||
:is(.admin-drawing-overview, .admin-runtime-policy-overview, .admin-access-overview, .admin-email-overview, .admin-storage-overview, .admin-ark-overview, .admin-intercept-overview, .admin-third-party-overview)
|
:is(.admin-drawing-overview, .admin-runtime-policy-overview, .admin-access-overview, .admin-email-overview, .admin-storage-overview, .admin-ark-overview, .admin-intercept-overview, .admin-third-party-overview)
|
||||||
.admin-stat-tile-value {
|
.admin-stat-tile-value {
|
||||||
|
|||||||
@@ -1155,6 +1155,11 @@
|
|||||||
box-shadow: 0 8px 24px color-mix(in srgb, var(--workspace-accent) 18%, transparent);
|
box-shadow: 0 8px 24px color-mix(in srgb, var(--workspace-accent) 18%, transparent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.brand-logo-frame[data-logo-frame-enabled="false"] > :is(img, svg) {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* 工作区保留滚轮与触控板滚动,只隐藏会形成额外竖向分割的浏览器轨道。 */
|
/* 工作区保留滚轮与触控板滚动,只隐藏会形成额外竖向分割的浏览器轨道。 */
|
||||||
|
|||||||
@@ -0,0 +1,116 @@
|
|||||||
|
import { expect, test } from "bun:test";
|
||||||
|
|
||||||
|
import { appearanceLogoURL, normalizePublicAppearance } from "../src/stores/use-appearance-store";
|
||||||
|
|
||||||
|
test("initial HTML stays brand neutral until the public appearance is resolved", async () => {
|
||||||
|
const [html, mainSource] = await Promise.all([Bun.file(new URL("../index.html", import.meta.url)).text(), Bun.file(new URL("../src/main.tsx", import.meta.url)).text()]);
|
||||||
|
|
||||||
|
expect(html).not.toContain("影策");
|
||||||
|
expect(html).not.toContain("/logo.svg");
|
||||||
|
expect(html).toContain("<title>正在加载</title>");
|
||||||
|
expect(mainSource.indexOf("bootstrapAppearance()")).toBeLessThan(mainSource.indexOf('import("./application")'));
|
||||||
|
});
|
||||||
|
|
||||||
|
test("a custom login video never falls back to the built-in poster", () => {
|
||||||
|
const appearance = normalizePublicAppearance({
|
||||||
|
brandName: "HIMA Studio",
|
||||||
|
brandSlug: "hima-studio",
|
||||||
|
authHeroTitle: "把灵感,\n变成可见的故事。",
|
||||||
|
authHeroDescription: "从同一个创作空间持续推进。",
|
||||||
|
authVideoConfigured: true,
|
||||||
|
authVideoUrl: "/api/public/appearance/assets/video?v=next",
|
||||||
|
authVideoPosterConfigured: false,
|
||||||
|
authVideoPosterUrl: "",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(appearance.brandName).toBe("HIMA Studio");
|
||||||
|
expect(appearance.brandSlug).toBe("hima-studio");
|
||||||
|
expect(appearance.authHeroTitle).toBe("把灵感,\n变成可见的故事。");
|
||||||
|
expect(appearance.authHeroDescription).toBe("从同一个创作空间持续推进。");
|
||||||
|
expect(appearance.authVideoPosterUrl).toBe("");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("appearance URLs reject executable and insecure remote schemes", () => {
|
||||||
|
const appearance = normalizePublicAppearance({
|
||||||
|
logoConfigured: true,
|
||||||
|
logoUrl: "javascript:alert(1)",
|
||||||
|
authVideoConfigured: true,
|
||||||
|
authVideoUrl: "http://example.com/brand.mp4",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(appearance.logoUrl).toBe("/logo.svg");
|
||||||
|
expect(appearance.authVideoUrl).not.toContain("example.com");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("appearance selects theme logos and falls back to the single configured logo", () => {
|
||||||
|
const dual = normalizePublicAppearance({
|
||||||
|
logoConfigured: true,
|
||||||
|
darkLogoConfigured: true,
|
||||||
|
logoUrl: "/api/public/appearance/assets/logo?v=dual",
|
||||||
|
darkLogoUrl: "/api/public/appearance/assets/logo-dark?v=dual",
|
||||||
|
logoFrameEnabled: false,
|
||||||
|
});
|
||||||
|
expect(appearanceLogoURL(dual, "light")).toContain("/logo?");
|
||||||
|
expect(appearanceLogoURL(dual, "dark")).toContain("/logo-dark?");
|
||||||
|
expect(dual.logoFrameEnabled).toBe(false);
|
||||||
|
|
||||||
|
const single = normalizePublicAppearance({ logoConfigured: true, logoUrl: "/api/public/appearance/assets/logo?v=single" });
|
||||||
|
expect(appearanceLogoURL(single, "light")).toBe(single.logoUrl);
|
||||||
|
expect(appearanceLogoURL(single, "dark")).toBe(single.logoUrl);
|
||||||
|
expect(single.logoFrameEnabled).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("auth scene consumes resolved appearance instead of hardcoded media constants", async () => {
|
||||||
|
const source = await Bun.file(new URL("../src/pages/auth/auth-scene.tsx", import.meta.url)).text();
|
||||||
|
|
||||||
|
expect(source).toContain("appearance.authVideoUrl");
|
||||||
|
expect(source).toContain("appearance.authVideoPosterUrl || undefined");
|
||||||
|
expect(source).toContain("appearance.brandName");
|
||||||
|
expect(source).toContain("appearance.authHeroTitle");
|
||||||
|
expect(source).toContain("appearance.authHeroDescription");
|
||||||
|
expect(source).toContain('theme="dark"');
|
||||||
|
expect(source).not.toContain("让一个故事,");
|
||||||
|
expect(source).not.toContain("AUTH_VIDEO_URL");
|
||||||
|
expect(source).not.toContain("AUTH_VIDEO_POSTER");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("appearance management exposes light and dark logo uploads plus the frame switch", async () => {
|
||||||
|
const [pageSource, brandSource, adminStyles, globalStyles] = await Promise.all([
|
||||||
|
Bun.file(new URL("../src/pages/admin/settings/appearance-settings-page.tsx", import.meta.url)).text(),
|
||||||
|
Bun.file(new URL("../src/components/brand/brand-logo.tsx", import.meta.url)).text(),
|
||||||
|
Bun.file(new URL("../src/styles/admin-ui.css", import.meta.url)).text(),
|
||||||
|
Bun.file(new URL("../src/styles/globals.css", import.meta.url)).text(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(pageSource).toContain('slot="logo-dark"');
|
||||||
|
expect(pageSource).toContain("浅色模式 Logo");
|
||||||
|
expect(pageSource).toContain("深色模式 Logo(可选)");
|
||||||
|
expect(pageSource).toContain("禁用 Logo 后面的圆角矩形外框");
|
||||||
|
expect(pageSource).toContain("<Switch");
|
||||||
|
expect(pageSource).toContain("checked={!logoFrameEnabled}");
|
||||||
|
expect(pageSource).toContain("setLogoFrameEnabled(!checked)");
|
||||||
|
expect(pageSource).not.toContain("<Checkbox");
|
||||||
|
expect(pageSource).toContain("深浅模式 Logo 预览");
|
||||||
|
expect(brandSource).toContain("useThemeStore");
|
||||||
|
expect(brandSource).toContain("data-logo-frame-enabled");
|
||||||
|
expect(adminStyles).toContain(".admin-appearance-logo-preview-mark.is-unframed img");
|
||||||
|
expect(globalStyles).toContain('.brand-logo-frame[data-logo-frame-enabled="false"] > :is(img, svg)');
|
||||||
|
});
|
||||||
|
|
||||||
|
test("object storage can adopt the configured English brand identifier without replacing saved prefixes automatically", async () => {
|
||||||
|
const source = await Bun.file(new URL("../src/pages/admin/settings/storage-settings-page.tsx", import.meta.url)).text();
|
||||||
|
|
||||||
|
expect(source).toContain("state.appearance.brandSlug");
|
||||||
|
expect(source).toContain("使用品牌标识");
|
||||||
|
expect(source).toContain('form.setFieldValue("pathPrefix", brandSlug)');
|
||||||
|
expect(source).toContain("setting.pathPrefix || DEFAULT_OSS_PATH_PREFIX");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("appearance management exposes a server-side reset to the built-in Yingce brand", async () => {
|
||||||
|
const [pageSource, apiSource] = await Promise.all([Bun.file(new URL("../src/pages/admin/settings/appearance-settings-page.tsx", import.meta.url)).text(), Bun.file(new URL("../src/services/api/appearance.ts", import.meta.url)).text()]);
|
||||||
|
|
||||||
|
expect(pageSource).toContain("恢复影策默认");
|
||||||
|
expect(pageSource).toContain("resetAdminAppearance()");
|
||||||
|
expect(pageSource).toContain("已上传文件仍保留在存储资源中");
|
||||||
|
expect(apiSource).toContain('apiClient.delete("/admin/settings/appearance")');
|
||||||
|
});
|
||||||
Reference in new issue
Block a user