chore: update usage and limits api
This commit is contained in:
parent
b77ac38ea3
commit
430fbf845a
|
|
@ -3,10 +3,7 @@ use client_api_entity::billing_dto::WorkspaceUsageAndLimit;
|
||||||
use reqwest::Method;
|
use reqwest::Method;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use shared_entity::{
|
use shared_entity::{
|
||||||
dto::billing_dto::{
|
dto::billing_dto::{RecurringInterval, SubscriptionPlan, WorkspaceSubscriptionStatus},
|
||||||
RecurringInterval, SubscriptionPlan, WorkspaceSubscriptionStatus, WorkspaceUsage,
|
|
||||||
WorkspaceUsageLimit,
|
|
||||||
},
|
|
||||||
response::{AppResponse, AppResponseError},
|
response::{AppResponse, AppResponseError},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -101,23 +98,6 @@ impl Client {
|
||||||
.into_data()
|
.into_data()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_billing_workspace_usage(
|
|
||||||
&self,
|
|
||||||
workspace_id: &str,
|
|
||||||
) -> Result<WorkspaceUsage, AppResponseError> {
|
|
||||||
let num_members = self.get_workspace_members(workspace_id).await?.len();
|
|
||||||
let limits = self.get_workspace_limits(workspace_id).await?;
|
|
||||||
let doc_usage = self.get_workspace_usage(workspace_id).await?;
|
|
||||||
|
|
||||||
let workspace_usage = WorkspaceUsage {
|
|
||||||
member_count: num_members,
|
|
||||||
member_count_limit: limits.member_count,
|
|
||||||
total_blob_bytes: doc_usage.consumed_capacity as _,
|
|
||||||
total_blob_bytes_limit: limits.total_blob_size,
|
|
||||||
};
|
|
||||||
Ok(workspace_usage)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn get_portal_session_link(&self) -> Result<String, AppResponseError> {
|
pub async fn get_portal_session_link(&self) -> Result<String, AppResponseError> {
|
||||||
let url = format!(
|
let url = format!(
|
||||||
"{}/billing/api/v1/portal-session-link",
|
"{}/billing/api/v1/portal-session-link",
|
||||||
|
|
@ -135,23 +115,6 @@ impl Client {
|
||||||
Ok(portal_url)
|
Ok(portal_url)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated
|
|
||||||
async fn get_workspace_limits(
|
|
||||||
&self,
|
|
||||||
workspace_id: &str,
|
|
||||||
) -> Result<WorkspaceUsageLimit, AppResponseError> {
|
|
||||||
let url = format!("{}/api/workspace/{}/limit", self.base_url, workspace_id);
|
|
||||||
self
|
|
||||||
.http_client_with_auth(Method::GET, &url)
|
|
||||||
.await?
|
|
||||||
.send()
|
|
||||||
.await?
|
|
||||||
.error_for_status()?
|
|
||||||
.json::<AppResponse<WorkspaceUsageLimit>>()
|
|
||||||
.await?
|
|
||||||
.into_data()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn get_workspace_usage_and_limit(
|
pub async fn get_workspace_usage_and_limit(
|
||||||
&self,
|
&self,
|
||||||
workspace_id: &str,
|
workspace_id: &str,
|
||||||
|
|
|
||||||
|
|
@ -66,30 +66,13 @@ pub struct WorkspaceSubscriptionStatus {
|
||||||
pub canceled_at: Option<i64>,
|
pub canceled_at: Option<i64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
|
||||||
pub struct WorkspaceUsage {
|
|
||||||
pub member_count: usize,
|
|
||||||
pub member_count_limit: usize,
|
|
||||||
pub total_blob_bytes: usize,
|
|
||||||
pub total_blob_bytes_limit: usize,
|
|
||||||
// TODO(AI):
|
|
||||||
// pub ai_responses: String,
|
|
||||||
// pub ai_responses_limit: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
pub struct WorkspaceUsageLimit {
|
|
||||||
pub total_blob_size: usize,
|
|
||||||
pub single_blob_size: usize,
|
|
||||||
pub member_count: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct WorkspaceUsageAndLimit {
|
pub struct WorkspaceUsageAndLimit {
|
||||||
pub member_count: i64,
|
pub member_count: i64,
|
||||||
pub member_count_limit: i64,
|
pub member_count_limit: i64,
|
||||||
pub total_blob_bytes: i64,
|
pub storage_bytes: i64,
|
||||||
pub total_blob_bytes_limit: i64,
|
pub storage_bytes_limit: i64,
|
||||||
|
pub storage_bytes_unlimited: bool,
|
||||||
pub ai_responses_count: i64,
|
pub ai_responses_count: i64,
|
||||||
pub ai_responses_count_limit: i64,
|
pub ai_responses_count_limit: i64,
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue