41 lines
1.3 KiB
PHP
41 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
|
|
|
|
use Pterodactyl\Models\Server;
|
|
use Pterodactyl\Transformers\Api\Client\ServerTransformer;
|
|
use Pterodactyl\Services\Servers\GetUserPermissionsService;
|
|
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
|
use Pterodactyl\Http\Requests\Api\Client\Servers\GetServerRequest;
|
|
|
|
class ServerController extends ClientApiController
|
|
{
|
|
private GetUserPermissionsService $permissionsService;
|
|
|
|
/**
|
|
* ServerController constructor.
|
|
*/
|
|
public function __construct(GetUserPermissionsService $permissionsService)
|
|
{
|
|
parent::__construct();
|
|
|
|
$this->permissionsService = $permissionsService;
|
|
}
|
|
|
|
/**
|
|
* Transform an individual server into a response that can be consumed by a
|
|
* client using the API.
|
|
*
|
|
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
|
*/
|
|
public function index(GetServerRequest $request, Server $server): array
|
|
{
|
|
return $this->fractal->item($server)
|
|
->transformWith(ServerTransformer::class)
|
|
->addMeta([
|
|
'is_server_owner' => $request->user()->id === $server->owner_id,
|
|
'user_permissions' => $this->permissionsService->handle($server, $request->user()),
|
|
])
|
|
->toArray();
|
|
}
|
|
}
|