diff --git a/astrbot/dashboard/routes/config.py b/astrbot/dashboard/routes/config.py index 4d54d4b38..8a9bde030 100644 --- a/astrbot/dashboard/routes/config.py +++ b/astrbot/dashboard/routes/config.py @@ -852,16 +852,19 @@ class ConfigRoute(Route): async def post_update_platform(self): update_platform_config = await request.json - platform_id = update_platform_config.get("id", None) + origin_platform_id = update_platform_config.get("id", None) new_config = update_platform_config.get("config", None) - if not platform_id or not new_config: + if not origin_platform_id or not new_config: return Response().error("参数错误").__dict__ + + if origin_platform_id != new_config.get("id", None): + return Response().error("机器人名称不允许修改").__dict__ # 如果是支持统一 webhook 模式的平台,且启用了统一 webhook 模式,确保有 webhook_uuid ensure_platform_webhook_config(new_config) for i, platform in enumerate(self.config["platform"]): - if platform["id"] == platform_id: + if platform["id"] == origin_platform_id: self.config["platform"][i] = new_config break else: diff --git a/dashboard/src/components/platform/AddNewPlatform.vue b/dashboard/src/components/platform/AddNewPlatform.vue index c5cec502b..67b6b99da 100644 --- a/dashboard/src/components/platform/AddNewPlatform.vue +++ b/dashboard/src/components/platform/AddNewPlatform.vue @@ -394,6 +394,9 @@ export default { // 配置抽屉 showConfigDrawer: false, configDrawerTargetId: null, + + // 保存更新前的平台 ID,防止用户修改 ID 后丢失原始定位 + originalUpdatingPlatformId: null, }; }, setup() { @@ -481,6 +484,7 @@ export default { updatingPlatformConfig: { handler(newConfig) { if (this.updatingMode && newConfig && newConfig.id) { + this.originalUpdatingPlatformId = newConfig.id; this.getPlatformConfigs(newConfig.id); } }, @@ -533,6 +537,8 @@ export default { this.showConfigDrawer = false; this.configDrawerTargetId = null; + + this.originalUpdatingPlatformId = null; }, closeDialog() { this.resetForm(); @@ -624,7 +630,7 @@ export default { } }, async updatePlatform() { - let id = this.updatingPlatformConfig.id; + const id = this.originalUpdatingPlatformId || this.updatingPlatformConfig.id; if (!id) { this.loading = false; this.showError('更新失败,缺少平台 ID。'); @@ -633,11 +639,15 @@ export default { try { // 更新平台配置 - await axios.post('/api/config/platform/update', { + let resp = await axios.post('/api/config/platform/update', { id: id, config: this.updatingPlatformConfig - }); + }) + if (resp.data.status === 'error') { + throw new Error(resp.data.message || '平台更新失败'); + } + // 同时更新路由表 await this.saveRoutesInternal(); @@ -885,7 +895,10 @@ export default { // 内部保存路由表方法(不显示成功提示) async saveRoutesInternal() { - if (!this.updatingPlatformConfig || !this.updatingPlatformConfig.id) { + const originalPlatformId = this.originalUpdatingPlatformId || this.updatingPlatformConfig?.id; + const newPlatformId = this.updatingPlatformConfig?.id || originalPlatformId; + + if (!originalPlatformId && !newPlatformId) { throw new Error('无法获取平台 ID'); } @@ -895,9 +908,11 @@ export default { const fullRoutingTable = routesRes.data.data.routing; // 删除该平台的所有旧路由 - const platformId = this.updatingPlatformConfig.id; for (const umop in fullRoutingTable) { - if (this.isUmopMatchPlatform(umop, platformId)) { + if ( + (originalPlatformId && this.isUmopMatchPlatform(umop, originalPlatformId)) || + (newPlatformId && this.isUmopMatchPlatform(umop, newPlatformId)) + ) { delete fullRoutingTable[umop]; } } @@ -906,7 +921,8 @@ export default { for (const route of this.platformRoutes) { const messageType = route.messageType === '*' ? '*' : route.messageType; const sessionId = route.sessionId === '*' ? '*' : route.sessionId; - const newUmop = `${platformId}:${messageType}:${sessionId}`; + const platformIdForRoute = newPlatformId || originalPlatformId; + const newUmop = `${platformIdForRoute}:${messageType}:${sessionId}`; if (route.configId) { fullRoutingTable[newUmop] = route.configId;