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: add instance url system setting

Steven89ef9b8531fd
diff --git a/api/v1/system.go b/api/v1/system.go
index 109e7f319..f3654aa80 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 708e812b4..a354d747d 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 0310fae86..4e0fb2f20 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<string>("");
+ const [instanceUrl, setInstanceUrl] = useState<string>("");
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 = () => {
/>
</div>
<Divider className="!mt-3 !my-4" />
+ <div className="form-label">
+ <div className="flex flex-row items-center">
+ <div className="w-auto flex items-center">
+ <span className="text-sm mr-1">Instance URL</span>
+ </div>
+ </div>
+ <Button variant="outlined" color="neutral" onClick={handleSaveInstanceUrl}>
+ {t("common.save")}
+ </Button>
+ </div>
+ <Input
+ className="w-full"
+ sx={{
+ fontFamily: "monospace",
+ fontSize: "14px",
+ }}
+ placeholder={"Your instance url, should be started with http:// or https://"}
+ value={instanceUrl}
+ onChange={(event) => handleInstanceUrlChanged(event.target.value)}
+ />
+ <Divider className="!mt-3 !my-4" />
<div className="form-label">
<div className="flex flex-row items-center">
<div className="w-auto flex items-center">