diff --git a/router/router_server.go b/router/router_server.go index 0412d7d..c866495 100644 --- a/router/router_server.go +++ b/router/router_server.go @@ -46,7 +46,10 @@ func postServerPower(c *gin.Context) { s := GetServer(c.Param("server")) var data server.PowerAction - c.BindJSON(&data) + // BindJSON sends 400 if the request fails, all we need to do is return + if err := c.BindJSON(&data); err != nil { + return + } if !data.IsValid() { c.AbortWithStatusJSON(http.StatusUnprocessableEntity, gin.H{ @@ -98,8 +101,13 @@ func postServerCommands(c *gin.Context) { return } - var data struct{ Commands []string `json:"commands"` } - c.BindJSON(&data) + var data struct { + Commands []string `json:"commands"` + } + // BindJSON sends 400 if the request fails, all we need to do is return + if err := c.BindJSON(&data); err != nil { + return + } for _, command := range data.Commands { if err := s.Environment.SendCommand(command); err != nil { diff --git a/router/router_server_backup.go b/router/router_server_backup.go index 2928b3c..a154542 100644 --- a/router/router_server_backup.go +++ b/router/router_server_backup.go @@ -15,7 +15,10 @@ func postServerBackup(c *gin.Context) { s := GetServer(c.Param("server")) data := &backup.Request{} - c.BindJSON(&data) + // BindJSON sends 400 if the request fails, all we need to do is return + if err := c.BindJSON(&data); err != nil { + return + } var adapter backup.BackupInterface var err error @@ -41,7 +44,6 @@ func postServerBackup(c *gin.Context) { } }(adapter, s) - c.Status(http.StatusAccepted) } diff --git a/router/router_server_files.go b/router/router_server_files.go index f0b28e6..09f1d3d 100644 --- a/router/router_server_files.go +++ b/router/router_server_files.go @@ -89,7 +89,10 @@ func putServerRenameFile(c *gin.Context) { RenameFrom string `json:"rename_from"` RenameTo string `json:"rename_to"` } - c.BindJSON(&data) + // BindJSON sends 400 if the request fails, all we need to do is return + if err := c.BindJSON(&data); err != nil { + return + } if data.RenameFrom == "" || data.RenameTo == "" { c.AbortWithStatusJSON(http.StatusUnprocessableEntity, gin.H{ @@ -113,7 +116,10 @@ func postServerCopyFile(c *gin.Context) { var data struct { Location string `json:"location"` } - c.BindJSON(&data) + // BindJSON sends 400 if the request fails, all we need to do is return + if err := c.BindJSON(&data); err != nil { + return + } if err := s.Filesystem.Copy(data.Location); err != nil { TrackedServerError(err, s).AbortWithServerError(c) @@ -130,7 +136,10 @@ func postServerDeleteFile(c *gin.Context) { var data struct { Location string `json:"location"` } - c.BindJSON(&data) + // BindJSON sends 400 if the request fails, all we need to do is return + if err := c.BindJSON(&data); err != nil { + return + } if err := s.Filesystem.Delete(data.Location); err != nil { TrackedServerError(err, s).AbortWithServerError(c) @@ -167,7 +176,10 @@ func postServerCreateDirectory(c *gin.Context) { Name string `json:"name"` Path string `json:"path"` } - c.BindJSON(&data) + // BindJSON sends 400 if the request fails, all we need to do is return + if err := c.BindJSON(&data); err != nil { + return + } if err := s.Filesystem.CreateDirectory(data.Name, data.Path); err != nil { TrackedServerError(err, s).AbortWithServerError(c) diff --git a/router/router_system.go b/router/router_system.go index 085f383..07553f6 100644 --- a/router/router_system.go +++ b/router/router_system.go @@ -77,7 +77,10 @@ func postUpdateConfiguration(c *gin.Context) { // A copy of the configuration we're using to bind the data recevied into. cfg := *config.Get() - c.BindJSON(&cfg) + // BindJSON sends 400 if the request fails, all we need to do is return + if err := c.BindJSON(&cfg); err != nil { + return + } config.Set(&cfg) if err := config.Get().WriteToDisk(); err != nil { @@ -90,4 +93,4 @@ func postUpdateConfiguration(c *gin.Context) { } c.Status(http.StatusNoContent) -} \ No newline at end of file +}