mirror of
https://github.com/OwO-Network/DeepLX.git
synced 2026-06-11 15:28:50 +00:00
fix(service): validate request body on /translate and /v1/translate (#225)
The two handlers ignored the error from c.BindJSON, so a malformed JSON body was silently processed as an empty payload. Check the error and return 400, consistent with /v2/translate.
This commit is contained in:
parent
3f099d187c
commit
d19a3902df
@ -108,7 +108,13 @@ func Router(cfg *Config) *gin.Engine {
|
||||
// Free API endpoint, No Pro Account required
|
||||
r.POST("/translate", authMiddleware(cfg), func(c *gin.Context) {
|
||||
req := PayloadFree{}
|
||||
c.BindJSON(&req)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"code": http.StatusBadRequest,
|
||||
"message": "Invalid request payload",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
sourceLang := req.SourceLang
|
||||
targetLang := req.TargetLang
|
||||
@ -156,7 +162,13 @@ func Router(cfg *Config) *gin.Engine {
|
||||
// Pro API endpoint, Pro Account required
|
||||
r.POST("/v1/translate", authMiddleware(cfg), func(c *gin.Context) {
|
||||
req := PayloadFree{}
|
||||
c.BindJSON(&req)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"code": http.StatusBadRequest,
|
||||
"message": "Invalid request payload",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
sourceLang := req.SourceLang
|
||||
targetLang := req.TargetLang
|
||||
|
||||
Loading…
Reference in New Issue
Block a user