68 lines
1.7 KiB
TypeScript
68 lines
1.7 KiB
TypeScript
/**
|
|
* 订阅相关 API
|
|
*/
|
|
import apiClient from './client';
|
|
|
|
// 类型定义
|
|
export interface SubscriptionPlan {
|
|
name: 'free' | 'pro' | 'enterprise';
|
|
display_name: string;
|
|
price: number;
|
|
currency: string;
|
|
max_projects: number;
|
|
max_storage_gb: number;
|
|
features: string[];
|
|
}
|
|
|
|
export interface QuotaStatus {
|
|
projects: {
|
|
used: number;
|
|
limit: number;
|
|
status: 'normal' | 'warning' | 'critical' | 'exceeded';
|
|
};
|
|
storage: {
|
|
used_gb: number;
|
|
limit_gb: number;
|
|
status: 'normal' | 'warning' | 'critical' | 'exceeded';
|
|
};
|
|
}
|
|
|
|
// 获取所有订阅计划
|
|
export const getPlans = async (): Promise<SubscriptionPlan[]> => {
|
|
const response = await apiClient.get('/subscriptions/plans');
|
|
return response.data;
|
|
};
|
|
|
|
// 获取当前订阅
|
|
export const getCurrentSubscription = async (
|
|
workspaceId: string
|
|
): Promise<SubscriptionPlan> => {
|
|
const response = await apiClient.get(`/workspaces/${workspaceId}/subscription`);
|
|
return response.data;
|
|
};
|
|
|
|
// 升级订阅
|
|
export const upgradeSubscription = async (
|
|
workspaceId: string,
|
|
plan: 'pro' | 'enterprise'
|
|
): Promise<{ message: string }> => {
|
|
const response = await apiClient.post(`/workspaces/${workspaceId}/subscription/upgrade`, {
|
|
plan,
|
|
});
|
|
return response.data;
|
|
};
|
|
|
|
// 取消订阅
|
|
export const cancelSubscription = async (
|
|
workspaceId: string
|
|
): Promise<{ message: string }> => {
|
|
const response = await apiClient.post(`/workspaces/${workspaceId}/subscription/cancel`);
|
|
return response.data;
|
|
};
|
|
|
|
// 获取配额状态
|
|
export const getQuotaStatus = async (workspaceId: string): Promise<QuotaStatus> => {
|
|
const response = await apiClient.get(`/workspaces/${workspaceId}/quota`);
|
|
return response.data;
|
|
};
|