mirror of
https://github.com/Awuqing/BackupX.git
synced 2026-05-11 09:59:56 +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 驱动的可搜索后端选择器 + 动态配置表单
37 lines
1.1 KiB
Go
37 lines
1.1 KiB
Go
package rclone
|
||
|
||
import (
|
||
"context"
|
||
|
||
"github.com/rclone/rclone/fs"
|
||
"github.com/rclone/rclone/fs/accounting"
|
||
)
|
||
|
||
// TransferConfig 控制 rclone 传输层行为。
|
||
type TransferConfig struct {
|
||
LowLevelRetries int // 底层 HTTP 请求重试次数,0 保持 rclone 默认(10)
|
||
BandwidthLimit string // 带宽限制,如 "10M"、"1M:500k"(上传:下载),空或 "0" 不限
|
||
}
|
||
|
||
// ConfiguredContext 返回注入了 rclone 传输配置的 context。
|
||
// 各 rclone 后端在 fs.NewFs 时读取 context 中的配置,自动应用重试和限速。
|
||
func ConfiguredContext(ctx context.Context, cfg TransferConfig) context.Context {
|
||
ctx, ci := fs.AddConfig(ctx)
|
||
if cfg.LowLevelRetries > 0 {
|
||
ci.LowLevelRetries = cfg.LowLevelRetries
|
||
}
|
||
if cfg.BandwidthLimit != "" && cfg.BandwidthLimit != "0" {
|
||
var bwTable fs.BwTimetable
|
||
if err := bwTable.Set(cfg.BandwidthLimit); err == nil {
|
||
ci.BwLimit = bwTable
|
||
}
|
||
}
|
||
return ctx
|
||
}
|
||
|
||
// StartAccounting 初始化 rclone 的传输统计和令牌桶限速系统。
|
||
// 应在应用启动时调用一次。
|
||
func StartAccounting(ctx context.Context) {
|
||
accounting.Start(ctx)
|
||
}
|