Cloudreve API Client for Rust
A comprehensive Rust client library for the Cloudreve API with automatic token refresh support.
Features
- ✅ Automatic Token Refresh: Handles access token expiration and refresh automatically
- ✅ Type-Safe: Strongly typed API with comprehensive models
- ✅ Async/Await: Built on tokio for high-performance async operations
- ✅ Error Handling: Detailed error types for different API error conditions
- ✅ Complete API Coverage: Support for all major Cloudreve API endpoints
- User authentication and management
- File explorer operations (list, create, delete, move, etc.)
- File upload and download
- Workflow and task management
- Site configuration
Installation
Add this to your Cargo.toml:
[]
= "0.1"
= { = "1.0", = ["full"] }
Quick Start
Run the included login and file-listing example:
use ;
use ;
async
Authentication
Password Login
let login_response = client.login.await?;
client.set_tokens_with_expiry.await?;
Two-Factor Authentication
// First attempt will fail with 2FA required
match client.login.await
Token Refresh
Tokens are automatically refreshed when they expire. The client handles this transparently:
// First request - uses existing token
let user = client.get_user_me.await?;
// ... token expires ...
// Next request - automatically refreshes token before making the request
let capacity = client.get_user_capacity.await?; // No error!
Error Handling
The library provides detailed error types for different scenarios:
use ;
match client.list_files.await
API Examples
File Operations
use *;
// Create a folder
let create_req = CreateFileService ;
let folder = client.create_file.await?;
// Upload a file (simplified)
let upload_req = UploadSessionRequest ;
let credential = client.create_upload_session.await?;
// Delete files
let delete_req = DeleteFileService ;
client.delete_files.await?;
// Move files
let move_req = MoveFileService ;
client.move_files.await?;
// Get file info
let info_req = GetFileInfoService ;
let file_info = client.get_file_info.await?;
Task Management
use *;
use WorkflowApi;
// Create archive task
let archive_req = ArchiveWorkflowService ;
let task = client.create_archive.await?;
println!;
// List tasks
let list_req = ListTaskService ;
let tasks = client.list_tasks.await?;
// Monitor task
let task_status = client.get_task.await?;
println!;
User Management
use UserApi;
// Get user info
let user = client.get_user_me.await?;
println!;
// Get capacity
let capacity = client.get_user_capacity.await?;
println!;
// Update settings
let mut settings = default;
settings.preferred_theme = Some;
client.patch_user_settings.await?;
Advanced Configuration
Custom Timeout
let config = new
.with_timeout; // 60 seconds timeout
let client = new;
Request Options
// Skip batch error handling (get first error)
let opts = new
.skip_batch_error;
// Include purchase ticket
let opts = new
.with_purchase_ticket;
// No authentication
let opts = new
.no_credential;
Error Codes
The library handles these Cloudreve error codes:
0- Success203- Continue401- Login required403- Permission denied404- Not found40020- Credential invalid40069- Incorrect password40073- Lock conflict (file locked by another user)40076- Stale version40081- Batch operation not fully completed40083- Purchase required40087- Domain not licensed40088- Anonymous access denied
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.