mirror of
https://github.com/usememos/memos.git
synced 2025-03-04 01:04:38 +08:00
chore: add instance url system setting
This commit is contained in:
parent
56b55ad941
commit
89ef9b8531
3 changed files with 48 additions and 1 deletions
|
@ -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)
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find system setting list").SetInternal(err)
|
||||||
}
|
}
|
||||||
for _, systemSetting := range systemSettingList {
|
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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,8 @@ const (
|
||||||
SystemSettingMemoDisplayWithUpdatedTsName SystemSettingName = "memo-display-with-updated-ts"
|
SystemSettingMemoDisplayWithUpdatedTsName SystemSettingName = "memo-display-with-updated-ts"
|
||||||
// SystemSettingAutoBackupIntervalName is the name of auto backup interval as seconds.
|
// SystemSettingAutoBackupIntervalName is the name of auto backup interval as seconds.
|
||||||
SystemSettingAutoBackupIntervalName SystemSettingName = "auto-backup-interval"
|
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"`
|
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 {
|
if err := json.Unmarshal([]byte(upsert.Value), &value); err != nil {
|
||||||
return errors.Errorf(systemSettingUnmarshalError, settingName)
|
return errors.Errorf(systemSettingUnmarshalError, settingName)
|
||||||
}
|
}
|
||||||
|
case SystemSettingInstanceURLName:
|
||||||
default:
|
default:
|
||||||
return errors.New("invalid system setting name")
|
return errors.New("invalid system setting name")
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ const SystemSection = () => {
|
||||||
memoDisplayWithUpdatedTs: systemStatus.memoDisplayWithUpdatedTs,
|
memoDisplayWithUpdatedTs: systemStatus.memoDisplayWithUpdatedTs,
|
||||||
});
|
});
|
||||||
const [telegramBotToken, setTelegramBotToken] = useState<string>("");
|
const [telegramBotToken, setTelegramBotToken] = useState<string>("");
|
||||||
|
const [instanceUrl, setInstanceUrl] = useState<string>("");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
globalStore.fetchSystemStatus();
|
globalStore.fetchSystemStatus();
|
||||||
|
@ -51,6 +52,10 @@ const SystemSection = () => {
|
||||||
if (telegramBotSetting) {
|
if (telegramBotSetting) {
|
||||||
setTelegramBotToken(telegramBotSetting.value);
|
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"));
|
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) => {
|
const handleTelegramBotTokenChanged = (value: string) => {
|
||||||
setTelegramBotToken(value);
|
setTelegramBotToken(value);
|
||||||
};
|
};
|
||||||
|
@ -314,6 +337,27 @@ const SystemSection = () => {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<Divider className="!mt-3 !my-4" />
|
<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="form-label">
|
||||||
<div className="flex flex-row items-center">
|
<div className="flex flex-row items-center">
|
||||||
<div className="w-auto flex items-center">
|
<div className="w-auto flex items-center">
|
||||||
|
|
Loading…
Reference in a new issue