Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
336b3200
Unverified
Commit
336b3200
authored
Jul 19, 2023
by
Athurg Gooth
Committed by
GitHub
Jul 19, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add AutoBackupInterval in SystemSetting (#1989)
Add AutoBackupInterval in SystemSetting page
parent
7b5c13b7
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
58 additions
and
10 deletions
+58
-10
system.go
api/v1/system.go
+5
-0
system_setting.go
api/v1/system_setting.go
+3
-10
SystemSection.tsx
web/src/components/Settings/SystemSection.tsx
+44
-0
en.json
web/src/locales/en.json
+2
-0
zh-Hans.json
web/src/locales/zh-Hans.json
+2
-0
global.ts
web/src/store/module/global.ts
+1
-0
system.d.ts
web/src/types/modules/system.d.ts
+1
-0
No files found.
api/v1/system.go
View file @
336b3200
...
...
@@ -23,6 +23,8 @@ type SystemStatus struct {
DisablePublicMemos
bool
`json:"disablePublicMemos"`
// Max upload size.
MaxUploadSizeMiB
int
`json:"maxUploadSizeMiB"`
// Auto Backup Interval.
AutoBackupInterval
int
`json:"autoBackupInterval"`
// Additional style.
AdditionalStyle
string
`json:"additionalStyle"`
// Additional script.
...
...
@@ -50,6 +52,7 @@ func (s *APIV1Service) registerSystemRoutes(g *echo.Group) {
AllowSignUp
:
false
,
DisablePublicMemos
:
false
,
MaxUploadSizeMiB
:
32
,
AutoBackupInterval
:
0
,
AdditionalStyle
:
""
,
AdditionalScript
:
""
,
CustomizedProfile
:
CustomizedProfile
{
...
...
@@ -103,6 +106,8 @@ func (s *APIV1Service) registerSystemRoutes(g *echo.Group) {
systemStatus
.
DisablePublicMemos
=
baseValue
.
(
bool
)
case
SystemSettingMaxUploadSizeMiBName
.
String
()
:
systemStatus
.
MaxUploadSizeMiB
=
int
(
baseValue
.
(
float64
))
case
SystemSettingAutoBackupIntervalName
.
String
()
:
systemStatus
.
AutoBackupInterval
=
int
(
baseValue
.
(
float64
))
case
SystemSettingAdditionalStyleName
.
String
()
:
systemStatus
.
AdditionalStyle
=
baseValue
.
(
string
)
case
SystemSettingAdditionalScriptName
.
String
()
:
...
...
api/v1/system_setting.go
View file @
336b3200
...
...
@@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"net/http"
"strconv"
"strings"
"github.com/labstack/echo/v4"
...
...
@@ -143,18 +142,12 @@ func (upsert UpsertSystemSettingRequest) Validate() error {
return
fmt
.
Errorf
(
systemSettingUnmarshalError
,
settingName
)
}
case
SystemSettingAutoBackupIntervalName
:
var
value
string
var
value
int
if
err
:=
json
.
Unmarshal
([]
byte
(
upsert
.
Value
),
&
value
);
err
!=
nil
{
return
fmt
.
Errorf
(
systemSettingUnmarshalError
,
settingName
)
}
if
value
!=
""
{
v
,
err
:=
strconv
.
Atoi
(
value
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
systemSettingUnmarshalError
,
settingName
)
}
if
v
<
0
{
return
fmt
.
Errorf
(
"backup interval should > 0"
)
}
if
value
<
0
{
return
fmt
.
Errorf
(
"must be positive"
)
}
case
SystemSettingTelegramBotTokenName
:
if
upsert
.
Value
==
""
{
...
...
web/src/components/Settings/SystemSection.tsx
View file @
336b3200
...
...
@@ -17,6 +17,7 @@ interface State {
additionalStyle
:
string
;
additionalScript
:
string
;
maxUploadSizeMiB
:
number
;
autoBackupInterval
:
number
;
memoDisplayWithUpdatedTs
:
boolean
;
}
...
...
@@ -31,6 +32,7 @@ const SystemSection = () => {
additionalScript
:
systemStatus
.
additionalScript
,
disablePublicMemos
:
systemStatus
.
disablePublicMemos
,
maxUploadSizeMiB
:
systemStatus
.
maxUploadSizeMiB
,
autoBackupInterval
:
systemStatus
.
autoBackupInterval
,
memoDisplayWithUpdatedTs
:
systemStatus
.
memoDisplayWithUpdatedTs
,
});
const
[
telegramBotToken
,
setTelegramBotToken
]
=
useState
<
string
>
(
""
);
...
...
@@ -57,6 +59,7 @@ const SystemSection = () => {
additionalScript
:
systemStatus
.
additionalScript
,
disablePublicMemos
:
systemStatus
.
disablePublicMemos
,
maxUploadSizeMiB
:
systemStatus
.
maxUploadSizeMiB
,
autoBackupInterval
:
systemStatus
.
autoBackupInterval
,
memoDisplayWithUpdatedTs
:
systemStatus
.
memoDisplayWithUpdatedTs
,
});
},
[
systemStatus
]);
...
...
@@ -194,6 +197,30 @@ const SystemSection = () => {
event
.
target
.
select
();
};
const
handleAutoBackupIntervalChanged
=
async
(
event
:
React
.
FocusEvent
<
HTMLInputElement
>
)
=>
{
// fixes cursor skipping position on mobile
event
.
target
.
selectionEnd
=
event
.
target
.
value
.
length
;
let
num
=
parseInt
(
event
.
target
.
value
);
if
(
Number
.
isNaN
(
num
))
{
num
=
0
;
}
setState
({
...
state
,
autoBackupInterval
:
num
,
});
event
.
target
.
value
=
num
.
toString
();
globalStore
.
setSystemStatus
({
autoBackupInterval
:
num
});
await
api
.
upsertSystemSetting
({
name
:
"auto-backup-interval"
,
value
:
JSON
.
stringify
(
num
),
});
};
const
handleAutoBackupIntervalFocus
=
(
event
:
React
.
FocusEvent
<
HTMLInputElement
>
)
=>
{
event
.
target
.
select
();
};
return
(
<
div
className=
"section-container system-section-container"
>
<
p
className=
"title-text"
>
{
t
(
"common.basic"
)
}
</
p
>
...
...
@@ -239,6 +266,23 @@ const SystemSection = () => {
onChange=
{
handleMaxUploadSizeChanged
}
/>
</
div
>
<
div
className=
"form-label"
>
<
div
className=
"flex flex-row items-center"
>
<
span
className=
"text-sm mr-1"
>
{
t
(
"setting.system-section.auto-backup-interval"
)
}
</
span
>
<
Tooltip
title=
{
t
(
"setting.system-section.auto-backup-interval-hint"
)
}
placement=
"top"
>
<
Icon
.
HelpCircle
className=
"w-4 h-auto"
/>
</
Tooltip
>
</
div
>
<
Input
className=
"w-16"
sx=
{
{
fontFamily
:
"monospace"
,
}
}
defaultValue=
{
state
.
autoBackupInterval
}
onFocus=
{
handleAutoBackupIntervalFocus
}
onChange=
{
handleAutoBackupIntervalChanged
}
/>
</
div
>
<
Divider
className=
"!mt-3 !my-4"
/>
<
div
className=
"form-label"
>
<
div
className=
"flex flex-row items-center"
>
...
...
web/src/locales/en.json
View file @
336b3200
...
...
@@ -260,6 +260,8 @@
"disable-public-memos"
:
"Disable public memos"
,
"max-upload-size"
:
"Maximum upload size (MiB)"
,
"max-upload-size-hint"
:
"Recommended value is 32 MiB."
,
"auto-backup-interval"
:
"Auto backup interval (seconds)"
,
"auto-backup-interval-hint"
:
"Set 0 to disable auto backup. Reboot is required after changing this value."
,
"additional-style"
:
"Additional style"
,
"additional-script"
:
"Additional script"
,
"additional-style-placeholder"
:
"Additional CSS code"
,
...
...
web/src/locales/zh-Hans.json
View file @
336b3200
...
...
@@ -435,6 +435,8 @@
"server-name"
:
"服务名称"
,
"max-upload-size-hint"
:
"建议值为 32 MiB。"
,
"max-upload-size"
:
"最大上传大小 (MiB)"
,
"auto-backup-interval"
:
"自动备份间隔(单位:秒)"
,
"auto-backup-interval-hint"
:
"设置为0禁止自动备份,重启后生效"
,
"display-with-updated-time"
:
"Display with updated time"
}
},
...
...
web/src/store/module/global.ts
View file @
336b3200
...
...
@@ -13,6 +13,7 @@ export const initialGlobalState = async () => {
allowSignUp
:
false
,
disablePublicMemos
:
false
,
maxUploadSizeMiB
:
0
,
autoBackupInterval
:
0
,
additionalStyle
:
""
,
additionalScript
:
""
,
memoDisplayWithUpdatedTs
:
false
,
...
...
web/src/types/modules/system.d.ts
View file @
336b3200
...
...
@@ -20,6 +20,7 @@ interface SystemStatus {
allowSignUp
:
boolean
;
disablePublicMemos
:
boolean
;
maxUploadSizeMiB
:
number
;
autoBackupInterval
:
number
;
additionalStyle
:
string
;
additionalScript
:
string
;
customizedProfile
:
CustomizedProfile
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment