mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-22 16:43:35 +00:00
feat(admin): 余额脚本驱动的余额/配额刷新与管理端体验修复
- 明确刷新语义:仅脚本启用且已配置时触发远程查询;未配置时前端禁用并提示\n- 新增余额脚本安全开关 BALANCE_SCRIPT_ENABLED(默认开启),脚本测试接口受控\n- Redis 增加单账户脚本配置存取,响应透出 scriptEnabled/scriptConfigured 供 UI 判定\n- accountBalanceService:本地统计汇总改用 SCAN+pipeline,避免 KEYS;仅缓存远程成功结果,避免失败/降级覆盖有效缓存\n- 管理端体验:刷新按钮按配置状态灰置;脚本弹窗内容可滚动、底部操作栏固定,并 append-to-body 使弹窗跟随当前视窗
This commit is contained in:
44
src/utils/featureFlags.js
Normal file
44
src/utils/featureFlags.js
Normal file
@@ -0,0 +1,44 @@
|
||||
let config = {}
|
||||
try {
|
||||
// config/config.js 可能在某些环境不存在(例如仅拷贝了 config.example.js)
|
||||
// 为保证可运行,这里做容错处理
|
||||
// eslint-disable-next-line global-require
|
||||
config = require('../../config/config')
|
||||
} catch (error) {
|
||||
config = {}
|
||||
}
|
||||
|
||||
const parseBooleanEnv = (value) => {
|
||||
if (typeof value === 'boolean') {
|
||||
return value
|
||||
}
|
||||
if (typeof value !== 'string') {
|
||||
return false
|
||||
}
|
||||
const normalized = value.trim().toLowerCase()
|
||||
return normalized === 'true' || normalized === '1' || normalized === 'yes' || normalized === 'on'
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否允许执行“余额脚本”(安全开关)
|
||||
* 默认开启,便于保持现有行为;如需禁用请显式设置 BALANCE_SCRIPT_ENABLED=false(环境变量优先)
|
||||
*/
|
||||
const isBalanceScriptEnabled = () => {
|
||||
if (
|
||||
process.env.BALANCE_SCRIPT_ENABLED !== undefined &&
|
||||
process.env.BALANCE_SCRIPT_ENABLED !== ''
|
||||
) {
|
||||
return parseBooleanEnv(process.env.BALANCE_SCRIPT_ENABLED)
|
||||
}
|
||||
|
||||
const fromConfig =
|
||||
config?.accountBalance?.enableBalanceScript ??
|
||||
config?.features?.balanceScriptEnabled ??
|
||||
config?.security?.enableBalanceScript
|
||||
|
||||
return typeof fromConfig === 'boolean' ? fromConfig : true
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
isBalanceScriptEnabled
|
||||
}
|
||||
Reference in New Issue
Block a user