From 1d1128cf945c4615efa05cf41ba7fa766e2ee428 Mon Sep 17 00:00:00 2001 From: MHSanaei Date: Wed, 24 Jun 2026 18:24:54 +0200 Subject: [PATCH] fix(update): read setUpdateChannel body as form field, not JSON The panel's axios layer posts application/x-www-form-urlencoded, so the dev-channel toggle sent dev=true and ShouldBindJSON failed with 'invalid character d'. Parse c.PostForm("dev") to match the codebase's form-encoded POST convention. --- frontend/public/openapi.json | 3 --- frontend/src/pages/api-docs/endpoints.ts | 5 ++++- internal/web/controller/server.go | 8 +++----- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/frontend/public/openapi.json b/frontend/public/openapi.json index 1b0b04124..22dad2a2a 100644 --- a/frontend/public/openapi.json +++ b/frontend/public/openapi.json @@ -4253,9 +4253,6 @@ "application/json": { "schema": { "type": "object" - }, - "example": { - "dev": true } } } diff --git a/frontend/src/pages/api-docs/endpoints.ts b/frontend/src/pages/api-docs/endpoints.ts index dc3b58b60..794982433 100644 --- a/frontend/src/pages/api-docs/endpoints.ts +++ b/frontend/src/pages/api-docs/endpoints.ts @@ -404,7 +404,10 @@ export const sections: readonly Section[] = [ method: 'POST', path: '/panel/api/server/setUpdateChannel', summary: 'Toggle the panel update channel between stable and the rolling per-commit dev release. Only effective on dev builds.', - body: '{\n "dev": true\n}', + params: [ + { name: 'dev', in: 'body (form)', type: 'boolean', desc: 'true = dev channel, false = stable.' }, + ], + body: 'dev=true', }, { method: 'POST', diff --git a/internal/web/controller/server.go b/internal/web/controller/server.go index aeef01700..27ced715c 100644 --- a/internal/web/controller/server.go +++ b/internal/web/controller/server.go @@ -214,14 +214,12 @@ func (a *ServerController) updatePanel(c *gin.Context) { // setUpdateChannel toggles whether self-update tracks the rolling dev release. func (a *ServerController) setUpdateChannel(c *gin.Context) { - var req struct { - Dev bool `json:"dev"` - } - if err := c.ShouldBindJSON(&req); err != nil { + dev, err := strconv.ParseBool(c.PostForm("dev")) + if err != nil { jsonMsg(c, "invalid data", err) return } - err := a.settingService.SetDevChannelEnable(req.Dev) + err = a.settingService.SetDevChannelEnable(dev) jsonMsg(c, I18nWeb(c, "pages.index.updateChannelChanged"), err) }