chore: update server activity (#898)

This commit is contained in:
boojack
2023-01-03 20:05:37 +08:00
committed by GitHub
parent e5550828a0
commit 79180928d4
4 changed files with 50 additions and 28 deletions

View File

@@ -2,6 +2,7 @@ package api
import (
"encoding/json"
"errors"
"fmt"
"golang.org/x/exp/slices"
@@ -10,6 +11,8 @@ import (
type SystemSettingName string
const (
// SystemSettingServerID is the key type of server id.
SystemSettingServerID SystemSettingName = "serverId"
// SystemSettingAllowSignUpName is the key type of allow signup setting.
SystemSettingAllowSignUpName SystemSettingName = "allowSignUp"
// SystemSettingAdditionalStyleName is the key type of additional style.
@@ -38,6 +41,8 @@ type CustomizedProfile struct {
func (key SystemSettingName) String() string {
switch key {
case SystemSettingServerID:
return "serverId"
case SystemSettingAllowSignUpName:
return "allowSignUp"
case SystemSettingAdditionalStyleName:
@@ -56,7 +61,7 @@ var (
type SystemSetting struct {
Name SystemSettingName
// Value is a JSON string with basic value
// Value is a JSON string with basic value.
Value string
Description string
}
@@ -68,7 +73,9 @@ type SystemSettingUpsert struct {
}
func (upsert SystemSettingUpsert) Validate() error {
if upsert.Name == SystemSettingAllowSignUpName {
if upsert.Name == SystemSettingServerID {
return errors.New("update server id is not allowed")
} else if upsert.Name == SystemSettingAllowSignUpName {
value := false
err := json.Unmarshal([]byte(upsert.Value), &value)
if err != nil {