优化后端可以编辑皮肤等等
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user