api(application): v2 backport
This commit is contained in:
parent
4cd0bee231
commit
67bf3e342e
172 changed files with 2922 additions and 1579 deletions
|
@ -25,7 +25,7 @@ class AccountController extends ClientApiController
|
|||
public function index(Request $request): array
|
||||
{
|
||||
return $this->fractal->item($request->user())
|
||||
->transformWith($this->getTransformer(AccountTransformer::class))
|
||||
->transformWith(AccountTransformer::class)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ class ActivityLogController extends ClientApiController
|
|||
->appends($request->query());
|
||||
|
||||
return $this->fractal->collection($activity)
|
||||
->transformWith($this->getTransformer(ActivityLogTransformer::class))
|
||||
->transformWith(ActivityLogTransformer::class)
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ class ApiKeyController extends ClientApiController
|
|||
public function index(ClientApiRequest $request): array
|
||||
{
|
||||
return $this->fractal->collection($request->user()->apiKeys)
|
||||
->transformWith($this->getTransformer(ApiKeyTransformer::class))
|
||||
->transformWith(ApiKeyTransformer::class)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ class ApiKeyController extends ClientApiController
|
|||
->log();
|
||||
|
||||
return $this->fractal->item($token->accessToken)
|
||||
->transformWith($this->getTransformer(ApiKeyTransformer::class))
|
||||
->transformWith(ApiKeyTransformer::class)
|
||||
->addMeta(['secret_token' => $token->plainTextToken])
|
||||
->toArray();
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace Pterodactyl\Http\Controllers\Api\Client;
|
||||
|
||||
use Webmozart\Assert\Assert;
|
||||
use Pterodactyl\Transformers\Api\Client\BaseClientTransformer;
|
||||
use Pterodactyl\Transformers\Api\Transformer;
|
||||
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
|
||||
|
||||
abstract class ClientApiController extends ApplicationApiController
|
||||
|
@ -11,7 +11,7 @@ abstract class ClientApiController extends ApplicationApiController
|
|||
/**
|
||||
* Returns only the includes which are valid for the given transformer.
|
||||
*/
|
||||
protected function getIncludesForTransformer(BaseClientTransformer $transformer, array $merge = []): array
|
||||
protected function getIncludesForTransformer(Transformer $transformer, array $merge = []): array
|
||||
{
|
||||
$filtered = array_filter($this->parseIncludes(), function ($datum) use ($transformer) {
|
||||
return in_array($datum, $transformer->getAvailableIncludes());
|
||||
|
@ -35,22 +35,4 @@ abstract class ClientApiController extends ApplicationApiController
|
|||
return trim($item);
|
||||
}, explode(',', $includes));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an instance of an application transformer.
|
||||
*
|
||||
* @template T of \Pterodactyl\Transformers\Api\Client\BaseClientTransformer
|
||||
*
|
||||
* @param class-string<T> $abstract
|
||||
*
|
||||
* @return T
|
||||
*
|
||||
* @noinspection PhpDocSignatureInspection
|
||||
*/
|
||||
public function getTransformer(string $abstract)
|
||||
{
|
||||
Assert::subclassOf($abstract, BaseClientTransformer::class);
|
||||
|
||||
return $abstract::fromRequest($this->request);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ class ClientController extends ClientApiController
|
|||
public function index(GetServersRequest $request): array
|
||||
{
|
||||
$user = $request->user();
|
||||
$transformer = $this->getTransformer(ServerTransformer::class);
|
||||
$transformer = new ServerTransformer();
|
||||
|
||||
// Start the query builder and ensure we eager load any requested relationships from the request.
|
||||
$builder = QueryBuilder::for(
|
||||
|
|
|
@ -17,7 +17,7 @@ class SSHKeyController extends ClientApiController
|
|||
public function index(ClientApiRequest $request): array
|
||||
{
|
||||
return $this->fractal->collection($request->user()->sshKeys)
|
||||
->transformWith($this->getTransformer(UserSSHKeyTransformer::class))
|
||||
->transformWith(UserSSHKeyTransformer::class)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ class SSHKeyController extends ClientApiController
|
|||
->log();
|
||||
|
||||
return $this->fractal->item($model)
|
||||
->transformWith($this->getTransformer(UserSSHKeyTransformer::class))
|
||||
->transformWith(UserSSHKeyTransformer::class)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ class ActivityLogController extends ClientApiController
|
|||
->appends($request->query());
|
||||
|
||||
return $this->fractal->collection($activity)
|
||||
->transformWith($this->getTransformer(ActivityLogTransformer::class))
|
||||
->transformWith(ActivityLogTransformer::class)
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ class BackupController extends ClientApiController
|
|||
$limit = min($request->query('per_page') ?? 20, 50);
|
||||
|
||||
return $this->fractal->collection($server->backups()->paginate($limit))
|
||||
->transformWith($this->getTransformer(BackupTransformer::class))
|
||||
->transformWith(BackupTransformer::class)
|
||||
->addMeta([
|
||||
'backup_count' => $this->repository->getNonFailedBackups($server)->count(),
|
||||
])
|
||||
|
@ -84,7 +84,7 @@ class BackupController extends ClientApiController
|
|||
->log();
|
||||
|
||||
return $this->fractal->item($backup)
|
||||
->transformWith($this->getTransformer(BackupTransformer::class))
|
||||
->transformWith(BackupTransformer::class)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ class BackupController extends ClientApiController
|
|||
Activity::event($action)->subject($backup)->property('name', $backup->name)->log();
|
||||
|
||||
return $this->fractal->item($backup)
|
||||
->transformWith($this->getTransformer(BackupTransformer::class))
|
||||
->transformWith(BackupTransformer::class)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
@ -123,7 +123,7 @@ class BackupController extends ClientApiController
|
|||
}
|
||||
|
||||
return $this->fractal->item($backup)
|
||||
->transformWith($this->getTransformer(BackupTransformer::class))
|
||||
->transformWith(BackupTransformer::class)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ class DatabaseController extends ClientApiController
|
|||
public function index(GetDatabasesRequest $request, Server $server): array
|
||||
{
|
||||
return $this->fractal->collection($server->databases)
|
||||
->transformWith($this->getTransformer(DatabaseTransformer::class))
|
||||
->transformWith(DatabaseTransformer::class)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ class DatabaseController extends ClientApiController
|
|||
|
||||
return $this->fractal->item($database)
|
||||
->parseIncludes(['password'])
|
||||
->transformWith($this->getTransformer(DatabaseTransformer::class))
|
||||
->transformWith(DatabaseTransformer::class)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,7 @@ class DatabaseController extends ClientApiController
|
|||
|
||||
return $this->fractal->item($database)
|
||||
->parseIncludes(['password'])
|
||||
->transformWith($this->getTransformer(DatabaseTransformer::class))
|
||||
->transformWith(DatabaseTransformer::class)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ class FileController extends ClientApiController
|
|||
->getDirectory($request->get('directory') ?? '/');
|
||||
|
||||
return $this->fractal->collection($contents)
|
||||
->transformWith($this->getTransformer(FileObjectTransformer::class))
|
||||
->transformWith(FileObjectTransformer::class)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
@ -183,7 +183,7 @@ class FileController extends ClientApiController
|
|||
->log();
|
||||
|
||||
return $this->fractal->item($file)
|
||||
->transformWith($this->getTransformer(FileObjectTransformer::class))
|
||||
->transformWith(FileObjectTransformer::class)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ class NetworkAllocationController extends ClientApiController
|
|||
public function index(GetNetworkRequest $request, Server $server): array
|
||||
{
|
||||
return $this->fractal->collection($server->allocations)
|
||||
->transformWith($this->getTransformer(AllocationTransformer::class))
|
||||
->transformWith(AllocationTransformer::class)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ class NetworkAllocationController extends ClientApiController
|
|||
}
|
||||
|
||||
return $this->fractal->item($allocation)
|
||||
->transformWith($this->getTransformer(AllocationTransformer::class))
|
||||
->transformWith(AllocationTransformer::class)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ class NetworkAllocationController extends ClientApiController
|
|||
->log();
|
||||
|
||||
return $this->fractal->item($allocation)
|
||||
->transformWith($this->getTransformer(AllocationTransformer::class))
|
||||
->transformWith(AllocationTransformer::class)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ class NetworkAllocationController extends ClientApiController
|
|||
->log();
|
||||
|
||||
return $this->fractal->item($allocation)
|
||||
->transformWith($this->getTransformer(AllocationTransformer::class))
|
||||
->transformWith(AllocationTransformer::class)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ class ResourceUtilizationController extends ClientApiController
|
|||
});
|
||||
|
||||
return $this->fractal->item($stats)
|
||||
->transformWith($this->getTransformer(StatsTransformer::class))
|
||||
->transformWith(StatsTransformer::class)
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ class ScheduleController extends ClientApiController
|
|||
$schedules = $server->schedules->loadMissing('tasks');
|
||||
|
||||
return $this->fractal->collection($schedules)
|
||||
->transformWith($this->getTransformer(ScheduleTransformer::class))
|
||||
->transformWith(ScheduleTransformer::class)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ class ScheduleController extends ClientApiController
|
|||
->log();
|
||||
|
||||
return $this->fractal->item($model)
|
||||
->transformWith($this->getTransformer(ScheduleTransformer::class))
|
||||
->transformWith(ScheduleTransformer::class)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
@ -88,7 +88,7 @@ class ScheduleController extends ClientApiController
|
|||
$schedule->loadMissing('tasks');
|
||||
|
||||
return $this->fractal->item($schedule)
|
||||
->transformWith($this->getTransformer(ScheduleTransformer::class))
|
||||
->transformWith(ScheduleTransformer::class)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
@ -131,7 +131,7 @@ class ScheduleController extends ClientApiController
|
|||
->log();
|
||||
|
||||
return $this->fractal->item($schedule->refresh())
|
||||
->transformWith($this->getTransformer(ScheduleTransformer::class))
|
||||
->transformWith(ScheduleTransformer::class)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ class ScheduleTaskController extends ClientApiController
|
|||
->log();
|
||||
|
||||
return $this->fractal->item($task)
|
||||
->transformWith($this->getTransformer(TaskTransformer::class))
|
||||
->transformWith(TaskTransformer::class)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
@ -97,7 +97,7 @@ class ScheduleTaskController extends ClientApiController
|
|||
->log();
|
||||
|
||||
return $this->fractal->item($task->refresh())
|
||||
->transformWith($this->getTransformer(TaskTransformer::class))
|
||||
->transformWith(TaskTransformer::class)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ class ServerController extends ClientApiController
|
|||
public function index(GetServerRequest $request, Server $server): array
|
||||
{
|
||||
return $this->fractal->item($server)
|
||||
->transformWith($this->getTransformer(ServerTransformer::class))
|
||||
->transformWith(ServerTransformer::class)
|
||||
->addMeta([
|
||||
'is_server_owner' => $request->user()->id === $server->owner_id,
|
||||
'user_permissions' => $this->permissionsService->handle($server, $request->user()),
|
||||
|
|
|
@ -34,7 +34,7 @@ class StartupController extends ClientApiController
|
|||
return $this->fractal->collection(
|
||||
$server->variables()->where('user_viewable', true)->get()
|
||||
)
|
||||
->transformWith($this->getTransformer(EggVariableTransformer::class))
|
||||
->transformWith(EggVariableTransformer::class)
|
||||
->addMeta([
|
||||
'startup_command' => $startup,
|
||||
'docker_images' => $server->egg->docker_images,
|
||||
|
@ -90,7 +90,7 @@ class StartupController extends ClientApiController
|
|||
}
|
||||
|
||||
return $this->fractal->item($variable)
|
||||
->transformWith($this->getTransformer(EggVariableTransformer::class))
|
||||
->transformWith(EggVariableTransformer::class)
|
||||
->addMeta([
|
||||
'startup_command' => $startup,
|
||||
'raw_startup_command' => $server->startup,
|
||||
|
|
|
@ -38,7 +38,7 @@ class SubuserController extends ClientApiController
|
|||
public function index(GetSubuserRequest $request, Server $server): array
|
||||
{
|
||||
return $this->fractal->collection($server->subusers)
|
||||
->transformWith($this->getTransformer(SubuserTransformer::class))
|
||||
->transformWith(SubuserTransformer::class)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ class SubuserController extends ClientApiController
|
|||
$subuser = $request->attributes->get('subuser');
|
||||
|
||||
return $this->fractal->item($subuser)
|
||||
->transformWith($this->getTransformer(SubuserTransformer::class))
|
||||
->transformWith(SubuserTransformer::class)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ class SubuserController extends ClientApiController
|
|||
->log();
|
||||
|
||||
return $this->fractal->item($response)
|
||||
->transformWith($this->getTransformer(SubuserTransformer::class))
|
||||
->transformWith(SubuserTransformer::class)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
@ -129,7 +129,7 @@ class SubuserController extends ClientApiController
|
|||
$log->reset();
|
||||
|
||||
return $this->fractal->item($subuser->refresh())
|
||||
->transformWith($this->getTransformer(SubuserTransformer::class))
|
||||
->transformWith(SubuserTransformer::class)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue