Actually enforce upload file size limit (#122)
This commit is contained in:
parent
f85509a0c7
commit
067ca5bb60
|
@ -89,8 +89,8 @@ type ApiConfiguration struct {
|
||||||
// servers.
|
// servers.
|
||||||
DisableRemoteDownload bool `json:"disable_remote_download" yaml:"disable_remote_download"`
|
DisableRemoteDownload bool `json:"disable_remote_download" yaml:"disable_remote_download"`
|
||||||
|
|
||||||
// The maximum size for files uploaded through the Panel in bytes.
|
// The maximum size for files uploaded through the Panel in MB.
|
||||||
UploadLimit int `default:"100" json:"upload_limit" yaml:"upload_limit"`
|
UploadLimit int64 `default:"100" json:"upload_limit" yaml:"upload_limit"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoteQueryConfiguration defines the configuration settings for remote requests
|
// RemoteQueryConfiguration defines the configuration settings for remote requests
|
||||||
|
|
|
@ -3,6 +3,7 @@ package router
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"context"
|
"context"
|
||||||
|
"github.com/pterodactyl/wings/config"
|
||||||
"io"
|
"io"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -537,8 +538,16 @@ func postServerUploadFiles(c *gin.Context) {
|
||||||
|
|
||||||
directory := c.Query("directory")
|
directory := c.Query("directory")
|
||||||
|
|
||||||
|
maxFileSize := config.Get().Api.UploadLimit
|
||||||
|
maxFileSizeBytes := maxFileSize * 1024 * 1024
|
||||||
var totalSize int64
|
var totalSize int64
|
||||||
for _, header := range headers {
|
for _, header := range headers {
|
||||||
|
if header.Size > maxFileSizeBytes {
|
||||||
|
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{
|
||||||
|
"error": "File " + header.Filename + " is larger than the maximum file upload size of " + strconv.FormatInt(maxFileSize, 10) + " MB.",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
totalSize += header.Size
|
totalSize += header.Size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user