Skip to content

Commit 091f581

Browse files
committed
Merge branch 'main' of https://github.com/krau/SaveAny-Bot
2 parents b431fa0 + 8b86330 commit 091f581

File tree

12 files changed

+460
-1
lines changed

12 files changed

+460
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
- S3
3636
- WebDAV
3737
- Local filesystem
38+
- Rclone (via command line)
3839
- Telegram (re-upload to specified chats)
3940

4041
## 📦 Quick Start

README_zh.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
- S3
3434
- WebDAV
3535
- 本地磁盘
36+
- Rclone
3637
- Telegram (重传回指定聊天)
3738

3839
## 快速开始

config/storage/factory.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var storageFactories = map[storenum.StorageType]func(cfg *BaseConfig) (StorageCo
1616
storenum.Minio: createStorageConfig(&MinioStorageConfig{}),
1717
storenum.S3: createStorageConfig(&S3StorageConfig{}),
1818
storenum.Telegram: createStorageConfig(&TelegramStorageConfig{}),
19+
storenum.Rclone: createStorageConfig(&RcloneStorageConfig{}),
1920
}
2021

2122
func createStorageConfig(configType StorageConfig) func(cfg *BaseConfig) (StorageConfig, error) {

config/storage/rclone.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package storage
2+
3+
import (
4+
"fmt"
5+
6+
storenum "github.com/krau/SaveAny-Bot/pkg/enums/storage"
7+
)
8+
9+
type RcloneStorageConfig struct {
10+
BaseConfig
11+
// The name of the remote as defined in rclone config
12+
Remote string `toml:"remote" mapstructure:"remote" json:"remote"`
13+
BasePath string `toml:"base_path" mapstructure:"base_path" json:"base_path"`
14+
// The path to the rclone config file, if not using the default
15+
ConfigPath string `toml:"config_path" mapstructure:"config_path" json:"config_path"`
16+
// Additional flags to pass to rclone commands
17+
Flags []string `toml:"flags" mapstructure:"flags" json:"flags"`
18+
}
19+
20+
func (r *RcloneStorageConfig) Validate() error {
21+
if r.Remote == "" {
22+
return fmt.Errorf("remote is required for rclone storage")
23+
}
24+
return nil
25+
}
26+
27+
func (r *RcloneStorageConfig) GetType() storenum.StorageType {
28+
return storenum.Rclone
29+
}
30+
31+
func (r *RcloneStorageConfig) GetName() string {
32+
return r.Name
33+
}

docs/content/en/deployment/configuration/storages.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,60 @@ chat_id = "123456789" # Telegram chat ID, the bot will send files to this chat
8080
force_file = false # Force sending as file, default is false
8181
skip_large = false # Skip large files, default is false. If enabled, files exceeding Telegram's limit will not be uploaded.
8282
spilt_size_mb = 2000 # Split size in MB, default is 2000 MB (2 GB). Files larger than this will be split into multiple parts (zip format). Ignored when skip_large is true.
83+
```
84+
85+
## Rclone
86+
87+
`type=rclone`
88+
89+
Supports multiple cloud storage services through the [rclone](https://rclone.org/) command-line tool. You need to install rclone and configure remote storage first.
90+
91+
```toml
92+
# Remote name configured in rclone, can be any remote defined in rclone.conf
93+
remote = "mydrive"
94+
# Base path in the remote storage, all files will be stored under this path
95+
base_path = "/telegram"
96+
# Path to rclone config file, optional, leave empty to use default path (~/.config/rclone/rclone.conf)
97+
config_path = ""
98+
# Additional flags to pass to rclone commands, optional
99+
flags = ["--transfers", "4", "--checkers", "8"]
100+
```
101+
102+
### Configuring rclone Remote
103+
104+
First, you need to configure an rclone remote. Run `rclone config` for interactive configuration, or directly edit the `rclone.conf` file.
105+
106+
rclone supports many cloud storage services, including but not limited to:
107+
- Google Drive
108+
- Dropbox
109+
- OneDrive
110+
- Amazon S3 and compatible services
111+
- SFTP
112+
- FTP
113+
- For more services, please refer to the [rclone official documentation](https://rclone.org/overview/)
114+
115+
### Usage Examples
116+
117+
After configuring Google Drive, you can configure the storage like this:
118+
119+
```toml
120+
[[storages]]
121+
name = "GoogleDrive"
122+
type = "rclone"
123+
enable = true
124+
remote = "gdrive"
125+
base_path = "/SaveAnyBot"
126+
```
127+
128+
If using a custom rclone config file:
129+
130+
```toml
131+
[[storages]]
132+
name = "MyRemote"
133+
type = "rclone"
134+
enable = true
135+
remote = "myremote"
136+
base_path = "/backup"
137+
config_path = "/path/to/rclone.conf"
138+
flags = ["--progress"]
83139
```

docs/content/zh/_index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ title: 介绍
2929
- S3
3030
- WebDAV
3131
- 本地磁盘
32+
- Rclone (通过命令行调用)
3233
- Telegram (重传回指定聊天)
3334

3435
## [贡献者](https://github.com/krau/SaveAny-Bot/graphs/contributors)

docs/content/zh/deployment/configuration/storages.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,60 @@ skip_large = false
8686
# 超过该大小的文件将被分割成多个部分上传.(使用 zip 格式)
8787
# 当 skip_large 启用时, 该选项无效.
8888
spilt_size_mb = 2000
89+
```
90+
91+
## Rclone
92+
93+
`type=rclone`
94+
95+
通过 [rclone](https://rclone.org/) 命令行工具支持多种云存储服务. 需要先安装 rclone 并配置好远程存储.
96+
97+
```toml
98+
# rclone 配置的远程名称, 可以是任何在 rclone.conf 中配置的远程
99+
remote = "mydrive"
100+
# 在远程存储中的基础路径, 所有文件将存储在此路径下
101+
base_path = "/telegram"
102+
# rclone 配置文件的路径, 可选, 留空使用默认路径 (~/.config/rclone/rclone.conf)
103+
config_path = ""
104+
# 传递给 rclone 命令的额外参数, 可选
105+
flags = ["--transfers", "4", "--checkers", "8"]
106+
```
107+
108+
### 配置 rclone 远程
109+
110+
首先需要配置 rclone 远程, 运行 `rclone config` 命令进行交互式配置, 或直接编辑 `rclone.conf` 文件.
111+
112+
rclone 支持多种云存储服务, 包括但不限于:
113+
- Google Drive
114+
- Dropbox
115+
- OneDrive
116+
- Amazon S3 及兼容服务
117+
- SFTP
118+
- FTP
119+
- 更多服务请参考 [rclone 官方文档](https://rclone.org/overview/)
120+
121+
### 使用示例
122+
123+
配置 Google Drive 后, 可以这样配置存储:
124+
125+
```toml
126+
[[storages]]
127+
name = "GoogleDrive"
128+
type = "rclone"
129+
enable = true
130+
remote = "gdrive"
131+
base_path = "/SaveAnyBot"
132+
```
133+
134+
如果使用自定义的 rclone 配置文件:
135+
136+
```toml
137+
[[storages]]
138+
name = "MyRemote"
139+
type = "rclone"
140+
enable = true
141+
remote = "myremote"
142+
base_path = "/backup"
143+
config_path = "/path/to/rclone.conf"
144+
flags = ["--progress"]
89145
```

pkg/enums/storage/storages.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ package storage
44

55
// StorageType
66
/* ENUM(
7-
local, webdav, alist, minio, telegram, s3
7+
local, webdav, alist, minio, telegram, s3, rclone
88
) */
99
type StorageType string

pkg/enums/storage/storages_enum.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

storage/rclone/errs.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package rclone
2+
3+
import "errors"
4+
5+
var (
6+
ErrRcloneNotFound = errors.New("rclone: rclone command not found in PATH")
7+
ErrRemoteNotFound = errors.New("rclone: remote not found")
8+
ErrFailedToSaveFile = errors.New("rclone: failed to save file")
9+
ErrFailedToListFiles = errors.New("rclone: failed to list files")
10+
ErrFailedToOpenFile = errors.New("rclone: failed to open file")
11+
ErrFailedToCheckFile = errors.New("rclone: failed to check file exists")
12+
ErrFailedToCreateDir = errors.New("rclone: failed to create directory")
13+
ErrCommandFailed = errors.New("rclone: command execution failed")
14+
)

0 commit comments

Comments
 (0)