Path: blob/1.0-develop/app/Http/Requests/Api/Application/Nodes/StoreNodeRequest.php
10280 views
<?php12namespace Pterodactyl\Http\Requests\Api\Application\Nodes;34use Pterodactyl\Models\Node;5use Pterodactyl\Services\Acl\Api\AdminAcl;6use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;78class StoreNodeRequest extends ApplicationApiRequest9{10protected ?string $resource = AdminAcl::RESOURCE_NODES;1112protected int $permission = AdminAcl::WRITE;1314/**15* Validation rules to apply to this request.16*/17public function rules(?array $rules = null): array18{19return collect($rules ?? Node::getRules())->only([20'public',21'name',22'description',23'location_id',24'fqdn',25'scheme',26'behind_proxy',27'maintenance_mode',28'memory',29'memory_overallocate',30'disk',31'disk_overallocate',32'upload_size',33'daemonListen',34'daemonSFTP',35'daemonBase',36])->mapWithKeys(function ($value, $key) {37$key = ($key === 'daemonSFTP') ? 'daemonSftp' : $key;3839return [snake_case($key) => $value];40})->toArray();41}4243/**44* Fields to rename for clarity in the API response.45*/46public function attributes(): array47{48return [49'daemon_base' => 'Daemon Base Path',50'upload_size' => 'File Upload Size Limit',51'location_id' => 'Location',52'public' => 'Node Visibility',53];54}5556/**57* Change the formatting of some data keys in the validated response data58* to match what the application expects in the services.59*/60public function validated($key = null, $default = null): array61{62$response = parent::validated();63$response['daemonListen'] = $response['daemon_listen'];64$response['daemonSFTP'] = $response['daemon_sftp'];65$response['daemonBase'] = $response['daemon_base'] ?? (new Node())->getAttribute('daemonBase');6667unset($response['daemon_base'], $response['daemon_listen'], $response['daemon_sftp']);6869return $response;70}71}727374