A Rust library for interacting with the Cloudreve API. This library provides asynchronous access to all major Cloudreve API endpoints with proper error handling and type safety.
- β¨ Full async/await support with Tokio
- π Complete authentication flow (login, token refresh, 2FA)
- π Comprehensive file operations (upload, download, list, delete, move, copy)
- π Share link management
- π€ User and storage management
- π― Type-safe request and response structures
- π‘οΈ Built-in error handling
- π¦ Support for both Cloudreve v3 and v4 APIs
Add this to your Cargo.toml:
[dependencies]
cloudreve-api = "0.3"
tokio = { version = "1", features = ["full"] }Or use cargo-edit:
cargo add cloudreve-apiuse cloudreve_api::{CloudreveAPI, Result};
#[tokio::main]
async fn main() -> Result<()> {
// Create a client instance (auto-detects API version)
let mut api = CloudreveAPI::new("https://your-cloudreve-instance.com").await?;
// Login
api.login("user@example.com", "password").await?;
println!("Successfully logged in!");
Ok(())
}use cloudreve_api::{CloudreveAPI, Result};
#[tokio::main]
async fn main() -> Result<()> {
let mut api = CloudreveAPI::new("https://your-cloudreve-instance.com").await?;
api.login("user@example.com", "password").await?;
// List files in a directory
let files = api.list_files("/").await?;
println!("Found {} items", files.total_count());
for item in files.items() {
if item.is_folder {
println!(" π {}/", item.name);
} else {
println!(" π {} ({} bytes)", item.name, item.size);
}
}
Ok(())
}use cloudreve_api::{CloudreveAPI, Result};
#[tokio::main]
async fn main() -> Result<()> {
let mut api = CloudreveAPI::new("https://your-cloudreve-instance.com").await?;
api.login("user@example.com", "password").await?;
// Create a new directory
api.create_directory("/photos/vacation").await?;
println!("Directory created successfully!");
Ok(())
}use cloudreve_api::{CloudreveAPI, Result};
#[tokio::main]
async fn main() -> Result<()> {
let mut api = CloudreveAPI::new("https://your-cloudreve-instance.com").await?;
api.login("user@example.com", "password").await?;
// Upload a file
let content = b"Hello, World!".to_vec();
api.upload_file("/hello.txt", content, None).await?;
println!("File uploaded successfully!");
Ok(())
}use cloudreve_api::{CloudreveAPI, Result};
#[tokio::main]
async fn main() -> Result<()> {
let mut api = CloudreveAPI::new("https://your-cloudreve-instance.com").await?;
api.login("user@example.com", "password").await?;
// Get download URL
let url = api.download_file("/document.pdf").await?;
println!("Download URL: {}", url);
Ok(())
}use cloudreve_api::{CloudreveAPI, Result};
#[tokio::main]
async fn main() -> Result<()> {
let mut api = CloudreveAPI::new("https://your-cloudreve-instance.com").await?;
api.login("user@example.com", "password").await?;
// List shares
let shares = api.list_shares().await?;
for share in shares {
println!("Share key: {}", share.key);
}
Ok(())
}-
Authentication & Session
- Login with email/password
- Token management
- 2FA support
-
User Management
- User profile
- Storage capacity
- Storage policies
- Settings management
-
File Operations
- List files/directories
- Upload (with chunked support)
- Download
- Create directory
- Rename
- Move
- Copy
- Delete
- Get file info
-
Sharing
- Create share links
- List share links
- Update share links
- Delete share links
-
Advanced Features
- File search
- Thumbnail generation
- Archive operations
- WebDAV account management
This library supports both Cloudreve v3 and v4 APIs with automatic version detection:
use cloudreve_api::{CloudreveAPI, ApiVersion, Result};
#[tokio::main]
async fn main() -> Result<()> {
// Auto-detect version
let api = CloudreveAPI::new("https://instance.com").await?;
// Or specify version explicitly
let api = CloudreveAPI::with_version("https://instance.com", ApiVersion::V4)?;
Ok(())
}All API calls return a Result<T, Error> type:
use cloudreve_api::{CloudreveAPI, Error};
#[tokio::main]
async fn main() {
let mut api = CloudreveAPI::new("https://your-cloudreve-instance.com").await.unwrap();
match api.login("user@example.com", "wrong_password").await {
Ok(_) => println!("Login successful"),
Err(Error::Api { code, message }) => {
eprintln!("API Error {}: {}", code, message);
}
Err(Error::Http(err)) => {
eprintln!("HTTP Error: {}", err);
}
Err(err) => {
eprintln!("Other Error: {}", err);
}
}
}Error::Http- Network/HTTP related errorsError::Json- Serialization/deserialization errorsError::Api- API error responses with code and messageError::Reqwest- Underlying reqwest errorsError::Url- URL parsing errorsError::InvalidResponse- Invalid API response format
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
If you encounter any issues or have questions, please file an issue.