chore: add http api for usage and limit

This commit is contained in:
Zack Fu Zi Xiang 2024-07-06 23:33:49 +08:00
parent a41344fbae
commit b77ac38ea3
No known key found for this signature in database
2 changed files with 35 additions and 5 deletions

View File

@ -1,4 +1,5 @@
use crate::Client;
use client_api_entity::billing_dto::WorkspaceUsageAndLimit;
use reqwest::Method;
use serde_json::json;
use shared_entity::{
@ -134,15 +135,12 @@ impl Client {
Ok(portal_url)
}
// Deprecated
async fn get_workspace_limits(
&self,
workspace_id: &str,
) -> Result<WorkspaceUsageLimit, AppResponseError> {
let url = format!(
"{}/api/workspace/{}/limit",
self.base_billing_url(),
workspace_id
);
let url = format!("{}/api/workspace/{}/limit", self.base_url, workspace_id);
self
.http_client_with_auth(Method::GET, &url)
.await?
@ -153,4 +151,23 @@ impl Client {
.await?
.into_data()
}
pub async fn get_workspace_usage_and_limit(
&self,
workspace_id: &str,
) -> Result<WorkspaceUsageAndLimit, AppResponseError> {
let url = format!(
"{}/api/workspace/{}/usage-and-limit",
self.base_url, workspace_id
);
self
.http_client_with_auth(Method::GET, &url)
.await?
.send()
.await?
.error_for_status()?
.json::<AppResponse<WorkspaceUsageAndLimit>>()
.await?
.into_data()
}
}

View File

@ -83,3 +83,16 @@ pub struct WorkspaceUsageLimit {
pub single_blob_size: usize,
pub member_count: usize,
}
#[derive(Deserialize)]
pub struct WorkspaceUsageAndLimit {
pub member_count: i64,
pub member_count_limit: i64,
pub total_blob_bytes: i64,
pub total_blob_bytes_limit: i64,
pub ai_responses_count: i64,
pub ai_responses_count_limit: i64,
pub local_ai: bool,
pub ai_responses_unlimited: bool,
}