diff --git a/api/v1/system.go b/api/v1/system.go index 109e7f31..f3654aa8 100644 --- a/api/v1/system.go +++ b/api/v1/system.go @@ -104,7 +104,7 @@ func (s *APIV1Service) GetSystemStatus(c echo.Context) error { return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find system setting list").SetInternal(err) } for _, systemSetting := range systemSettingList { - if systemSetting.Name == SystemSettingServerIDName.String() || systemSetting.Name == SystemSettingSecretSessionName.String() || systemSetting.Name == SystemSettingTelegramBotTokenName.String() { + if systemSetting.Name == SystemSettingServerIDName.String() || systemSetting.Name == SystemSettingSecretSessionName.String() || systemSetting.Name == SystemSettingTelegramBotTokenName.String() || systemSetting.Name == SystemSettingInstanceURLName.String() { continue } diff --git a/api/v1/system_setting.go b/api/v1/system_setting.go index 708e812b..a354d747 100644 --- a/api/v1/system_setting.go +++ b/api/v1/system_setting.go @@ -42,6 +42,8 @@ const ( SystemSettingMemoDisplayWithUpdatedTsName SystemSettingName = "memo-display-with-updated-ts" // SystemSettingAutoBackupIntervalName is the name of auto backup interval as seconds. SystemSettingAutoBackupIntervalName SystemSettingName = "auto-backup-interval" + // SystemSettingInstanceURLName is the name of instance url setting. + SystemSettingInstanceURLName SystemSettingName = "instance-url" ) const systemSettingUnmarshalError = `failed to unmarshal value from system setting "%v"` @@ -271,6 +273,7 @@ func (upsert UpsertSystemSettingRequest) Validate() error { if err := json.Unmarshal([]byte(upsert.Value), &value); err != nil { return errors.Errorf(systemSettingUnmarshalError, settingName) } + case SystemSettingInstanceURLName: default: return errors.New("invalid system setting name") } diff --git a/web/src/components/Settings/SystemSection.tsx b/web/src/components/Settings/SystemSection.tsx index 0310fae8..4e0fb2f2 100644 --- a/web/src/components/Settings/SystemSection.tsx +++ b/web/src/components/Settings/SystemSection.tsx @@ -40,6 +40,7 @@ const SystemSection = () => { memoDisplayWithUpdatedTs: systemStatus.memoDisplayWithUpdatedTs, }); const [telegramBotToken, setTelegramBotToken] = useState(""); + const [instanceUrl, setInstanceUrl] = useState(""); useEffect(() => { globalStore.fetchSystemStatus(); @@ -51,6 +52,10 @@ const SystemSection = () => { if (telegramBotSetting) { setTelegramBotToken(telegramBotSetting.value); } + const instanceUrlSetting = systemSettings.find((setting) => setting.name === "instance-url"); + if (instanceUrlSetting) { + setInstanceUrl(instanceUrlSetting.value); + } }); }, []); @@ -117,6 +122,24 @@ const SystemSection = () => { toast.success(t("message.succeed-vacuum-database")); }; + const handleInstanceUrlChanged = (value: string) => { + setInstanceUrl(value); + }; + + const handleSaveInstanceUrl = async () => { + try { + await api.upsertSystemSetting({ + name: "instance-url", + value: instanceUrl, + }); + } catch (error: any) { + console.error(error); + toast.error(error.response.data.message); + return; + } + toast.success("Instance URL updated"); + }; + const handleTelegramBotTokenChanged = (value: string) => { setTelegramBotToken(value); }; @@ -314,6 +337,27 @@ const SystemSection = () => { /> +
+
+
+ Instance URL +
+
+ +
+ handleInstanceUrlChanged(event.target.value)} + /> +