mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-28 00:35:32 +08:00
feat(deeplink): 深链支持用量查询配置 (#400)
## 新增功能
- 深链导入支持用量查询配置参数:
- `usageEnabled`: 是否启用用量查询
- `usageScript`: Base64 编码的用量查询脚本
- `usageApiKey`: 用量查询专用 API Key
- `usageBaseUrl`: 用量查询专用 Base URL
- `usageAccessToken`: 访问令牌(NewAPI 模板)
- `usageUserId`: 用户 ID(NewAPI 模板)
- `usageAutoInterval`: 自动查询间隔(分钟)
## 修改文件
- **mod.rs**: DeepLinkImportRequest 结构体添加用量查询字段
- **parser.rs**: 解析 URL 中的用量查询参数
- **provider.rs**: 构建 ProviderMeta 包含 UsageScript 配置
- **deeplink.ts**: 添加 TypeScript 类型定义
- **DeepLinkImportDialog.tsx**: 确认对话框显示用量查询配置
## Bug 修复
- **formatters.ts**: 修复 formatJSON() 格式化时删除 "env" 键的问题
## 深链格式示例
```
ccswitch://v1/import?resource=provider&app=claude&name=xxx&usageEnabled=true&usageScript={base64}&usageAutoInterval=30
```
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* 格式化 JSON 字符串
|
||||
* @param value - 原始 JSON 字符串(支持带键名包装的格式)
|
||||
* @param value - 原始 JSON 字符串
|
||||
* @returns 格式化后的 JSON 字符串(2 空格缩进)
|
||||
* @throws 如果 JSON 格式无效
|
||||
*/
|
||||
@@ -9,9 +9,8 @@ export function formatJSON(value: string): string {
|
||||
if (!trimmed) {
|
||||
return "";
|
||||
}
|
||||
// 使用智能解析器来处理可能的片段格式
|
||||
const result = parseSmartMcpJson(trimmed);
|
||||
return result.formattedConfig;
|
||||
const parsed = JSON.parse(trimmed);
|
||||
return JSON.stringify(parsed, null, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user