同步代码

This commit is contained in:
2025-08-12 09:27:50 +08:00
parent dd4446fd8c
commit 9c3bc5200a
421 changed files with 54063 additions and 53044 deletions

View File

@@ -0,0 +1,73 @@
/**
* API URL工具函数
* 用于统一处理API地址的拼接逻辑
*
* URL结构: {VITE_API_BASE_URL}/v1/api/scenarios/{path}
*
* 示例:
* - 开发环境: http://localhost:3000/api/v1/api/scenarios/webhook/123
* - 生产环境: https://api.example.com/v1/api/scenarios/webhook/123
*/
/**
* 获取完整的API基础路径
* @returns 完整的API基础路径包含 /v1/api/scenarios
*
* 示例:
* - 开发环境: http://localhost:3000/api/v1/api/scenarios
* - 生产环境: https://api.example.com/v1/api/scenarios
*/
export const getFullApiPath = (): string => {
const apiBaseUrl = (import.meta as any).env?.VITE_API_BASE_URL || "/api";
return `${apiBaseUrl}/v1/api/scenarios`;
};
/**
* 构建完整的API URL
* @param path 相对路径或完整URL
* @returns 完整的API URL
*
* 示例:
* - buildApiUrl('/webhook/123') → 'http://localhost:3000/api/v1/api/scenarios/webhook/123'
* - buildApiUrl('webhook/123') → 'http://localhost:3000/api/v1/api/scenarios/webhook/123'
* - buildApiUrl('https://api.example.com/webhook/123') → 'https://api.example.com/webhook/123'
*/
export const buildApiUrl = (path: string): string => {
if (!path) return "";
// 如果已经是完整的URL包含http或https直接返回
if (path.startsWith("http://") || path.startsWith("https://")) {
return path;
}
const fullApiPath = getFullApiPath();
// 如果是相对路径拼接完整API路径
if (path.startsWith("/")) {
return `${fullApiPath}${path}`;
}
// 其他情况拼接完整API路径和路径
return `${fullApiPath}?${path}`;
};
/**
* 构建webhook URL
* @param taskId 任务ID
* @param path 可选的相对路径
* @returns 完整的webhook URL
*
* 示例:
* - buildWebhookUrl('123') → 'http://localhost:3000/api/v1/api/scenarios/webhook/123'
* - buildWebhookUrl('123', '/custom/path') → 'http://localhost:3000/api/v1/api/scenarios/custom/path'
*/
export const buildWebhookUrl = (taskId: string, path?: string): string => {
const fullApiPath = getFullApiPath();
const webhookPath = path || `/webhook/${taskId}`;
if (webhookPath.startsWith("/")) {
return `${fullApiPath}${webhookPath}`;
}
return `${fullApiPath}/${webhookPath}`;
};