mirror of
https://github.com/SECTL/SecScore.git
synced 2026-07-19 12:34:22 +08:00
fix: 修复云空间用量Failed to fetch
This commit is contained in:
@@ -707,6 +707,63 @@ pub struct OnlineStatusResponse {
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct OAuthStorageUsageResponse {
|
||||
pub used_storage: i64,
|
||||
pub used_storage_formatted: String,
|
||||
pub total_storage: i64,
|
||||
pub total_storage_formatted: String,
|
||||
pub available_storage: i64,
|
||||
pub available_storage_formatted: String,
|
||||
pub percentage: f64,
|
||||
pub file_count: i64,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn oauth_get_storage_usage(
|
||||
access_token: String,
|
||||
platform_id: String,
|
||||
user_id: String,
|
||||
state: State<'_, Arc<RwLock<AppState>>>,
|
||||
) -> Result<IpcResponse<OAuthStorageUsageResponse>, String> {
|
||||
let state_guard = state.read();
|
||||
let client = &state_guard.http_client;
|
||||
|
||||
let response = client
|
||||
.get("https://appwrite.sectl.top/api/cloud/storage/usage")
|
||||
.query(&[("client_id", platform_id), ("user_id", user_id)])
|
||||
.header("Authorization", format!("Bearer {}", access_token))
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| format!("Request failed: {}", e))?;
|
||||
|
||||
if !response.status().is_success() {
|
||||
let error_text = response
|
||||
.text()
|
||||
.await
|
||||
.unwrap_or_else(|_| "Unknown error".to_string());
|
||||
let error_message =
|
||||
if let Ok(json_err) = serde_json::from_str::<serde_json::Value>(&error_text) {
|
||||
json_err
|
||||
.get("error_description")
|
||||
.or_else(|| json_err.get("error"))
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or(&error_text)
|
||||
.to_string()
|
||||
} else {
|
||||
error_text
|
||||
};
|
||||
return Ok(IpcResponse::error(&error_message));
|
||||
}
|
||||
|
||||
let storage_usage: OAuthStorageUsageResponse = response
|
||||
.json()
|
||||
.await
|
||||
.map_err(|e| format!("Failed to parse response: {}", e))?;
|
||||
|
||||
Ok(IpcResponse::success(storage_usage))
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn oauth_report_online(
|
||||
platform_id: String,
|
||||
@@ -898,3 +955,4 @@ pub async fn oauth_refresh_access_token(
|
||||
|
||||
Ok(IpcResponse::success(token_response))
|
||||
}
|
||||
|
||||
|
||||
@@ -86,6 +86,7 @@ pub fn run() {
|
||||
oauth_stop_callback_server,
|
||||
oauth_report_online,
|
||||
oauth_get_device_uuid,
|
||||
oauth_get_storage_usage,
|
||||
oauth_save_login_state,
|
||||
oauth_load_login_state,
|
||||
oauth_clear_login_state,
|
||||
@@ -449,3 +450,4 @@ fn setup_window_events(app: &mut App) -> Result<(), Box<dyn std::error::Error>>
|
||||
fn setup_window_events(_app: &mut App) -> Result<(), Box<dyn std::error::Error>> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user