优化后端可以编辑皮肤等等

This commit is contained in:
yml
2026-05-22 23:34:18 +08:00
parent 52ac6b7827
commit b68411166d
11 changed files with 1286 additions and 694 deletions
@@ -1,6 +1,9 @@
package systemconfig
import "errors"
import (
"encoding/json"
"errors"
)
var (
ErrDependencyUnavailable = errors.New("dependency unavailable")
@@ -22,6 +25,22 @@ func (s *Service) List() ([]ConfigDTO, error) {
return s.repo.List()
}
func (s *Service) PublishOptions() (*PublishOptionsDTO, error) {
if s.repo == nil {
return nil, ErrDependencyUnavailable
}
value, err := s.repo.FindValue(publishOptionsConfigKey)
if err != nil {
return nil, err
}
options := DefaultPublishOptions()
if err := json.Unmarshal([]byte(value), &options); err != nil {
options = DefaultPublishOptions()
}
normalizePublishOptions(&options)
return &options, nil
}
func (s *Service) Update(actorID uint64, key string, req UpdateRequest, meta AuditMeta) (*ConfigDTO, error) {
if s.repo == nil {
return nil, ErrDependencyUnavailable
@@ -31,3 +50,37 @@ func (s *Service) Update(actorID uint64, key string, req UpdateRequest, meta Aud
}
return s.repo.Update(actorID, key, req, meta)
}
func normalizePublishOptions(options *PublishOptionsDTO) {
defaults := DefaultPublishOptions()
if len(options.ServerOptions) == 0 {
options.ServerOptions = defaults.ServerOptions
}
if len(options.FaceOptions) == 0 {
options.FaceOptions = defaults.FaceOptions
}
if len(options.RankOptions) == 0 {
options.RankOptions = defaults.RankOptions
}
if len(options.InsuranceOptions) == 0 {
options.InsuranceOptions = defaults.InsuranceOptions
}
if len(options.LevelOptions) == 0 {
options.LevelOptions = defaults.LevelOptions
}
if len(options.LoginMethodOptions) == 0 {
options.LoginMethodOptions = defaults.LoginMethodOptions
}
if len(options.RegionOptions) == 0 {
options.RegionOptions = defaults.RegionOptions
}
if len(options.SkinGroups) == 0 {
options.SkinGroups = defaults.SkinGroups
}
if len(options.QuantityItems) == 0 {
options.QuantityItems = defaults.QuantityItems
}
if len(options.ScreenshotSlots) == 0 {
options.ScreenshotSlots = defaults.ScreenshotSlots
}
}