lsdrive 是一个高性能、功能丰富的文件管理系统。
- 多云存储支持 - 阿里云盘、OneDrive、百度网盘、Google Drive 等
- 六边形架构 - 模块化设计,易于扩展
- 高性能 - Rust + Tokio 异步运行时
- WebDAV 服务器 - 完整的 WebDAV 协议支持
- 文件预览 - 图片、视频、文档在线预览
- 离线下载 - 多线程下载,断点续传
- 文件分享 - 灵活的分享权限和过期控制
- REST + GraphQL API - 双 API 架构
- JWT 认证 - 安全的用户认证系统
- 现代化前端 - React + TypeScript + shadcn/ui
- Docker 支持 - 完整的容器化部署方案
- 实时监控 - 性能监控和优化建议
# 克隆项目 git clone https://github.com/your-repo/lsdrive.git cd lsdrive # 使用 Docker Compose 启动 docker-compose up -d # 或使用部署脚本 ./docker/deploy.sh
# 安装 Rust curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh # 克隆并构建 git clone https://github.com/your-repo/lsdrive.git cd lsdrive cargo build --release # 运行 ./target/release/lsdrive server
cd web
npm install
npm run dev创建配置文件 lsdrive.toml:
# 数据库配置 database_url = "sqlite:./lsdrive.db" # 服务器配置 [server] host = "127.0.0.1" port = 8080 # 存储后端配置 [storage_backends.local] type = "Local" root_path = "./storage"
[storage_backends.aliyun] type = "AliyunDrive" refresh_token = "your_refresh_token" client_id = "your_client_id" client_secret = "your_client_secret"
[storage_backends.onedrive] type = "OneDrive" client_id = "your_client_id" client_secret = "your_client_secret" redirect_uri = "http://localhost:8080/auth/callback"
# 获取文件列表 curl http://localhost:8080/api/files # 创建分享 curl -X POST http://localhost:8080/api/shares \ -H "Content-Type: application/json" \ -d '{"name":"test.txt","path":"/test.txt"}'
query { files(path: "/") { edges { node { id name size isDir } } } }
# 挂载为网络驱动器 # Windows: \\localhost:8080\webdav # macOS/Linux: http://localhost:8080/webdav
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Web UI │ │ REST API │ │ GraphQL API │
│ (React) │ │ (Axum) │ │ (async-graphql)│
└─────────────────┘ └─────────────────┘ └─────────────────┘
│ │ │
└───────────────────────┼───────────────────────┘
│
┌─────────────────────────────────┼─────────────────────────────────┐
│ 应用服务层 │ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐│
│ │ 文件管理 │ │ 用户认证 │ │ 分享管理 │ │ 下载管理 ││
│ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘│
└─────────────────────────────────┼─────────────────────────────────┘
│
┌─────────────────────────────────┼─────────────────────────────────┐
│ VFS 引擎 │ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐│
│ │ 本地存储 │ │ 阿里云盘 │ │ OneDrive │ │ 百度网盘 ││
│ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘│
└─────────────────────────────────────────────────────────────────┘
lsdrive/
├── crates/ # Rust Crates
│ ├── lsdrive-core/ # 核心库
│ ├── lsdrive-vfs/ # VFS 引擎
│ ├── lsdrive-api/ # API 服务
│ ├── lsdrive-storage-*/ # 存储适配器
│ ├── lsdrive-webdav/ # WebDAV 服务
│ ├── lsdrive-preview/ # 文件预览
│ ├── lsdrive-downloader/ # 下载管理
│ ├── lsdrive-share/ # 分享管理
│ └── lsdrive-cli/ # 命令行工具
├── web/ # 前端代码
├── tests/ # 测试文件
├── docker/ # Docker 配置
└── docs/ # 文档
- 创建新的 crate:
cargo new --lib crates/lsdrive-storage-newtype
- 实现
StorageBackendtrait:
use lsdrive_vfs::StorageBackend; #[async_trait] impl StorageBackend for NewTypeBackend { async fn list_directory(&self, path: &str) -> Result<Vec<VfsNode>> { // 实现目录列表 } // 实现其他必需方法 }
- 注册到 VFS 引擎
# 运行所有测试 cargo test # 运行特定测试 cargo test --test integration_tests # 性能测试 cargo test --test simple_performance --release
# 生成 API 文档 cargo doc --open # 构建用户文档 cd docs && mdbook build
# 基础服务 docker-compose up -d # 包含 nginx 反向代理 docker-compose --profile nginx up -d # 包含 PostgreSQL 数据库 docker-compose --profile postgres up -d
# 使用部署脚本 ./docker/deploy.sh --with-nginx --with-postgres up # 查看服务状态 ./docker/deploy.sh status # 查看日志 ./docker/deploy.sh logs
| 变量名 | 默认值 | 说明 |
|---|---|---|
LSDRIVE_HOST |
0.0.0.0 |
监听地址 |
LSDRIVE_PORT |
8080 |
监听端口 |
LSDRIVE_CONFIG_PATH |
/app/config/lsdrive.toml |
配置文件路径 |
LSDRIVE_DATA_DIR |
/app/data |
数据目录 |
LSDRIVE_STORAGE_DIR |
/app/storage |
存储目录 |
RUST_LOG |
info |
日志级别 |
[performance] metadata_cache_size_mb = 256 file_cache_size_mb = 1024 db_pool_size = 20
[performance] max_concurrent_uploads = 10 max_concurrent_downloads = 20 worker_threads = 8
- 访问
/metrics获取 Prometheus 格式指标 - 使用
/api/health进行健康检查 - 查看
/api/stats获取系统统计
[security] enable_auth = true jwt_secret = "your-super-secret-key" token_expiry_hours = 24
# 生成 SSL 证书 openssl req -x509 -nodes -days 365 -newkey rsa:2048 \ -keyout key.pem -out cert.pem # 配置 nginx 反向代理 ./docker/deploy.sh --with-nginx up
- Fork 项目
- 创建特性分支 (
git checkout -b feature/AmazingFeature) - 提交更改 (
git commit -m 'Add some AmazingFeature') - 推送到分支 (
git push origin feature/AmazingFeature) - 开启 Pull Request
- 使用
cargo fmt格式化代码 - 使用
cargo clippy检查代码质量 - 确保所有测试通过
- 添加必要的文档和注释
本项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情。