Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Http/Requests/Api/Application/Nodes/StoreNodeRequest.php
10280 views
1
<?php
2
3
namespace Pterodactyl\Http\Requests\Api\Application\Nodes;
4
5
use Pterodactyl\Models\Node;
6
use Pterodactyl\Services\Acl\Api\AdminAcl;
7
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
8
9
class StoreNodeRequest extends ApplicationApiRequest
10
{
11
protected ?string $resource = AdminAcl::RESOURCE_NODES;
12
13
protected int $permission = AdminAcl::WRITE;
14
15
/**
16
* Validation rules to apply to this request.
17
*/
18
public function rules(?array $rules = null): array
19
{
20
return collect($rules ?? Node::getRules())->only([
21
'public',
22
'name',
23
'description',
24
'location_id',
25
'fqdn',
26
'scheme',
27
'behind_proxy',
28
'maintenance_mode',
29
'memory',
30
'memory_overallocate',
31
'disk',
32
'disk_overallocate',
33
'upload_size',
34
'daemonListen',
35
'daemonSFTP',
36
'daemonBase',
37
])->mapWithKeys(function ($value, $key) {
38
$key = ($key === 'daemonSFTP') ? 'daemonSftp' : $key;
39
40
return [snake_case($key) => $value];
41
})->toArray();
42
}
43
44
/**
45
* Fields to rename for clarity in the API response.
46
*/
47
public function attributes(): array
48
{
49
return [
50
'daemon_base' => 'Daemon Base Path',
51
'upload_size' => 'File Upload Size Limit',
52
'location_id' => 'Location',
53
'public' => 'Node Visibility',
54
];
55
}
56
57
/**
58
* Change the formatting of some data keys in the validated response data
59
* to match what the application expects in the services.
60
*/
61
public function validated($key = null, $default = null): array
62
{
63
$response = parent::validated();
64
$response['daemonListen'] = $response['daemon_listen'];
65
$response['daemonSFTP'] = $response['daemon_sftp'];
66
$response['daemonBase'] = $response['daemon_base'] ?? (new Node())->getAttribute('daemonBase');
67
68
unset($response['daemon_base'], $response['daemon_listen'], $response['daemon_sftp']);
69
70
return $response;
71
}
72
}
73
74