mirror of
https://github.com/pyrohost/pyrodactyl.git
synced 2026-04-06 04:01:58 +02:00
fix: backups ratelimiting being dumb
This commit is contained in:
@@ -42,4 +42,16 @@ class BackupRepository extends EloquentRepository
|
||||
->orWhere('is_successful', true);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns backups that are currently in progress for a specific server.
|
||||
*/
|
||||
public function getBackupsInProgress(int $serverId): Collection
|
||||
{
|
||||
return $this->getBuilder()
|
||||
->where('server_id', $serverId)
|
||||
->whereNull('completed_at')
|
||||
->get()
|
||||
->toBase();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace Pterodactyl\Services\Backups;
|
||||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Webmozart\Assert\Assert;
|
||||
use Pterodactyl\Models\Backup;
|
||||
use Pterodactyl\Models\Server;
|
||||
@@ -78,15 +77,10 @@ class InitiateBackupService
|
||||
// Validate server state before creating backup
|
||||
$this->validateServerForBackup($server);
|
||||
|
||||
$limit = config('backups.throttles.limit');
|
||||
$period = config('backups.throttles.period');
|
||||
if ($period > 0) {
|
||||
$previous = $this->repository->getBackupsGeneratedDuringTimespan($server->id, $period);
|
||||
if ($previous->count() >= $limit) {
|
||||
$message = sprintf('Only %d backups may be generated within a %d second span of time.', $limit, $period);
|
||||
|
||||
throw new TooManyRequestsHttpException((int) CarbonImmutable::now()->diffInSeconds($previous->last()->created_at->addSeconds($period)), $message);
|
||||
}
|
||||
// Check for existing backups in progress (only allow one at a time)
|
||||
$inProgressBackups = $this->repository->getBackupsInProgress($server->id);
|
||||
if ($inProgressBackups->count() > 0) {
|
||||
throw new TooManyRequestsHttpException(30, 'A backup is already in progress. Please wait for it to complete before starting another.');
|
||||
}
|
||||
|
||||
// Check if the server has reached or exceeded its backup limit.
|
||||
|
||||
@@ -21,16 +21,6 @@ return [
|
||||
// to 6 hours. To disable this feature, set the value to `0`.
|
||||
'prune_age' => env('BACKUP_PRUNE_AGE', 360),
|
||||
|
||||
// Defines the backup creation throttle limits for users. In this default example, we allow
|
||||
// a user to create two (successful or pending) backups per 10 minutes. Even if they delete
|
||||
// a backup it will be included in the throttle count.
|
||||
//
|
||||
// Set the period to "0" to disable this throttle. The period is defined in seconds.
|
||||
'throttles' => [
|
||||
'limit' => env('BACKUP_THROTTLE_LIMIT', 2),
|
||||
'period' => env('BACKUP_THROTTLE_PERIOD', 600),
|
||||
],
|
||||
|
||||
'disks' => [
|
||||
// There is no configuration for the local disk for Wings. That configuration
|
||||
// is determined by the Daemon configuration, and not the Panel.
|
||||
|
||||
Reference in New Issue
Block a user