diff --git a/docs/Tasktracking/2026-04-27-fix-batch-edit-shouldbindjson.md b/docs/Tasktracking/2026-04-27-fix-batch-edit-shouldbindjson.md new file mode 100644 index 00000000..2c34e9e2 --- /dev/null +++ b/docs/Tasktracking/2026-04-27-fix-batch-edit-shouldbindjson.md @@ -0,0 +1,27 @@ +# Task Record + +Date: 2026-04-27 +Related Module: web/controller/inbound.go +Change Type: Fix + +## Background +批量编辑(batch edit)功能提示 "入站连接已成功更新 (invalid character 'i' looking for beginning of value)",操作实际未生效。 + +根因:前端全局 axios 配置将 POST Content-Type 设为 `application/x-www-form-urlencoded`,请求拦截器用 `Qs.stringify` 将数据转为 URL-encoded 格式。但 `batchUpdateInboundClients` 处理器使用了 `c.ShouldBindJSON`,它只接受 JSON 格式。form-encoded 数据(如 `inboundId=123&...`)以 `i` 开头,导致 Go JSON 解析器报 `invalid character 'i' looking for beginning of value`。 + +项目中其他所有 handler(`addInbound`、`updateInbound`、`addClient` 等)均使用 `c.ShouldBind`(根据 Content-Type 自动选择绑定方式),仅在 batchUpdateInboundClients 中使用了 `ShouldBindJSON`,导致不一致。 + +## Changes +- `web/controller/inbound.go:481`: `c.ShouldBindJSON(&request)` → `c.ShouldBind(&request)` + +## Impact +- `ShouldBind` 会根据 Content-Type 自动选择 form 绑定(浏览器请求)或 JSON 绑定(其他客户端),与项目其他 handler 一致 +- 向后兼容:JSON 请求依然能被正确解析 +- 不影响数据库、API、配置 + +## Verification +- `gofmt -l -w .` — 无格式问题 +- `go vet ./web/controller/...` — 通过 + +## Risks And Follow-Up +- 低风险,单行变更,与项目现有代码风格一致 diff --git a/web/controller/inbound.go b/web/controller/inbound.go index c64cd309..8fa7e455 100644 --- a/web/controller/inbound.go +++ b/web/controller/inbound.go @@ -478,7 +478,7 @@ func (a *InboundController) batchUpdateInboundClients(c *gin.Context) { ClientIDs []string `json:"clientIds"` UpdateFields string `json:"updateFields"` } - if err := c.ShouldBindJSON(&request); err != nil { + if err := c.ShouldBind(&request); err != nil { jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err) return }