2018-01-13 20:08:19 +00:00
|
|
|
<?php
|
|
|
|
|
2018-01-20 01:58:57 +00:00
|
|
|
namespace Pterodactyl\Http\Requests\Api\Application\Nodes;
|
2018-01-13 20:08:19 +00:00
|
|
|
|
|
|
|
use Pterodactyl\Models\Node;
|
|
|
|
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
2018-01-20 03:47:06 +00:00
|
|
|
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
2018-01-13 20:08:19 +00:00
|
|
|
|
2018-01-20 03:47:06 +00:00
|
|
|
class StoreNodeRequest extends ApplicationApiRequest
|
2018-01-13 20:08:19 +00:00
|
|
|
{
|
2022-10-14 16:59:20 +00:00
|
|
|
protected ?string $resource = AdminAcl::RESOURCE_NODES;
|
2018-01-13 20:08:19 +00:00
|
|
|
|
2022-10-14 16:59:20 +00:00
|
|
|
protected int $permission = AdminAcl::WRITE;
|
2018-01-13 20:08:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Validation rules to apply to this request.
|
|
|
|
*/
|
|
|
|
public function rules(array $rules = null): array
|
|
|
|
{
|
2019-09-05 05:26:28 +00:00
|
|
|
return collect($rules ?? Node::getRules())->only([
|
2018-01-13 20:08:19 +00:00
|
|
|
'public',
|
|
|
|
'name',
|
|
|
|
'location_id',
|
|
|
|
'fqdn',
|
|
|
|
'scheme',
|
|
|
|
'behind_proxy',
|
|
|
|
'memory',
|
|
|
|
'memory_overallocate',
|
|
|
|
'disk',
|
2019-03-02 22:48:05 +00:00
|
|
|
'disk_overallocate',
|
2018-01-13 20:08:19 +00:00
|
|
|
'upload_size',
|
|
|
|
'daemonListen',
|
|
|
|
'daemonSFTP',
|
|
|
|
'daemonBase',
|
|
|
|
])->mapWithKeys(function ($value, $key) {
|
|
|
|
$key = ($key === 'daemonSFTP') ? 'daemonSftp' : $key;
|
|
|
|
|
|
|
|
return [snake_case($key) => $value];
|
|
|
|
})->toArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fields to rename for clarity in the API response.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function attributes(): array
|
2018-01-13 20:08:19 +00:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
'daemon_base' => 'Daemon Base Path',
|
|
|
|
'upload_size' => 'File Upload Size Limit',
|
|
|
|
'location_id' => 'Location',
|
|
|
|
'public' => 'Node Visibility',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change the formatting of some data keys in the validated response data
|
|
|
|
* to match what the application expects in the services.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function validated($key = null, $default = null): array
|
2018-01-13 20:08:19 +00:00
|
|
|
{
|
|
|
|
$response = parent::validated();
|
|
|
|
$response['daemonListen'] = $response['daemon_listen'];
|
|
|
|
$response['daemonSFTP'] = $response['daemon_sftp'];
|
2021-01-23 20:33:34 +00:00
|
|
|
$response['daemonBase'] = $response['daemon_base'] ?? (new Node())->getAttribute('daemonBase');
|
2018-01-13 20:08:19 +00:00
|
|
|
|
|
|
|
unset($response['daemon_base'], $response['daemon_listen'], $response['daemon_sftp']);
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
}
|