mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
feat: add user setting field (#2054)
This commit is contained in:
@@ -12,8 +12,18 @@ import (
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func autoBackup(ctx context.Context, s *store.Store) {
|
||||
intervalStr := s.GetSystemSettingValueWithDefault(&ctx, apiv1.SystemSettingAutoBackupIntervalName.String(), "")
|
||||
type BackupRunner struct {
|
||||
Store *store.Store
|
||||
}
|
||||
|
||||
func NewBackupRunner(store *store.Store) *BackupRunner {
|
||||
return &BackupRunner{
|
||||
Store: store,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *BackupRunner) Run(ctx context.Context) {
|
||||
intervalStr := r.Store.GetSystemSettingValueWithDefault(&ctx, apiv1.SystemSettingAutoBackupIntervalName.String(), "")
|
||||
if intervalStr == "" {
|
||||
log.Info("no SystemSettingAutoBackupIntervalName setting, disable auto backup")
|
||||
return
|
||||
@@ -38,9 +48,9 @@ func autoBackup(ctx context.Context, s *store.Store) {
|
||||
case t = <-ticker.C:
|
||||
}
|
||||
|
||||
filename := s.Profile.DSN + t.Format("-20060102-150405.bak")
|
||||
filename := r.Store.Profile.DSN + t.Format("-20060102-150405.bak")
|
||||
log.Info(fmt.Sprintf("create backup to %s", filename))
|
||||
err := s.BackupTo(ctx, filename)
|
||||
err := r.Store.BackupTo(ctx, filename)
|
||||
if err != nil {
|
||||
log.Error("fail to create backup", zap.Error(err))
|
||||
}
|
||||
|
@@ -32,7 +32,9 @@ type Server struct {
|
||||
Profile *profile.Profile
|
||||
Store *store.Store
|
||||
|
||||
telegramBot *telegram.Bot
|
||||
// Asynchronous runners.
|
||||
backupRunner *BackupRunner
|
||||
telegramBot *telegram.Bot
|
||||
}
|
||||
|
||||
func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store) (*Server, error) {
|
||||
@@ -45,10 +47,11 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store
|
||||
e: e,
|
||||
Store: store,
|
||||
Profile: profile,
|
||||
}
|
||||
|
||||
telegramBotHandler := newTelegramHandler(store)
|
||||
s.telegramBot = telegram.NewBotWithHandler(telegramBotHandler)
|
||||
// Asynchronous runners.
|
||||
backupRunner: NewBackupRunner(store),
|
||||
telegramBot: telegram.NewBotWithHandler(newTelegramHandler(store)),
|
||||
}
|
||||
|
||||
e.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
|
||||
Format: `{"time":"${time_rfc3339}",` +
|
||||
@@ -116,7 +119,7 @@ func (s *Server) Start(ctx context.Context) error {
|
||||
}
|
||||
|
||||
go s.telegramBot.Start(ctx)
|
||||
go autoBackup(ctx, s.Store)
|
||||
go s.backupRunner.Run(ctx)
|
||||
|
||||
// Start gRPC server.
|
||||
listen, err := net.Listen("tcp", fmt.Sprintf(":%d", s.Profile.Port+1))
|
||||
|
Reference in New Issue
Block a user