misc_pterodactyl-panel/app/Http/Requests/Api/Application/Nodes/StoreNodeRequest.php

72 lines
1.8 KiB
PHP
Raw Normal View History

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-12-15 00:05:46 +00:00
use Illuminate\Support\Arr;
2018-01-13 20:08:19 +00:00
use Pterodactyl\Models\Node;
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
2018-01-13 20:08:19 +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
{
return collect($rules ?? Node::getRules())->only([
2018-01-13 20:08:19 +00:00
'name',
2022-12-15 00:05:46 +00:00
'description',
2018-01-13 20:08:19 +00:00
'location_id',
2022-12-15 00:05:46 +00:00
'database_host_id',
2018-01-13 20:08:19 +00:00
'fqdn',
'scheme',
'behind_proxy',
2022-12-15 00:05:46 +00:00
'public',
'listen_port_http',
'public_port_http',
'listen_port_sftp',
'public_port_sftp',
2018-01-13 20:08:19 +00:00
'memory',
'memory_overallocate',
'disk',
'disk_overallocate',
2022-12-15 00:05:46 +00:00
2018-01-13 20:08:19 +00:00
'upload_size',
2022-12-15 00:05:46 +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.
*/
2022-12-15 01:04:16 +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-12-15 01:04:16 +00:00
public function validated($key = null, $default = null): array
2018-01-13 20:08:19 +00:00
{
$response = parent::validated();
2022-12-15 00:05:46 +00:00
$response['daemon_base'] = $response['daemon_base'] ?? Node::DEFAULT_DAEMON_BASE;
2018-01-13 20:08:19 +00:00
2022-12-15 00:05:46 +00:00
if (!is_null($key)) {
return Arr::get($response, $key, $default);
}
2018-01-13 20:08:19 +00:00
return $response;
}
}