Update endpoints for managing backups
This commit is contained in:
parent
0a20c6b857
commit
81f7734df2
4 changed files with 61 additions and 72 deletions
|
@ -0,0 +1,55 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Pterodactyl\Http\Controllers\Api\Remote\Backups;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Pterodactyl\Http\Controllers\Controller;
|
||||||
|
use Pterodactyl\Repositories\Eloquent\BackupRepository;
|
||||||
|
use Pterodactyl\Http\Requests\Api\Remote\ReportBackupCompleteRequest;
|
||||||
|
|
||||||
|
class BackupStatusController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var \Pterodactyl\Repositories\Eloquent\BackupRepository
|
||||||
|
*/
|
||||||
|
private $repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BackupStatusController constructor.
|
||||||
|
*
|
||||||
|
* @param \Pterodactyl\Repositories\Eloquent\BackupRepository $repository
|
||||||
|
*/
|
||||||
|
public function __construct(BackupRepository $repository)
|
||||||
|
{
|
||||||
|
$this->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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,68 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Pterodactyl\Http\Controllers\Api\Remote\Servers;
|
|
||||||
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use Illuminate\Http\JsonResponse;
|
|
||||||
use Pterodactyl\Http\Controllers\Controller;
|
|
||||||
use Pterodactyl\Repositories\Eloquent\BackupRepository;
|
|
||||||
use Pterodactyl\Repositories\Eloquent\ServerRepository;
|
|
||||||
use Pterodactyl\Http\Requests\Api\Remote\ReportBackupCompleteRequest;
|
|
||||||
|
|
||||||
class ServerBackupController extends Controller
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var \Pterodactyl\Repositories\Eloquent\BackupRepository
|
|
||||||
*/
|
|
||||||
private $repository;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \Pterodactyl\Repositories\Eloquent\ServerRepository
|
|
||||||
*/
|
|
||||||
private $serverRepository;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ServerBackupController constructor.
|
|
||||||
*
|
|
||||||
* @param \Pterodactyl\Repositories\Eloquent\BackupRepository $repository
|
|
||||||
* @param \Pterodactyl\Repositories\Eloquent\ServerRepository $serverRepository
|
|
||||||
*/
|
|
||||||
public function __construct(BackupRepository $repository, ServerRepository $serverRepository)
|
|
||||||
{
|
|
||||||
$this->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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -13,8 +13,8 @@ class ReportBackupCompleteRequest extends FormRequest
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'successful' => 'boolean',
|
'successful' => 'boolean',
|
||||||
'sha256_hash' => 'string|required_if:successful,true',
|
'checksum' => 'string|required_if:successful,true',
|
||||||
'file_size' => 'numeric|required_if:successful,true',
|
'size' => 'numeric|required_if:successful,true',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,8 @@ Route::group(['prefix' => '/servers/{uuid}'], function () {
|
||||||
Route::post('/archive', 'Servers\ServerTransferController@archive');
|
Route::post('/archive', 'Servers\ServerTransferController@archive');
|
||||||
Route::get('/transfer/failure', 'Servers\ServerTransferController@failure');
|
Route::get('/transfer/failure', 'Servers\ServerTransferController@failure');
|
||||||
Route::get('/transfer/success', 'Servers\ServerTransferController@success');
|
Route::get('/transfer/success', 'Servers\ServerTransferController@success');
|
||||||
|
});
|
||||||
Route::post('/backup/{backup}', 'Servers\ServerBackupController');
|
|
||||||
|
Route::group(['prefix' => '/backups'], function () {
|
||||||
|
Route::post('/{backup}', 'Backups\BackupStatusController');
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue