feat: add support for auto backup db file (#1950)

Add support for auto backup db file
This commit is contained in:
Athurg Gooth
2023-07-14 20:05:07 +08:00
committed by GitHub
parent 39351970d0
commit d9b3501fae
6 changed files with 108 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"strconv"
"strings"
"github.com/labstack/echo/v4"
@ -39,6 +40,8 @@ const (
SystemSettingMemoDisplayWithUpdatedTsName SystemSettingName = "memo-display-with-updated-ts"
// SystemSettingOpenAIConfigName is the name of OpenAI config.
SystemSettingOpenAIConfigName SystemSettingName = "openai-config"
// SystemSettingAutoBackupIntervalName is the name of auto backup interval as seconds.
SystemSettingAutoBackupIntervalName SystemSettingName = "auto-backup-interval"
)
// CustomizedProfile is the struct definition for SystemSettingCustomizedProfileName system setting item.
@ -139,6 +142,20 @@ func (upsert UpsertSystemSettingRequest) Validate() error {
if err := json.Unmarshal([]byte(upsert.Value), &value); err != nil {
return fmt.Errorf(systemSettingUnmarshalError, settingName)
}
case SystemSettingAutoBackupIntervalName:
var value string
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")
}
}
case SystemSettingTelegramBotTokenName:
if upsert.Value == "" {
return nil