MCPcopy Index your code
hub / github.com/vastsa/FileCodeBox / update_config

Method update_config

apps/admin/services.py:1524–1561  ·  view source on GitHub ↗
(self, data: dict)

Source from the content-addressed store, hash-verified

1522 return config
1523
1524 async def update_config(self, data: dict):
1525 current_config = dict(settings.items())
1526 next_config = dict(current_config)
1527 update_data = {
1528 key: value
1529 for key, value in data.items()
1530 if key in settings.default_config and key not in INTERNAL_CONFIG_KEYS
1531 }
1532
1533 admin_token = update_data.get("admin_token")
1534 admin_password_changed = False
1535 if admin_token is None or admin_token == "":
1536 update_data.pop("admin_token", None)
1537 elif not is_password_hashed(admin_token):
1538 update_data["admin_token"] = hash_password(admin_token)
1539 admin_password_changed = True
1540 else:
1541 admin_password_changed = True
1542
1543 for key, value in update_data.items():
1544 if value == "" and key in self.INT_FIELDS | self.FLOAT_FIELDS:
1545 continue
1546
1547 try:
1548 if key in self.INT_FIELDS:
1549 next_config[key] = int(value)
1550 elif key in self.FLOAT_FIELDS:
1551 next_config[key] = float(value)
1552 else:
1553 next_config[key] = value
1554 except (TypeError, ValueError):
1555 raise HTTPException(status_code=400, detail=f"{key} 配置值格式错误")
1556
1557 if admin_password_changed:
1558 next_config["jwt_secret"] = generate_jwt_secret()
1559
1560 await KeyValue.update_or_create(key="settings", defaults={"value": next_config})
1561 await refresh_settings()
1562
1563
1564class LocalFileService:

Callers 2

update_configFunction · 0.80

Calls 6

is_password_hashedFunction · 0.90
hash_passwordFunction · 0.90
generate_jwt_secretFunction · 0.90
refresh_settingsFunction · 0.90
itemsMethod · 0.80
update_or_createMethod · 0.45