mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-22 16:43:35 +00:00
Merge pull request #249 from iRubbish/feat/webhook-manual-disable-notification
feat: 增强 webhook 通知功能,支持手动禁用账号通知
This commit is contained in:
@@ -550,6 +550,26 @@ class ClaudeAccountService {
|
||||
|
||||
updatedData.updatedAt = new Date().toISOString()
|
||||
|
||||
// 检查是否手动禁用了账号,如果是则发送webhook通知
|
||||
if (updates.isActive === 'false' && accountData.isActive === 'true') {
|
||||
try {
|
||||
const webhookNotifier = require('../utils/webhookNotifier')
|
||||
await webhookNotifier.sendAccountAnomalyNotification({
|
||||
accountId,
|
||||
accountName: updatedData.name || 'Unknown Account',
|
||||
platform: 'claude-oauth',
|
||||
status: 'disabled',
|
||||
errorCode: 'CLAUDE_OAUTH_MANUALLY_DISABLED',
|
||||
reason: 'Account manually disabled by administrator'
|
||||
})
|
||||
} catch (webhookError) {
|
||||
logger.error(
|
||||
'Failed to send webhook notification for manual account disable:',
|
||||
webhookError
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
await redis.setClaudeAccount(accountId, updatedData)
|
||||
|
||||
logger.success(`📝 Updated Claude account: ${accountId}`)
|
||||
|
||||
@@ -261,6 +261,26 @@ class ClaudeConsoleAccountService {
|
||||
|
||||
updatedData.updatedAt = new Date().toISOString()
|
||||
|
||||
// 检查是否手动禁用了账号,如果是则发送webhook通知
|
||||
if (updates.isActive === false && existingAccount.isActive === true) {
|
||||
try {
|
||||
const webhookNotifier = require('../utils/webhookNotifier')
|
||||
await webhookNotifier.sendAccountAnomalyNotification({
|
||||
accountId,
|
||||
accountName: updatedData.name || existingAccount.name || 'Unknown Account',
|
||||
platform: 'claude-console',
|
||||
status: 'disabled',
|
||||
errorCode: 'CLAUDE_CONSOLE_MANUALLY_DISABLED',
|
||||
reason: 'Account manually disabled by administrator'
|
||||
})
|
||||
} catch (webhookError) {
|
||||
logger.error(
|
||||
'Failed to send webhook notification for manual account disable:',
|
||||
webhookError
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug(`[DEBUG] Final updatedData to save: ${JSON.stringify(updatedData, null, 2)}`)
|
||||
logger.debug(`[DEBUG] Updating Redis key: ${this.ACCOUNT_KEY_PREFIX}${accountId}`)
|
||||
|
||||
|
||||
@@ -455,6 +455,23 @@ async function updateAccount(accountId, updates) {
|
||||
}
|
||||
}
|
||||
|
||||
// 检查是否手动禁用了账号,如果是则发送webhook通知
|
||||
if (updates.isActive === 'false' && existingAccount.isActive !== 'false') {
|
||||
try {
|
||||
const webhookNotifier = require('../utils/webhookNotifier')
|
||||
await webhookNotifier.sendAccountAnomalyNotification({
|
||||
accountId,
|
||||
accountName: updates.name || existingAccount.name || 'Unknown Account',
|
||||
platform: 'gemini',
|
||||
status: 'disabled',
|
||||
errorCode: 'GEMINI_MANUALLY_DISABLED',
|
||||
reason: 'Account manually disabled by administrator'
|
||||
})
|
||||
} catch (webhookError) {
|
||||
logger.error('Failed to send webhook notification for manual account disable:', webhookError)
|
||||
}
|
||||
}
|
||||
|
||||
await client.hset(`${GEMINI_ACCOUNT_KEY_PREFIX}${accountId}`, updates)
|
||||
|
||||
logger.info(`Updated Gemini account: ${accountId}`)
|
||||
|
||||
@@ -125,15 +125,18 @@ class WebhookNotifier {
|
||||
const errorCodes = {
|
||||
'claude-oauth': {
|
||||
unauthorized: 'CLAUDE_OAUTH_UNAUTHORIZED',
|
||||
error: 'CLAUDE_OAUTH_ERROR'
|
||||
error: 'CLAUDE_OAUTH_ERROR',
|
||||
disabled: 'CLAUDE_OAUTH_MANUALLY_DISABLED'
|
||||
},
|
||||
'claude-console': {
|
||||
blocked: 'CLAUDE_CONSOLE_BLOCKED',
|
||||
error: 'CLAUDE_CONSOLE_ERROR'
|
||||
error: 'CLAUDE_CONSOLE_ERROR',
|
||||
disabled: 'CLAUDE_CONSOLE_MANUALLY_DISABLED'
|
||||
},
|
||||
gemini: {
|
||||
error: 'GEMINI_ERROR',
|
||||
unauthorized: 'GEMINI_UNAUTHORIZED'
|
||||
unauthorized: 'GEMINI_UNAUTHORIZED',
|
||||
disabled: 'GEMINI_MANUALLY_DISABLED'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user