Skip to content

biliup/lsdrive

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lsdrive

Version License Rust Docker

lsdrive 是一个高性能、功能丰富的文件管理系统。

✨ 特性

🔥 核心功能

  • 多云存储支持 - 阿里云盘、OneDrive、百度网盘、Google Drive 等
  • 六边形架构 - 模块化设计,易于扩展
  • 高性能 - Rust + Tokio 异步运行时
  • WebDAV 服务器 - 完整的 WebDAV 协议支持
  • 文件预览 - 图片、视频、文档在线预览
  • 离线下载 - 多线程下载,断点续传
  • 文件分享 - 灵活的分享权限和过期控制

🎯 技术特性

  • REST + GraphQL API - 双 API 架构
  • JWT 认证 - 安全的用户认证系统
  • 现代化前端 - React + TypeScript + shadcn/ui
  • Docker 支持 - 完整的容器化部署方案
  • 实时监控 - 性能监控和优化建议

🚀 快速开始

使用 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"

OneDrive

[storage_backends.onedrive]
type = "OneDrive"
client_id = "your_client_id"
client_secret = "your_client_secret"
redirect_uri = "http://localhost:8080/auth/callback"

API 使用

REST API

# 获取文件列表
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"}'

GraphQL

query {
  files(path: "/") {
    edges {
      node {
        id
        name
        size
        isDir
      }
    }
  }
}

WebDAV 访问

# 挂载为网络驱动器
# 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/                   # 文档

添加新的存储适配器

  1. 创建新的 crate:
cargo new --lib crates/lsdrive-storage-newtype
  1. 实现 StorageBackend trait:
use lsdrive_vfs::StorageBackend;

#[async_trait]
impl StorageBackend for NewTypeBackend {
    async fn list_directory(&self, path: &str) -> Result<Vec<VfsNode>> {
        // 实现目录列表
    }
    
    // 实现其他必需方法
}
  1. 注册到 VFS 引擎

运行测试

# 运行所有测试
cargo test

# 运行特定测试
cargo test --test integration_tests

# 性能测试
cargo test --test simple_performance --release

生成文档

# 生成 API 文档
cargo doc --open

# 构建用户文档
cd docs && mdbook build

🐳 Docker 部署

基础部署

# 基础服务
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

HTTPS 配置

# 生成 SSL 证书
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
  -keyout key.pem -out cert.pem

# 配置 nginx 反向代理
./docker/deploy.sh --with-nginx up

🤝 贡献指南

  1. Fork 项目
  2. 创建特性分支 (git checkout -b feature/AmazingFeature)
  3. 提交更改 (git commit -m 'Add some AmazingFeature')
  4. 推送到分支 (git push origin feature/AmazingFeature)
  5. 开启 Pull Request

代码规范

  • 使用 cargo fmt 格式化代码
  • 使用 cargo clippy 检查代码质量
  • 确保所有测试通过
  • 添加必要的文档和注释

📝 许可证

本项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情。


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published