INNER CODE UNIT · Python
admin_update_config
SPThole/CoexistAI · app.py:232
async def admin_update_config(request: Request):
"""Overwrite the config file with the posted JSON body. Protected by ADMIN_TOKEN.
Body must be a JSON object compatible with the config schema. Returns saved config on success.
"""
token = request.headers.get('X-Admin-Token')
try:
_check_admin_token(token)
except HTTPException as e:
raise e
try:
body = await request.json()
except Exception:
raise HTTPException(status_code=400, detail='Invalid JSON body')
cfg_path = os.environ.get('CONFIG_PATH', os.path.join(os.path.dirname(__file__), 'config', 'model_config.json'))
cfg_dir = os.path.dirname(cfg_path)
os.makedirs(cfg_dir, exist_ok=True)