Add API endpoint to get a server by external ID
This commit is contained in:
parent
a1e704d3a7
commit
fb1b2406b5
4 changed files with 82 additions and 0 deletions
|
@ -14,6 +14,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
|
|||
* Adds ability to include egg variables on an API request.
|
||||
* Added `external_id` column to servers that allows for easier linking with external services such as WHMCS.
|
||||
* Added back the sidebar when viewing servers that allows for quick-switching to a different server.
|
||||
* Added API endpoint to get a server by external ID.
|
||||
|
||||
## v0.7.1 (Derelict Dermodactylus)
|
||||
### Fixed
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Http\Controllers\Api\Application\Servers;
|
||||
|
||||
use Pterodactyl\Transformers\Api\Application\ServerTransformer;
|
||||
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
|
||||
use Pterodactyl\Http\Requests\Api\Application\Servers\GetExternalServerRequest;
|
||||
|
||||
class ExternalServerController extends ApplicationApiController
|
||||
{
|
||||
/**
|
||||
* Retrieve a specific server from the database using its external ID.
|
||||
*
|
||||
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\GetExternalServerRequest $request
|
||||
* @return array
|
||||
*/
|
||||
public function index(GetExternalServerRequest $request): array
|
||||
{
|
||||
return $this->fractal->item($request->getServerModel())
|
||||
->transformWith($this->getTransformer(ServerTransformer::class))
|
||||
->toArray();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Http\Requests\Api\Application\Servers;
|
||||
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
class GetExternalServerRequest extends ApplicationApiRequest
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Models\Server
|
||||
*/
|
||||
private $serverModel;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource = AdminAcl::RESOURCE_SERVERS;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $permission = AdminAcl::READ;
|
||||
|
||||
/**
|
||||
* Determine if the requested external user exists.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function resourceExists(): bool
|
||||
{
|
||||
$repository = $this->container->make(ServerRepositoryInterface::class);
|
||||
|
||||
try {
|
||||
$this->serverModel = $repository->findFirstWhere([
|
||||
['external_id', '=', $this->route()->parameter('external_id')],
|
||||
]);
|
||||
} catch (RecordNotFoundException $exception) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the server model for the requested external server.
|
||||
*
|
||||
* @return \Pterodactyl\Models\Server
|
||||
*/
|
||||
public function getServerModel(): Server
|
||||
{
|
||||
return $this->serverModel;
|
||||
}
|
||||
}
|
|
@ -74,6 +74,7 @@ Route::group(['prefix' => '/locations'], function () {
|
|||
Route::group(['prefix' => '/servers'], function () {
|
||||
Route::get('/', 'Servers\ServerController@index')->name('api.application.servers');
|
||||
Route::get('/{server}', 'Servers\ServerController@view')->name('api.application.servers.view');
|
||||
Route::get('/external/{external_id}', 'Servers\ExternalServerController@index')->name('api.application.servers.external');
|
||||
|
||||
Route::patch('/{server}/details', 'Servers\ServerDetailsController@details')->name('api.application.servers.details');
|
||||
Route::patch('/{server}/build', 'Servers\ServerDetailsController@build')->name('api.application.servers.build');
|
||||
|
|
Loading…
Reference in a new issue