From 81f7734df262d09ce809f007095d288fdf277a95 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Fri, 17 Apr 2020 10:21:51 -0700 Subject: [PATCH] Update endpoints for managing backups --- .../Remote/Backups/BackupStatusController.php | 55 +++++++++++++++ .../Remote/Servers/ServerBackupController.php | 68 ------------------- .../Remote/ReportBackupCompleteRequest.php | 4 +- routes/api-remote.php | 6 +- 4 files changed, 61 insertions(+), 72 deletions(-) create mode 100644 app/Http/Controllers/Api/Remote/Backups/BackupStatusController.php delete mode 100644 app/Http/Controllers/Api/Remote/Servers/ServerBackupController.php diff --git a/app/Http/Controllers/Api/Remote/Backups/BackupStatusController.php b/app/Http/Controllers/Api/Remote/Backups/BackupStatusController.php new file mode 100644 index 000000000..bb7d94c14 --- /dev/null +++ b/app/Http/Controllers/Api/Remote/Backups/BackupStatusController.php @@ -0,0 +1,55 @@ +repository = $repository; + } + + /** + * Handles updating the state of a backup. + * + * @param \Pterodactyl\Http\Requests\Api\Remote\ReportBackupCompleteRequest $request + * @param string $backup + * @return \Illuminate\Http\JsonResponse + * + * @throws \Pterodactyl\Exceptions\Model\DataValidationException + * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException + */ + public function __invoke(ReportBackupCompleteRequest $request, string $backup) + { + /** @var \Pterodactyl\Models\Backup $backup */ + $backup = $this->repository->findFirstWhere([['uuid', '=', $backup]]); + + if ($request->input('successful')) { + $this->repository->update($backup->id, [ + 'sha256_hash' => $request->input('checksum'), + 'bytes' => $request->input('size'), + 'completed_at' => Carbon::now(), + ], true, true); + } else { + $this->repository->delete($backup->id); + } + + return JsonResponse::create([], JsonResponse::HTTP_NO_CONTENT); + } +} diff --git a/app/Http/Controllers/Api/Remote/Servers/ServerBackupController.php b/app/Http/Controllers/Api/Remote/Servers/ServerBackupController.php deleted file mode 100644 index 8daee56af..000000000 --- a/app/Http/Controllers/Api/Remote/Servers/ServerBackupController.php +++ /dev/null @@ -1,68 +0,0 @@ -repository = $repository; - $this->serverRepository = $serverRepository; - } - - /** - * Updates a server backup's state in the database depending on wether or not - * it was successful. - * - * @param \Pterodactyl\Http\Requests\Api\Remote\ReportBackupCompleteRequest $request - * @param string $uuid - * @param string $backup - * @return \Illuminate\Http\JsonResponse - * - * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException - */ - public function __invoke(ReportBackupCompleteRequest $request, string $uuid, string $backup) - { - $server = $this->serverRepository->getByUuid($uuid); - - $where = [ - ['uuid', '=', $backup], - ['server_id', '=', $server->id], - ]; - - if ($request->input('successful')) { - $this->repository->updateWhere($where, [ - 'sha256_hash' => $request->input('sha256_hash'), - 'bytes' => $request->input('file_size'), - 'completed_at' => Carbon::now(), - ]); - } else { - $this->repository->deleteWhere($where); - } - - return JsonResponse::create([], JsonResponse::HTTP_NO_CONTENT); - } -} diff --git a/app/Http/Requests/Api/Remote/ReportBackupCompleteRequest.php b/app/Http/Requests/Api/Remote/ReportBackupCompleteRequest.php index b0383b963..d115fc50c 100644 --- a/app/Http/Requests/Api/Remote/ReportBackupCompleteRequest.php +++ b/app/Http/Requests/Api/Remote/ReportBackupCompleteRequest.php @@ -13,8 +13,8 @@ class ReportBackupCompleteRequest extends FormRequest { return [ 'successful' => 'boolean', - 'sha256_hash' => 'string|required_if:successful,true', - 'file_size' => 'numeric|required_if:successful,true', + 'checksum' => 'string|required_if:successful,true', + 'size' => 'numeric|required_if:successful,true', ]; } } diff --git a/routes/api-remote.php b/routes/api-remote.php index 3cf564e83..f85f2e8da 100644 --- a/routes/api-remote.php +++ b/routes/api-remote.php @@ -18,6 +18,8 @@ Route::group(['prefix' => '/servers/{uuid}'], function () { Route::post('/archive', 'Servers\ServerTransferController@archive'); Route::get('/transfer/failure', 'Servers\ServerTransferController@failure'); Route::get('/transfer/success', 'Servers\ServerTransferController@success'); - - Route::post('/backup/{backup}', 'Servers\ServerBackupController'); +}); + +Route::group(['prefix' => '/backups'], function () { + Route::post('/{backup}', 'Backups\BackupStatusController'); });