use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Default)]
pub struct UploadOptions {
pub parent_folder_id: Option<String>,
pub use_resumable: bool,
pub verify_checksum: bool,
}
impl UploadOptions {
pub fn with_parent(parent_id: String) -> Self {
Self {
parent_folder_id: Some(parent_id),
use_resumable: true,
verify_checksum: true,
}
}
pub fn resumable() -> Self {
Self {
use_resumable: true,
verify_checksum: true,
..Default::default()
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UploadResult {
pub file_id: String,
pub name: String,
pub size: u64,
pub md5_checksum: Option<String>,
pub web_view_link: Option<String>,
pub upload_duration_secs: f64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FolderInfo {
pub id: String,
pub name: String,
pub parent_id: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FileInfo {
pub id: String,
pub name: String,
pub size: u64,
pub mime_type: String,
pub modified_time: Option<i64>,
pub md5_checksum: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StorageStats {
pub used_bytes: u64,
pub limit_bytes: Option<u64>,
pub usage_percentage: f64,
}
impl StorageStats {
pub fn new(used_bytes: u64, limit_bytes: Option<u64>) -> Self {
let usage_percentage = if let Some(limit) = limit_bytes {
if limit > 0 {
(used_bytes as f64 / limit as f64) * 100.0
} else {
0.0
}
} else {
0.0
};
Self {
used_bytes,
limit_bytes,
usage_percentage,
}
}
pub fn is_near_limit(&self) -> bool {
self.usage_percentage > 90.0
}
pub fn is_over_limit(&self) -> bool {
self.usage_percentage >= 100.0
}
}