Set UA and limit simultaneous downloads
This commit is contained in:
		
							parent
							
								
									184013b652
								
							
						
					
					
						commit
						f7f5623c71
					
				|  | @ -4,8 +4,10 @@ import ( | ||||||
| 	"context" | 	"context" | ||||||
| 	"emperror.dev/errors" | 	"emperror.dev/errors" | ||||||
| 	"encoding/json" | 	"encoding/json" | ||||||
|  | 	"fmt" | ||||||
| 	"github.com/google/uuid" | 	"github.com/google/uuid" | ||||||
| 	"github.com/pterodactyl/wings/server" | 	"github.com/pterodactyl/wings/server" | ||||||
|  | 	"github.com/pterodactyl/wings/system" | ||||||
| 	"io" | 	"io" | ||||||
| 	"net/http" | 	"net/http" | ||||||
| 	"net/url" | 	"net/url" | ||||||
|  | @ -109,6 +111,7 @@ func (dl *Download) Execute() error { | ||||||
| 	defer dl.Cancel() | 	defer dl.Cancel() | ||||||
| 
 | 
 | ||||||
| 	req, _ := http.NewRequestWithContext(ctx, http.MethodGet, dl.req.URL.String(), nil) | 	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) | 	res, err := client.Do(req) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return errors.New("downloader: failed opening request to download file") | 		return errors.New("downloader: failed opening request to download file") | ||||||
|  |  | ||||||
|  | @ -271,6 +271,13 @@ func postServerPullRemoteFile(c *gin.Context) { | ||||||
| 		WithError(c, err) | 		WithError(c, err) | ||||||
| 		return | 		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{ | 	dl := downloader.New(s, downloader.DownloadRequest{ | ||||||
| 		URL:       u, | 		URL:       u, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user