chore: update system setting name convention (#1448)

pull/1449/head
boojack 2 years ago committed by GitHub
parent 8a33290722
commit 4f2adfef7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -11,26 +11,26 @@ import (
type SystemSettingName string type SystemSettingName string
const ( const (
// SystemSettingServerID is the key type of server id. // SystemSettingServerID is the name of server id.
SystemSettingServerID SystemSettingName = "serverId" SystemSettingServerIDName SystemSettingName = "server-id"
// SystemSettingSecretSessionName is the key type of secret session name. // SystemSettingSecretSessionName is the name of secret session.
SystemSettingSecretSessionName SystemSettingName = "secretSessionName" SystemSettingSecretSessionName SystemSettingName = "secret-session"
// SystemSettingAllowSignUpName is the key type of allow signup setting. // SystemSettingAllowSignUpName is the name of allow signup setting.
SystemSettingAllowSignUpName SystemSettingName = "allowSignUp" SystemSettingAllowSignUpName SystemSettingName = "allow-signup"
// SystemSettingDisablePublicMemosName is the key type of disable public memos setting. // SystemSettingDisablePublicMemosName is the name of disable public memos setting.
SystemSettingDisablePublicMemosName SystemSettingName = "disablePublicMemos" SystemSettingDisablePublicMemosName SystemSettingName = "disable-public-memos"
// SystemSettingAdditionalStyleName is the key type of additional style. // SystemSettingAdditionalStyleName is the name of additional style.
SystemSettingAdditionalStyleName SystemSettingName = "additionalStyle" SystemSettingAdditionalStyleName SystemSettingName = "additional-style"
// SystemSettingAdditionalScriptName is the key type of additional script. // SystemSettingAdditionalScriptName is the name of additional script.
SystemSettingAdditionalScriptName SystemSettingName = "additionalScript" SystemSettingAdditionalScriptName SystemSettingName = "additional-script"
// SystemSettingCustomizedProfileName is the key type of customized server profile. // SystemSettingCustomizedProfileName is the name of customized server profile.
SystemSettingCustomizedProfileName SystemSettingName = "customizedProfile" SystemSettingCustomizedProfileName SystemSettingName = "customized-profile"
// SystemSettingStorageServiceIDName is the key type of storage service ID. // SystemSettingStorageServiceIDName is the name of storage service ID.
SystemSettingStorageServiceIDName SystemSettingName = "storageServiceId" SystemSettingStorageServiceIDName SystemSettingName = "storage-service-id"
// SystemSettingLocalStoragePathName is the key type of local storage path. // SystemSettingLocalStoragePathName is the name of local storage path.
SystemSettingLocalStoragePathName SystemSettingName = "localStoragePath" SystemSettingLocalStoragePathName SystemSettingName = "local-storage-path"
// SystemSettingOpenAIConfigName is the key type of OpenAI config. // SystemSettingOpenAIConfigName is the name of OpenAI config.
SystemSettingOpenAIConfigName SystemSettingName = "openAIConfig" SystemSettingOpenAIConfigName SystemSettingName = "openai-config"
) )
// CustomizedProfile is the struct definition for SystemSettingCustomizedProfileName system setting item. // CustomizedProfile is the struct definition for SystemSettingCustomizedProfileName system setting item.
@ -56,26 +56,26 @@ type OpenAIConfig struct {
func (key SystemSettingName) String() string { func (key SystemSettingName) String() string {
switch key { switch key {
case SystemSettingServerID: case SystemSettingServerIDName:
return "serverId" return "server-id"
case SystemSettingSecretSessionName: case SystemSettingSecretSessionName:
return "secretSessionName" return "secret-session"
case SystemSettingAllowSignUpName: case SystemSettingAllowSignUpName:
return "allowSignUp" return "allow-signup"
case SystemSettingDisablePublicMemosName: case SystemSettingDisablePublicMemosName:
return "disablePublicMemos" return "disable-public-memos"
case SystemSettingAdditionalStyleName: case SystemSettingAdditionalStyleName:
return "additionalStyle" return "additional-style"
case SystemSettingAdditionalScriptName: case SystemSettingAdditionalScriptName:
return "additionalScript" return "additional-script"
case SystemSettingCustomizedProfileName: case SystemSettingCustomizedProfileName:
return "customizedProfile" return "customized-profile"
case SystemSettingStorageServiceIDName: case SystemSettingStorageServiceIDName:
return "storageServiceId" return "storage-service-id"
case SystemSettingLocalStoragePathName: case SystemSettingLocalStoragePathName:
return "localStoragePath" return "local-storage-path"
case SystemSettingOpenAIConfigName: case SystemSettingOpenAIConfigName:
return "openAIConfig" return "openai-config"
} }
return "" return ""
} }
@ -94,7 +94,7 @@ type SystemSettingUpsert struct {
} }
func (upsert SystemSettingUpsert) Validate() error { func (upsert SystemSettingUpsert) Validate() error {
if upsert.Name == SystemSettingServerID { if upsert.Name == SystemSettingServerIDName {
return errors.New("update server id is not allowed") return errors.New("update server id is not allowed")
} else if upsert.Name == SystemSettingAllowSignUpName { } else if upsert.Name == SystemSettingAllowSignUpName {
value := false value := false

@ -35,7 +35,7 @@ func (s *Server) registerRSSRoutes(g *echo.Group) {
} }
baseURL := c.Scheme() + "://" + c.Request().Host baseURL := c.Scheme() + "://" + c.Request().Host
rss, err := generateRSSFromMemoList(memoList, baseURL, &systemCustomizedProfile) rss, err := generateRSSFromMemoList(memoList, baseURL, systemCustomizedProfile)
if err != nil { if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to generate rss").SetInternal(err) return echo.NewHTTPError(http.StatusInternalServerError, "Failed to generate rss").SetInternal(err)
} }
@ -72,7 +72,7 @@ func (s *Server) registerRSSRoutes(g *echo.Group) {
baseURL := c.Scheme() + "://" + c.Request().Host baseURL := c.Scheme() + "://" + c.Request().Host
rss, err := generateRSSFromMemoList(memoList, baseURL, &systemCustomizedProfile) rss, err := generateRSSFromMemoList(memoList, baseURL, systemCustomizedProfile)
if err != nil { if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to generate rss").SetInternal(err) return echo.NewHTTPError(http.StatusInternalServerError, "Failed to generate rss").SetInternal(err)
} }
@ -114,57 +114,27 @@ func generateRSSFromMemoList(memoList []*api.Memo, baseURL string, profile *api.
return rss, nil return rss, nil
} }
func getSystemCustomizedProfile(ctx context.Context, s *Server) (api.CustomizedProfile, error) { func getSystemCustomizedProfile(ctx context.Context, s *Server) (*api.CustomizedProfile, error) {
systemStatus := api.SystemStatus{ customizedProfile := &api.CustomizedProfile{
CustomizedProfile: api.CustomizedProfile{
Name: "memos", Name: "memos",
LogoURL: "", LogoURL: "",
Description: "", Description: "",
Locale: "en", Locale: "en",
Appearance: "system", Appearance: "system",
ExternalURL: "", ExternalURL: "",
},
} }
systemSetting, err := s.Store.FindSystemSetting(ctx, &api.SystemSettingFind{
systemSettingList, err := s.Store.FindSystemSettingList(ctx, &api.SystemSettingFind{}) Name: api.SystemSettingCustomizedProfileName,
})
if err != nil { if err != nil {
return api.CustomizedProfile{}, err return customizedProfile, err
}
for _, systemSetting := range systemSettingList {
if systemSetting.Name == api.SystemSettingServerID || systemSetting.Name == api.SystemSettingSecretSessionName {
continue
} }
var value any err = json.Unmarshal([]byte(systemSetting.Value), customizedProfile)
err := json.Unmarshal([]byte(systemSetting.Value), &value)
if err != nil { if err != nil {
return api.CustomizedProfile{}, err return customizedProfile, err
}
if systemSetting.Name == api.SystemSettingCustomizedProfileName {
valueMap := value.(map[string]any)
systemStatus.CustomizedProfile = api.CustomizedProfile{}
if v := valueMap["name"]; v != nil {
systemStatus.CustomizedProfile.Name = v.(string)
}
if v := valueMap["logoUrl"]; v != nil {
systemStatus.CustomizedProfile.LogoURL = v.(string)
}
if v := valueMap["description"]; v != nil {
systemStatus.CustomizedProfile.Description = v.(string)
}
if v := valueMap["locale"]; v != nil {
systemStatus.CustomizedProfile.Locale = v.(string)
}
if v := valueMap["appearance"]; v != nil {
systemStatus.CustomizedProfile.Appearance = v.(string)
}
if v := valueMap["externalUrl"]; v != nil {
systemStatus.CustomizedProfile.ExternalURL = v.(string)
}
}
} }
return systemStatus.CustomizedProfile, nil return customizedProfile, nil
} }
func min(a, b int) int { func min(a, b int) int {

@ -60,7 +60,7 @@ func (s *Server) registerSystemRoutes(g *echo.Group) {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find system setting list").SetInternal(err) return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find system setting list").SetInternal(err)
} }
for _, systemSetting := range systemSettingList { for _, systemSetting := range systemSettingList {
if systemSetting.Name == api.SystemSettingServerID || systemSetting.Name == api.SystemSettingSecretSessionName || systemSetting.Name == api.SystemSettingOpenAIConfigName { if systemSetting.Name == api.SystemSettingServerIDName || systemSetting.Name == api.SystemSettingSecretSessionName || systemSetting.Name == api.SystemSettingOpenAIConfigName {
continue continue
} }
@ -194,14 +194,14 @@ func (s *Server) registerSystemRoutes(g *echo.Group) {
func (s *Server) getSystemServerID(ctx context.Context) (string, error) { func (s *Server) getSystemServerID(ctx context.Context) (string, error) {
serverIDValue, err := s.Store.FindSystemSetting(ctx, &api.SystemSettingFind{ serverIDValue, err := s.Store.FindSystemSetting(ctx, &api.SystemSettingFind{
Name: api.SystemSettingServerID, Name: api.SystemSettingServerIDName,
}) })
if err != nil && common.ErrorCode(err) != common.NotFound { if err != nil && common.ErrorCode(err) != common.NotFound {
return "", err return "", err
} }
if serverIDValue == nil || serverIDValue.Value == "" { if serverIDValue == nil || serverIDValue.Value == "" {
serverIDValue, err = s.Store.UpsertSystemSetting(ctx, &api.SystemSettingUpsert{ serverIDValue, err = s.Store.UpsertSystemSetting(ctx, &api.SystemSettingUpsert{
Name: api.SystemSettingServerID, Name: api.SystemSettingServerIDName,
Value: uuid.NewString(), Value: uuid.NewString(),
}) })
if err != nil { if err != nil {

@ -1,15 +1,6 @@
INSERT INTO UPDATE
user_setting (user_id, key, value)
SELECT
user_id,
'memo-visibility',
value
FROM
user_setting
WHERE
key = 'memoVisibility';
DELETE FROM
user_setting user_setting
SET
key = 'memo-visibility'
WHERE WHERE
key = 'memoVisibility'; key = 'memoVisibility';

@ -0,0 +1,69 @@
UPDATE
system_setting
SET
key = 'server-id'
WHERE
key = 'serverId';
UPDATE
system_setting
SET
key = 'secret-session'
WHERE
key = 'secretSessionName';
UPDATE
system_setting
SET
key = 'allow-signup'
WHERE
key = 'allowSignUp';
UPDATE
system_setting
SET
key = 'disable-public-memos'
WHERE
key = 'disablePublicMemos';
UPDATE
system_setting
SET
key = 'additional-style'
WHERE
key = 'additionalStyle';
UPDATE
system_setting
SET
key = 'additional-script'
WHERE
key = 'additionalScript';
UPDATE
system_setting
SET
key = 'customized-profile'
WHERE
key = 'customizedProfile';
UPDATE
system_setting
SET
key = 'storage-service-id'
WHERE
key = 'storageServiceId';
UPDATE
system_setting
SET
key = 'local-storage-path'
WHERE
key = 'localStoragePath';
UPDATE
system_setting
SET
key = 'openai-config'
WHERE
key = 'openAIConfig';

@ -1,4 +1,4 @@
INSERT INTO INSERT INTO
system_setting (`name`, `value`, `description`) system_setting (`name`, `value`, `description`)
VALUES VALUES
('allowSignUp', 'true', ''); ('allow-signup', 'true', '');

@ -29,7 +29,7 @@ const StorageSection = () => {
const handleActiveStorageServiceChanged = async (storageId: StorageId) => { const handleActiveStorageServiceChanged = async (storageId: StorageId) => {
await api.upsertSystemSetting({ await api.upsertSystemSetting({
name: "storageServiceId", name: "storage-service-id",
value: JSON.stringify(storageId), value: JSON.stringify(storageId),
}); });
await globalStore.fetchSystemStatus(); await globalStore.fetchSystemStatus();

@ -57,7 +57,7 @@ const SystemSection = () => {
useEffect(() => { useEffect(() => {
api.getSystemSetting().then(({ data: { data: systemSettings } }) => { api.getSystemSetting().then(({ data: { data: systemSettings } }) => {
const openAIConfigSetting = systemSettings.find((setting) => setting.name === "openAIConfig"); const openAIConfigSetting = systemSettings.find((setting) => setting.name === "openai-config");
if (openAIConfigSetting) { if (openAIConfigSetting) {
setOpenAIConfig(JSON.parse(openAIConfigSetting.value)); setOpenAIConfig(JSON.parse(openAIConfigSetting.value));
} }
@ -70,7 +70,7 @@ const SystemSection = () => {
allowSignUp: value, allowSignUp: value,
}); });
await api.upsertSystemSetting({ await api.upsertSystemSetting({
name: "allowSignUp", name: "allow-signup",
value: JSON.stringify(value), value: JSON.stringify(value),
}); });
}; };
@ -100,7 +100,7 @@ const SystemSection = () => {
const handleSaveOpenAIConfig = async () => { const handleSaveOpenAIConfig = async () => {
try { try {
await api.upsertSystemSetting({ await api.upsertSystemSetting({
name: "openAIConfig", name: "openai-config",
value: JSON.stringify(openAIConfig), value: JSON.stringify(openAIConfig),
}); });
} catch (error) { } catch (error) {
@ -127,7 +127,7 @@ const SystemSection = () => {
const handleSaveAdditionalStyle = async () => { const handleSaveAdditionalStyle = async () => {
try { try {
await api.upsertSystemSetting({ await api.upsertSystemSetting({
name: "additionalStyle", name: "additional-style",
value: JSON.stringify(state.additionalStyle), value: JSON.stringify(state.additionalStyle),
}); });
} catch (error) { } catch (error) {
@ -147,7 +147,7 @@ const SystemSection = () => {
const handleSaveAdditionalScript = async () => { const handleSaveAdditionalScript = async () => {
try { try {
await api.upsertSystemSetting({ await api.upsertSystemSetting({
name: "additionalScript", name: "additional-script",
value: JSON.stringify(state.additionalScript), value: JSON.stringify(state.additionalScript),
}); });
} catch (error) { } catch (error) {
@ -164,7 +164,7 @@ const SystemSection = () => {
}); });
globalStore.setSystemStatus({ disablePublicMemos: value }); globalStore.setSystemStatus({ disablePublicMemos: value });
await api.upsertSystemSetting({ await api.upsertSystemSetting({
name: "disablePublicMemos", name: "disable-public-memos",
value: JSON.stringify(value), value: JSON.stringify(value),
}); });
}; };

@ -83,7 +83,7 @@ const UpdateCustomizedProfileDialog: React.FC<Props> = ({ destroy }: Props) => {
try { try {
await api.upsertSystemSetting({ await api.upsertSystemSetting({
name: "customizedProfile", name: "customized-profile",
value: JSON.stringify(state), value: JSON.stringify(state),
}); });
await globalStore.fetchSystemStatus(); await globalStore.fetchSystemStatus();

@ -23,7 +23,7 @@ const UpdateLocalStorageDialog: React.FC<Props> = (props: Props) => {
const handleConfirmBtnClick = async () => { const handleConfirmBtnClick = async () => {
try { try {
await api.upsertSystemSetting({ await api.upsertSystemSetting({
name: "localStoragePath", name: "local-storage-path",
value: JSON.stringify(path), value: JSON.stringify(path),
}); });
await globalStore.fetchSystemStatus(); await globalStore.fetchSystemStatus();

Loading…
Cancel
Save