2018-02-28 03:28:43 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
|
|
|
|
|
|
|
|
use Pterodactyl\Models\Server;
|
|
|
|
use Pterodactyl\Transformers\Api\Client\ServerTransformer;
|
2020-04-17 17:21:15 +00:00
|
|
|
use Pterodactyl\Services\Servers\GetUserPermissionsService;
|
2018-02-28 03:28:43 +00:00
|
|
|
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
|
|
|
use Pterodactyl\Http\Requests\Api\Client\Servers\GetServerRequest;
|
|
|
|
|
|
|
|
class ServerController extends ClientApiController
|
|
|
|
{
|
2020-03-22 23:56:00 +00:00
|
|
|
/**
|
|
|
|
* ServerController constructor.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function __construct(private GetUserPermissionsService $permissionsService)
|
2020-03-22 23:56:00 +00:00
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
2018-02-28 03:28:43 +00:00
|
|
|
/**
|
|
|
|
* Transform an individual server into a response that can be consumed by a
|
|
|
|
* client using the API.
|
|
|
|
*/
|
2019-09-06 04:41:20 +00:00
|
|
|
public function index(GetServerRequest $request, Server $server): array
|
2018-02-28 03:28:43 +00:00
|
|
|
{
|
2019-09-06 04:41:20 +00:00
|
|
|
return $this->fractal->item($server)
|
2022-12-15 00:05:46 +00:00
|
|
|
->transformWith(ServerTransformer::class)
|
2020-03-22 23:56:00 +00:00
|
|
|
->addMeta([
|
|
|
|
'is_server_owner' => $request->user()->id === $server->owner_id,
|
2020-04-17 17:21:15 +00:00
|
|
|
'user_permissions' => $this->permissionsService->handle($server, $request->user()),
|
2020-03-22 23:56:00 +00:00
|
|
|
])
|
2018-02-28 03:28:43 +00:00
|
|
|
->toArray();
|
|
|
|
}
|
|
|
|
}
|