1
1
mirror of https://github.com/pterodactyl/panel.git synced 2024-11-23 01:22:30 +01:00

Merge branch 'develop' into feature/server-transfers-actually

This commit is contained in:
Matthew Penner 2020-04-04 17:09:39 -06:00 committed by GitHub
commit 7b518325c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 105 additions and 0 deletions

View File

@ -0,0 +1,70 @@
<?php
namespace Pterodactyl\Http\Controllers\Api\Remote\Servers;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Pterodactyl\Models\Server;
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);
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace Pterodactyl\Http\Requests\Api\Remote;
use Illuminate\Foundation\Http\FormRequest;
class ReportBackupCompleteRequest extends FormRequest
{
/**
* @return string[]
*/
public function rules()
{
return [
'successful' => 'boolean',
'sha256_hash' => 'string|required_if:successful,true',
'file_size' => 'numeric|required_if:successful,true',
];
}
}

View File

@ -177,6 +177,18 @@ abstract class EloquentRepository extends Repository implements RepositoryInterf
return ($this->withFresh) ? $instance->fresh() : $saved;
}
/**
* Update a model using the attributes passed.
*
* @param array|\Closure $attributes
* @param array $values
* @return int
*/
public function updateWhere($attributes, array $values)
{
return $this->getBuilder()->where($attributes)->update($values);
}
/**
* Perform a mass update where matching records are updated using whereIn.
* This does not perform any model data validation.

View File

@ -11,7 +11,10 @@ Route::group(['prefix' => '/servers/{uuid}'], function () {
Route::get('/', 'Servers\ServerDetailsController');
Route::get('/install', 'Servers\ServerInstallController@index');
Route::post('/install', 'Servers\ServerInstallController@store');
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');
});