xiaoyukkkk commited on
Commit
0b0c419
·
verified ·
1 Parent(s): 781b3fb

Upload account.py

Browse files
Files changed (1) hide show
  1. core/account.py +15 -2
core/account.py CHANGED
@@ -311,7 +311,20 @@ def save_accounts_to_file(accounts_data: list):
311
 
312
 
313
  def load_accounts_from_source() -> list:
314
- """从文件加载账户配置,文件不存在则创建空配置"""
 
 
 
 
 
 
 
 
 
 
 
 
 
315
  # 从文件加载
316
  if os.path.exists(ACCOUNTS_FILE):
317
  try:
@@ -327,7 +340,7 @@ def load_accounts_from_source() -> list:
327
 
328
  # 文件不存在,创建空配置
329
  logger.warning(f"[CONFIG] 未找到 {ACCOUNTS_FILE},已创建空配置文件")
330
- logger.info(f"[CONFIG] 💡 请在管理面板添加账户,或直接编辑 {ACCOUNTS_FILE},或使用批量上传功能")
331
  save_accounts_to_file([])
332
  return []
333
 
 
311
 
312
 
313
  def load_accounts_from_source() -> list:
314
+ """从环境变量或文件加载账户配置,优先使用环境变量"""
315
+ # 优先从环境变量加载
316
+ env_accounts = os.environ.get('ACCOUNTS_JSON')
317
+ if env_accounts:
318
+ try:
319
+ accounts_data = json.loads(env_accounts)
320
+ if accounts_data:
321
+ logger.info(f"[CONFIG] 从环境变量加载配置,共 {len(accounts_data)} 个账户")
322
+ else:
323
+ logger.warning(f"[CONFIG] 环境变量 ACCOUNTS_JSON 为空")
324
+ return accounts_data
325
+ except Exception as e:
326
+ logger.error(f"[CONFIG] 环境变量加载失败: {str(e)},尝试从文件加载")
327
+
328
  # 从文件加载
329
  if os.path.exists(ACCOUNTS_FILE):
330
  try:
 
340
 
341
  # 文件不存在,创建空配置
342
  logger.warning(f"[CONFIG] 未找到 {ACCOUNTS_FILE},已创建空配置文件")
343
+ logger.info(f"[CONFIG] 💡 请在管理面板添加账户,或直接编辑 {ACCOUNTS_FILE},或使用批量上传功能,或设置环境变量 ACCOUNTS_JSON")
344
  save_accounts_to_file([])
345
  return []
346