Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

chore: update system setting name convention (#1448)

boojack4f2adfef7b7e
diff --git a/api/system_setting.go b/api/system_setting.go
index 269e851c8..be1c3bf04 100644
--- a/api/system_setting.go
+++ b/api/system_setting.go
@@ -11,26 +11,26 @@ import (
type SystemSettingName string
const (
- // SystemSettingServerID is the key type of server id.
- SystemSettingServerID SystemSettingName = "serverId"
- // SystemSettingSecretSessionName is the key type of secret session name.
- SystemSettingSecretSessionName SystemSettingName = "secretSessionName"
- // SystemSettingAllowSignUpName is the key type of allow signup setting.
- SystemSettingAllowSignUpName SystemSettingName = "allowSignUp"
- // SystemSettingDisablePublicMemosName is the key type of disable public memos setting.
- SystemSettingDisablePublicMemosName SystemSettingName = "disablePublicMemos"
- // SystemSettingAdditionalStyleName is the key type of additional style.
- SystemSettingAdditionalStyleName SystemSettingName = "additionalStyle"
- // SystemSettingAdditionalScriptName is the key type of additional script.
- SystemSettingAdditionalScriptName SystemSettingName = "additionalScript"
- // SystemSettingCustomizedProfileName is the key type of customized server profile.
- SystemSettingCustomizedProfileName SystemSettingName = "customizedProfile"
- // SystemSettingStorageServiceIDName is the key type of storage service ID.
- SystemSettingStorageServiceIDName SystemSettingName = "storageServiceId"
- // SystemSettingLocalStoragePathName is the key type of local storage path.
- SystemSettingLocalStoragePathName SystemSettingName = "localStoragePath"
- // SystemSettingOpenAIConfigName is the key type of OpenAI config.
- SystemSettingOpenAIConfigName SystemSettingName = "openAIConfig"
+ // SystemSettingServerID is the name of server id.
+ SystemSettingServerIDName SystemSettingName = "server-id"
+ // SystemSettingSecretSessionName is the name of secret session.
+ SystemSettingSecretSessionName SystemSettingName = "secret-session"
+ // SystemSettingAllowSignUpName is the name of allow signup setting.
+ SystemSettingAllowSignUpName SystemSettingName = "allow-signup"
+ // SystemSettingDisablePublicMemosName is the name of disable public memos setting.
+ SystemSettingDisablePublicMemosName SystemSettingName = "disable-public-memos"
+ // SystemSettingAdditionalStyleName is the name of additional style.
+ SystemSettingAdditionalStyleName SystemSettingName = "additional-style"
+ // SystemSettingAdditionalScriptName is the name of additional script.
+ SystemSettingAdditionalScriptName SystemSettingName = "additional-script"
+ // SystemSettingCustomizedProfileName is the name of customized server profile.
+ SystemSettingCustomizedProfileName SystemSettingName = "customized-profile"
+ // SystemSettingStorageServiceIDName is the name of storage service ID.
+ SystemSettingStorageServiceIDName SystemSettingName = "storage-service-id"
+ // SystemSettingLocalStoragePathName is the name of local storage path.
+ SystemSettingLocalStoragePathName SystemSettingName = "local-storage-path"
+ // SystemSettingOpenAIConfigName is the name of OpenAI config.
+ SystemSettingOpenAIConfigName SystemSettingName = "openai-config"
)
// CustomizedProfile is the struct definition for SystemSettingCustomizedProfileName system setting item.
@@ -56,26 +56,26 @@ type OpenAIConfig struct {
func (key SystemSettingName) String() string {
switch key {
- case SystemSettingServerID:
- return "serverId"
+ case SystemSettingServerIDName:
+ return "server-id"
case SystemSettingSecretSessionName:
- return "secretSessionName"
+ return "secret-session"
case SystemSettingAllowSignUpName:
- return "allowSignUp"
+ return "allow-signup"
case SystemSettingDisablePublicMemosName:
- return "disablePublicMemos"
+ return "disable-public-memos"
case SystemSettingAdditionalStyleName:
- return "additionalStyle"
+ return "additional-style"
case SystemSettingAdditionalScriptName:
- return "additionalScript"
+ return "additional-script"
case SystemSettingCustomizedProfileName:
- return "customizedProfile"
+ return "customized-profile"
case SystemSettingStorageServiceIDName:
- return "storageServiceId"
+ return "storage-service-id"
case SystemSettingLocalStoragePathName:
- return "localStoragePath"
+ return "local-storage-path"
case SystemSettingOpenAIConfigName:
- return "openAIConfig"
+ return "openai-config"
}
return ""
}
@@ -94,7 +94,7 @@ type SystemSettingUpsert struct {
}
func (upsert SystemSettingUpsert) Validate() error {
- if upsert.Name == SystemSettingServerID {
+ if upsert.Name == SystemSettingServerIDName {
return errors.New("update server id is not allowed")
} else if upsert.Name == SystemSettingAllowSignUpName {
value := false
diff --git a/server/rss.go b/server/rss.go
index 88d4dc4d7..872f27c5d 100644
--- a/server/rss.go
+++ b/server/rss.go
@@ -35,7 +35,7 @@ func (s *Server) registerRSSRoutes(g *echo.Group) {
}
baseURL := c.Scheme() + "://" + c.Request().Host
- rss, err := generateRSSFromMemoList(memoList, baseURL, &systemCustomizedProfile)
+ rss, err := generateRSSFromMemoList(memoList, baseURL, systemCustomizedProfile)
if err != nil {
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
- rss, err := generateRSSFromMemoList(memoList, baseURL, &systemCustomizedProfile)
+ rss, err := generateRSSFromMemoList(memoList, baseURL, systemCustomizedProfile)
if err != nil {
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
}
-func getSystemCustomizedProfile(ctx context.Context, s *Server) (api.CustomizedProfile, error) {
- systemStatus := api.SystemStatus{
- CustomizedProfile: api.CustomizedProfile{
- Name: "memos",
- LogoURL: "",
- Description: "",
- Locale: "en",
- Appearance: "system",
- ExternalURL: "",
- },
+func getSystemCustomizedProfile(ctx context.Context, s *Server) (*api.CustomizedProfile, error) {
+ customizedProfile := &api.CustomizedProfile{
+ Name: "memos",
+ LogoURL: "",
+ Description: "",
+ Locale: "en",
+ Appearance: "system",
+ ExternalURL: "",
}
-
- systemSettingList, err := s.Store.FindSystemSettingList(ctx, &api.SystemSettingFind{})
+ systemSetting, err := s.Store.FindSystemSetting(ctx, &api.SystemSettingFind{
+ Name: api.SystemSettingCustomizedProfileName,
+ })
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), &value)
- if err != nil {
- return api.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)
- }
- }
+ err = json.Unmarshal([]byte(systemSetting.Value), customizedProfile)
+ if err != nil {
+ return customizedProfile, err
}
- return systemStatus.CustomizedProfile, nil
+ return customizedProfile, nil
}
func min(a, b int) int {
diff --git a/server/system.go b/server/system.go
index 9fbd284ce..0db7aaecb 100644
--- a/server/system.go
+++ b/server/system.go
@@ -60,7 +60,7 @@ func (s *Server) registerSystemRoutes(g *echo.Group) {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find system setting list").SetInternal(err)
}
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
}
@@ -194,14 +194,14 @@ func (s *Server) registerSystemRoutes(g *echo.Group) {
func (s *Server) getSystemServerID(ctx context.Context) (string, error) {
serverIDValue, err := s.Store.FindSystemSetting(ctx, &api.SystemSettingFind{
- Name: api.SystemSettingServerID,
+ Name: api.SystemSettingServerIDName,
})
if err != nil && common.ErrorCode(err) != common.NotFound {
return "", err
}
if serverIDValue == nil || serverIDValue.Value == "" {
serverIDValue, err = s.Store.UpsertSystemSetting(ctx, &api.SystemSettingUpsert{
- Name: api.SystemSettingServerID,
+ Name: api.SystemSettingServerIDName,
Value: uuid.NewString(),
})
if err != nil {
diff --git a/store/db/migration/prod/0.12/00__user_setting.sql b/store/db/migration/prod/0.12/00__user_setting.sql
index aca6f1d88..b9fbbe62e 100644
--- a/store/db/migration/prod/0.12/00__user_setting.sql
+++ b/store/db/migration/prod/0.12/00__user_setting.sql
@@ -1,15 +1,6 @@
-INSERT INTO
- user_setting (user_id, key, value)
-SELECT
- user_id,
- 'memo-visibility',
- value
-FROM
- user_setting
-WHERE
- key = 'memoVisibility';
-
-DELETE FROM
+UPDATE
user_setting
+SET
+ key = 'memo-visibility'
WHERE
key = 'memoVisibility';
\ No newline at end of file
diff --git a/store/db/migration/prod/0.12/01__system_setting.sql b/store/db/migration/prod/0.12/01__system_setting.sql
new file mode 100644
index 000000000..e42eaf73c
--- /dev/null
+++ b/store/db/migration/prod/0.12/01__system_setting.sql
@@ -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';
\ No newline at end of file
diff --git a/store/db/seed/10005__system_setting.sql b/store/db/seed/10005__system_setting.sql
index 143c1dbb2..ddce8ee43 100644
--- a/store/db/seed/10005__system_setting.sql
+++ b/store/db/seed/10005__system_setting.sql
@@ -1,4 +1,4 @@
INSERT INTO
system_setting (`name`, `value`, `description`)
VALUES
- ('allowSignUp', 'true', '');
\ No newline at end of file
+ ('allow-signup', 'true', '');
\ No newline at end of file
diff --git a/web/src/components/Settings/StorageSection.tsx b/web/src/components/Settings/StorageSection.tsx
index c60690bc5..8f36c6820 100644
--- a/web/src/components/Settings/StorageSection.tsx
+++ b/web/src/components/Settings/StorageSection.tsx
@@ -29,7 +29,7 @@ const StorageSection = () => {
const handleActiveStorageServiceChanged = async (storageId: StorageId) => {
await api.upsertSystemSetting({
- name: "storageServiceId",
+ name: "storage-service-id",
value: JSON.stringify(storageId),
});
await globalStore.fetchSystemStatus();
diff --git a/web/src/components/Settings/SystemSection.tsx b/web/src/components/Settings/SystemSection.tsx
index 572f953a4..f3a290e9f 100644
--- a/web/src/components/Settings/SystemSection.tsx
+++ b/web/src/components/Settings/SystemSection.tsx
@@ -57,7 +57,7 @@ const SystemSection = () => {
useEffect(() => {
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) {
setOpenAIConfig(JSON.parse(openAIConfigSetting.value));
}
@@ -70,7 +70,7 @@ const SystemSection = () => {
allowSignUp: value,
});
await api.upsertSystemSetting({
- name: "allowSignUp",
+ name: "allow-signup",
value: JSON.stringify(value),
});
};
@@ -100,7 +100,7 @@ const SystemSection = () => {
const handleSaveOpenAIConfig = async () => {
try {
await api.upsertSystemSetting({
- name: "openAIConfig",
+ name: "openai-config",
value: JSON.stringify(openAIConfig),
});
} catch (error) {
@@ -127,7 +127,7 @@ const SystemSection = () => {
const handleSaveAdditionalStyle = async () => {
try {
await api.upsertSystemSetting({
- name: "additionalStyle",
+ name: "additional-style",
value: JSON.stringify(state.additionalStyle),
});
} catch (error) {
@@ -147,7 +147,7 @@ const SystemSection = () => {
const handleSaveAdditionalScript = async () => {
try {
await api.upsertSystemSetting({
- name: "additionalScript",
+ name: "additional-script",
value: JSON.stringify(state.additionalScript),
});
} catch (error) {
@@ -164,7 +164,7 @@ const SystemSection = () => {
});
globalStore.setSystemStatus({ disablePublicMemos: value });
await api.upsertSystemSetting({
- name: "disablePublicMemos",
+ name: "disable-public-memos",
value: JSON.stringify(value),
});
};
diff --git a/web/src/components/UpdateCustomizedProfileDialog.tsx b/web/src/components/UpdateCustomizedProfileDialog.tsx
index db594cb0e..f904e84ac 100644
--- a/web/src/components/UpdateCustomizedProfileDialog.tsx
+++ b/web/src/components/UpdateCustomizedProfileDialog.tsx
@@ -83,7 +83,7 @@ const UpdateCustomizedProfileDialog: React.FC<Props> = ({ destroy }: Props) => {
try {
await api.upsertSystemSetting({
- name: "customizedProfile",
+ name: "customized-profile",
value: JSON.stringify(state),
});
await globalStore.fetchSystemStatus();
diff --git a/web/src/components/UpdateLocalStorageDialog.tsx b/web/src/components/UpdateLocalStorageDialog.tsx
index d8b723ec0..1a6e89763 100644
--- a/web/src/components/UpdateLocalStorageDialog.tsx
+++ b/web/src/components/UpdateLocalStorageDialog.tsx
@@ -23,7 +23,7 @@ const UpdateLocalStorageDialog: React.FC<Props> = (props: Props) => {
const handleConfirmBtnClick = async () => {
try {
await api.upsertSystemSetting({
- name: "localStoragePath",
+ name: "local-storage-path",
value: JSON.stringify(path),
});
await globalStore.fetchSystemStatus();