mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 19:57:20 +00:00
feat: 添加Gemini定价功能和界面优化
- 实现Gemini定价查询服务,支持实时计算token成本 - 改进API Key管理界面,添加模型快速选择功能 - 优化账户表单组件的渲染性能 - 更新Gemini账户服务,增强token刷新和错误处理 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -320,7 +320,18 @@ async function createAccount(accountData) {
|
||||
}
|
||||
|
||||
logger.info(`Created Gemini account: ${id}`);
|
||||
return account;
|
||||
|
||||
// 返回时解析代理配置
|
||||
const returnAccount = { ...account };
|
||||
if (returnAccount.proxy) {
|
||||
try {
|
||||
returnAccount.proxy = JSON.parse(returnAccount.proxy);
|
||||
} catch (e) {
|
||||
returnAccount.proxy = null;
|
||||
}
|
||||
}
|
||||
|
||||
return returnAccount;
|
||||
}
|
||||
|
||||
// 获取账户
|
||||
@@ -343,6 +354,16 @@ async function getAccount(accountId) {
|
||||
accountData.refreshToken = decrypt(accountData.refreshToken);
|
||||
}
|
||||
|
||||
// 解析代理配置
|
||||
if (accountData.proxy) {
|
||||
try {
|
||||
accountData.proxy = JSON.parse(accountData.proxy);
|
||||
} catch (e) {
|
||||
// 如果解析失败,保持原样或设置为null
|
||||
accountData.proxy = null;
|
||||
}
|
||||
}
|
||||
|
||||
return accountData;
|
||||
}
|
||||
|
||||
@@ -361,6 +382,11 @@ async function updateAccount(accountId, updates) {
|
||||
const oldRefreshToken = existingAccount.refreshToken || '';
|
||||
let needUpdateExpiry = false;
|
||||
|
||||
// 处理代理设置
|
||||
if (updates.proxy !== undefined) {
|
||||
updates.proxy = updates.proxy ? JSON.stringify(updates.proxy) : '';
|
||||
}
|
||||
|
||||
// 加密敏感字段
|
||||
if (updates.geminiOauth) {
|
||||
updates.geminiOauth = encrypt(
|
||||
@@ -423,7 +449,20 @@ async function updateAccount(accountId, updates) {
|
||||
);
|
||||
|
||||
logger.info(`Updated Gemini account: ${accountId}`);
|
||||
return { ...existingAccount, ...updates };
|
||||
|
||||
// 合并更新后的账户数据
|
||||
const updatedAccount = { ...existingAccount, ...updates };
|
||||
|
||||
// 返回时解析代理配置
|
||||
if (updatedAccount.proxy && typeof updatedAccount.proxy === 'string') {
|
||||
try {
|
||||
updatedAccount.proxy = JSON.parse(updatedAccount.proxy);
|
||||
} catch (e) {
|
||||
updatedAccount.proxy = null;
|
||||
}
|
||||
}
|
||||
|
||||
return updatedAccount;
|
||||
}
|
||||
|
||||
// 删除账户
|
||||
@@ -464,6 +503,16 @@ async function getAllAccounts() {
|
||||
for (const key of keys) {
|
||||
const accountData = await client.hgetall(key);
|
||||
if (accountData && Object.keys(accountData).length > 0) {
|
||||
// 解析代理配置
|
||||
if (accountData.proxy) {
|
||||
try {
|
||||
accountData.proxy = JSON.parse(accountData.proxy);
|
||||
} catch (e) {
|
||||
// 如果解析失败,设置为null
|
||||
accountData.proxy = null;
|
||||
}
|
||||
}
|
||||
|
||||
// 不解密敏感字段,只返回基本信息
|
||||
accounts.push({
|
||||
...accountData,
|
||||
|
||||
Reference in New Issue
Block a user