Set UA and limit simultaneous downloads

This commit is contained in:
Dane Everitt 2020-12-24 09:01:00 -08:00
parent 184013b652
commit f7f5623c71
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
2 changed files with 10 additions and 0 deletions

View File

@ -4,8 +4,10 @@ import (
"context"
"emperror.dev/errors"
"encoding/json"
"fmt"
"github.com/google/uuid"
"github.com/pterodactyl/wings/server"
"github.com/pterodactyl/wings/system"
"io"
"net/http"
"net/url"
@ -109,6 +111,7 @@ func (dl *Download) Execute() error {
defer dl.Cancel()
req, _ := http.NewRequestWithContext(ctx, http.MethodGet, dl.req.URL.String(), nil)
req.Header.Set("User-Agent", fmt.Sprintf("Pterodactyl Panel (Wings v%s) (https://pterodactyl.io)", system.Version))
res, err := client.Do(req)
if err != nil {
return errors.New("downloader: failed opening request to download file")

View File

@ -271,6 +271,13 @@ func postServerPullRemoteFile(c *gin.Context) {
WithError(c, err)
return
}
// Do not allow more than three simultaneous remote file downloads at one time.
if len(downloader.ByServer(s.Id())) >= 3 {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{
"error": "This server has reached its limit of 3 simultaneous remote file downloads at once. Please wait for one to complete before trying again.",
})
return
}
dl := downloader.New(s, downloader.DownloadRequest{
URL: u,