ZHIWEI666 commited on
Commit
ba85053
·
verified ·
1 Parent(s): 297651f

Upload 19 files

Browse files
Files changed (1) hide show
  1. app.py +17 -2
app.py CHANGED
@@ -563,8 +563,16 @@ async def get_system_config(config_key: str, current_user: str = Depends(require
563
  raise ValueError("invalid configuration constant")
564
  try:
565
  # 管理回读用于确认SQL保存结果,不能用另一个来源的旧值代替。
566
- row = db.query(SystemConfig).filter(SystemConfig.config_key == config_key).first()
 
567
  value = None if row is None else json.loads(row.config_value, parse_constant=reject_constant)
 
 
 
 
 
 
 
568
  except Exception:
569
  raise HTTPException(status_code=503, detail="config_read_unavailable") from None
570
  return {"status": "success", "data": value}
@@ -621,8 +629,15 @@ async def set_system_config(config_key: str, value: dict, current_user: str = De
621
  # 🔒 权限验证
622
  if not _is_admin(current_user):
623
  raise HTTPException(status_code=403, detail="无权修改系统配置,仅管理员可操作")
 
 
 
 
 
 
 
624
  try:
625
- _save_system_config_to_db(db, config_key, value, updated_by=current_user, strict=True)
626
  except Exception:
627
  raise HTTPException(status_code=503, detail="config_save_unconfirmed") from None
628
  return {"status": "success", "message": "配置已更新"}
 
563
  raise ValueError("invalid configuration constant")
564
  try:
565
  # 管理回读用于确认SQL保存结果,不能用另一个来源的旧值代替。
566
+ storage_key = "image_moderation_enabled" if config_key == "image_moderation" else config_key
567
+ row = db.query(SystemConfig).filter(SystemConfig.config_key == storage_key).first()
568
  value = None if row is None else json.loads(row.config_value, parse_constant=reject_constant)
569
+ if config_key == "image_moderation":
570
+ if row is None:
571
+ from image_moderation import _is_moderation_enabled
572
+ value = _is_moderation_enabled()
573
+ if type(value) is not bool:
574
+ raise ValueError("invalid moderation configuration")
575
+ value = {"enabled": value}
576
  except Exception:
577
  raise HTTPException(status_code=503, detail="config_read_unavailable") from None
578
  return {"status": "success", "data": value}
 
629
  # 🔒 权限验证
630
  if not _is_admin(current_user):
631
  raise HTTPException(status_code=403, detail="无权修改系统配置,仅管理员可操作")
632
+ storage_key = config_key
633
+ storage_value = value
634
+ if config_key == "image_moderation":
635
+ if set(value) != {"enabled"} or type(value["enabled"]) is not bool:
636
+ raise HTTPException(status_code=400, detail="invalid_moderation_configuration")
637
+ storage_key = "image_moderation_enabled"
638
+ storage_value = value["enabled"]
639
  try:
640
+ _save_system_config_to_db(db, storage_key, storage_value, updated_by=current_user, strict=True)
641
  except Exception:
642
  raise HTTPException(status_code=503, detail="config_save_unconfirmed") from None
643
  return {"status": "success", "message": "配置已更新"}