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
|
|
|
|
2022-02-27 15:50:25 +00:00
|
|
|
use Illuminate\Support\Arr;
|
2018-01-13 20:08:19 +00:00
|
|
|
use Pterodactyl\Models\Node;
|
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
|
|
|
{
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
'name',
|
2021-09-18 17:00:26 +00:00
|
|
|
'description',
|
2018-01-13 20:08:19 +00:00
|
|
|
'location_id',
|
2021-08-02 16:23:58 +00:00
|
|
|
'database_host_id',
|
2018-01-13 20:08:19 +00:00
|
|
|
'fqdn',
|
2021-08-02 16:23:58 +00:00
|
|
|
'scheme',
|
|
|
|
'behind_proxy',
|
|
|
|
'public',
|
|
|
|
|
2021-02-11 17:21:32 +00:00
|
|
|
'listen_port_http',
|
|
|
|
'public_port_http',
|
2021-08-02 16:23:58 +00:00
|
|
|
'listen_port_sftp',
|
2021-02-11 17:21:32 +00:00
|
|
|
'public_port_sftp',
|
2021-08-02 16:23:58 +00:00
|
|
|
|
2018-01-13 20:08:19 +00:00
|
|
|
'memory',
|
|
|
|
'memory_overallocate',
|
|
|
|
'disk',
|
2019-03-02 22:48:05 +00:00
|
|
|
'disk_overallocate',
|
2021-08-02 16:23:58 +00:00
|
|
|
|
2018-01-13 20:08:19 +00:00
|
|
|
'upload_size',
|
2021-02-11 17:21:32 +00:00
|
|
|
'daemon_base',
|
2018-01-13 20:08:19 +00:00
|
|
|
])->mapWithKeys(function ($value, $key) {
|
|
|
|
return [snake_case($key) => $value];
|
|
|
|
})->toArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fields to rename for clarity in the API response.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function attributes()
|
|
|
|
{
|
|
|
|
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-02-27 15:50:25 +00:00
|
|
|
* @param string|null $key
|
|
|
|
* @param string|array|null $default
|
|
|
|
* @return mixed
|
2018-01-13 20:08:19 +00:00
|
|
|
*/
|
2022-02-27 15:50:25 +00:00
|
|
|
public function validated($key = null, $default = null)
|
2018-01-13 20:08:19 +00:00
|
|
|
{
|
|
|
|
$response = parent::validated();
|
2022-02-27 15:50:25 +00:00
|
|
|
$response['daemon_base'] = $response['daemon_base'] ?? Node::DEFAULT_DAEMON_BASE;
|
|
|
|
|
|
|
|
if (!is_null($key)) {
|
|
|
|
return Arr::get($response, $key, $default);
|
|
|
|
}
|
2018-01-13 20:08:19 +00:00
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
}
|