From b87dcf22757e8bf55083d3bc7a3f0380576b9e40 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Wed, 17 Dec 2025 17:19:35 +0800 Subject: [PATCH] refactor: improve provider source ID validation to prevent duplicates during configuration updates --- astrbot/dashboard/routes/config.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/astrbot/dashboard/routes/config.py b/astrbot/dashboard/routes/config.py index 606e3df5e..abfff529b 100644 --- a/astrbot/dashboard/routes/config.py +++ b/astrbot/dashboard/routes/config.py @@ -243,7 +243,7 @@ class ConfigRoute(Route): return Response().error("缺少配置数据").__dict__ new_source_config = post_data.get("config") or post_data - original_id = post_data.get("original_id") or provider_source_id + original_id = provider_source_id if not isinstance(new_source_config, dict): return Response().error("缺少或错误的配置数据").__dict__ @@ -254,6 +254,16 @@ class ConfigRoute(Route): provider_sources = self.config.get("provider_sources", []) + for ps in provider_sources: + if ps.get("id") == new_source_config["id"] and ps.get("id") != original_id: + return ( + Response() + .error( + f"Provider source ID '{new_source_config['id']}' exists already, please try another ID.", + ) + .__dict__ + ) + # 查找旧的 provider_source,若不存在则追加为新配置 target_idx = next( (i for i, ps in enumerate(provider_sources) if ps.get("id") == original_id),