Cleanup remote backup controllers

This commit is contained in:
Matthew Penner 2020-12-06 15:19:54 -07:00
parent 1ce6d3bbba
commit 00429c3911
2 changed files with 8 additions and 19 deletions

View file

@ -6,9 +6,7 @@ use Carbon\CarbonImmutable;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Pterodactyl\Models\Backup; use Pterodactyl\Models\Backup;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Illuminate\Foundation\Application;
use League\Flysystem\AwsS3v3\AwsS3Adapter; use League\Flysystem\AwsS3v3\AwsS3Adapter;
use Illuminate\Contracts\Config\Repository;
use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Extensions\Backups\BackupManager; use Pterodactyl\Extensions\Backups\BackupManager;
use Pterodactyl\Repositories\Eloquent\BackupRepository; use Pterodactyl\Repositories\Eloquent\BackupRepository;
@ -18,11 +16,6 @@ class BackupRemoteUploadController extends Controller
{ {
const PART_SIZE = 5 * 1024 * 1024 * 1024; const PART_SIZE = 5 * 1024 * 1024 * 1024;
/**
* @var \Illuminate\Contracts\Config\Repository
*/
protected $config;
/** /**
* @var \Pterodactyl\Repositories\Eloquent\BackupRepository * @var \Pterodactyl\Repositories\Eloquent\BackupRepository
*/ */
@ -36,13 +29,11 @@ class BackupRemoteUploadController extends Controller
/** /**
* BackupRemoteUploadController constructor. * BackupRemoteUploadController constructor.
* *
* @param \Illuminate\Foundation\Application $app
* @param \Pterodactyl\Repositories\Eloquent\BackupRepository $repository * @param \Pterodactyl\Repositories\Eloquent\BackupRepository $repository
* @param \Pterodactyl\Extensions\Backups\BackupManager $backupManager * @param \Pterodactyl\Extensions\Backups\BackupManager $backupManager
*/ */
public function __construct(Application $app, BackupRepository $repository, BackupManager $backupManager) public function __construct(BackupRepository $repository, BackupManager $backupManager)
{ {
$this->config = $app->make(Repository::class);
$this->repository = $repository; $this->repository = $repository;
$this->backupManager = $backupManager; $this->backupManager = $backupManager;
} }
@ -86,7 +77,7 @@ class BackupRemoteUploadController extends Controller
// Get the S3 client // Get the S3 client
$client = $adapter->getClient(); $client = $adapter->getClient();
$expires = CarbonImmutable::now()->addMinutes($this->config->get('backups.presigned_url_lifespan', 60)); $expires = CarbonImmutable::now()->addMinutes(config('backups.presigned_url_lifespan', 60));
// Params for generating the presigned urls // Params for generating the presigned urls
$params = [ $params = [

View file

@ -60,7 +60,6 @@ class BackupStatusController extends Controller
$successful = $request->input('successful') ? true : false; $successful = $request->input('successful') ? true : false;
// TODO: Still run s3 code even if this fails.
$model->forceFill([ $model->forceFill([
'is_successful' => $successful, 'is_successful' => $successful,
'checksum' => $successful ? ($request->input('checksum_type') . ':' . $request->input('checksum')) : null, 'checksum' => $successful ? ($request->input('checksum_type') . ':' . $request->input('checksum')) : null,
@ -85,15 +84,14 @@ class BackupStatusController extends Controller
// If the backup was not successful, send an AbortMultipartUpload request. // If the backup was not successful, send an AbortMultipartUpload request.
if (! $successful) { if (! $successful) {
$client->execute($client->getCommand('AbortMultipartUpload', $params)); $client->execute($client->getCommand('AbortMultipartUpload', $params));
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); } else {
}
// Otherwise send a CompleteMultipartUpload request. // Otherwise send a CompleteMultipartUpload request.
$params['MultipartUpload'] = [ $params['MultipartUpload'] = [
'Parts' => $client->execute($client->getCommand('ListParts', $params))['Parts'], 'Parts' => $client->execute($client->getCommand('ListParts', $params))['Parts'],
]; ];
$client->execute($client->getCommand('CompleteMultipartUpload', $params)); $client->execute($client->getCommand('CompleteMultipartUpload', $params));
} }
}
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
} }