mirror of
https://github.com/Awuqing/BackupX.git
synced 2026-05-11 18:10:23 +08:00
1. 失败自动重试:rclone Pacer 指数退避,默认 10 次底层 HTTP 重试 2. 带宽限制:配置 bandwidth_limit + Settings 运行时可调 3. 上传实时进度:progressReader + LogHub SSE 推送字节级进度/速率 4. 存储空间查询:StorageAbout 可选接口,GetUsage 返回远端真实空间 5. 全 rclone 后端:backend/all 引入 70+ 后端,新增 rclone 存储类型, API 驱动的可搜索后端选择器 + 动态配置表单
56 lines
1.4 KiB
Go
56 lines
1.4 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
|
|
"backupx/server/internal/apperror"
|
|
"backupx/server/internal/model"
|
|
"backupx/server/internal/repository"
|
|
)
|
|
|
|
type SettingsService struct {
|
|
configs repository.SystemConfigRepository
|
|
}
|
|
|
|
func NewSettingsService(configs repository.SystemConfigRepository) *SettingsService {
|
|
return &SettingsService{configs: configs}
|
|
}
|
|
|
|
// settingsKeys lists all user-editable setting keys.
|
|
var settingsKeys = []string{
|
|
"site_name",
|
|
"language",
|
|
"timezone",
|
|
"backup_notification_enabled",
|
|
"bandwidth_limit",
|
|
}
|
|
|
|
func (s *SettingsService) GetAll(ctx context.Context) (map[string]string, error) {
|
|
items, err := s.configs.List(ctx)
|
|
if err != nil {
|
|
return nil, apperror.Internal("SETTINGS_LIST_FAILED", "无法获取系统设置", err)
|
|
}
|
|
result := make(map[string]string, len(items))
|
|
for _, item := range items {
|
|
result[item.Key] = item.Value
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
func (s *SettingsService) Update(ctx context.Context, settings map[string]string) (map[string]string, error) {
|
|
allowed := make(map[string]bool, len(settingsKeys))
|
|
for _, key := range settingsKeys {
|
|
allowed[key] = true
|
|
}
|
|
for key, value := range settings {
|
|
if !allowed[key] {
|
|
continue
|
|
}
|
|
item := &model.SystemConfig{Key: key, Value: value}
|
|
if err := s.configs.Upsert(ctx, item); err != nil {
|
|
return nil, apperror.Internal("SETTINGS_UPDATE_FAILED", "无法更新系统设置", err)
|
|
}
|
|
}
|
|
return s.GetAll(ctx)
|
|
}
|