api(application): v2 backport
This commit is contained in:
parent
4cd0bee231
commit
67bf3e342e
172 changed files with 2922 additions and 1579 deletions
|
@ -2,48 +2,50 @@
|
|||
|
||||
namespace Pterodactyl\Http\Requests\Api\Application\Nodes;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use Pterodactyl\Models\Node;
|
||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
class StoreNodeRequest extends ApplicationApiRequest
|
||||
{
|
||||
protected ?string $resource = AdminAcl::RESOURCE_NODES;
|
||||
|
||||
protected int $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* Validation rules to apply to this request.
|
||||
*/
|
||||
public function rules(array $rules = null): array
|
||||
{
|
||||
return collect($rules ?? Node::getRules())->only([
|
||||
'public',
|
||||
'name',
|
||||
'description',
|
||||
'location_id',
|
||||
'database_host_id',
|
||||
'fqdn',
|
||||
'scheme',
|
||||
'behind_proxy',
|
||||
'maintenance_mode',
|
||||
'public',
|
||||
|
||||
'listen_port_http',
|
||||
'public_port_http',
|
||||
'listen_port_sftp',
|
||||
'public_port_sftp',
|
||||
|
||||
'memory',
|
||||
'memory_overallocate',
|
||||
'disk',
|
||||
'disk_overallocate',
|
||||
'upload_size',
|
||||
'daemonListen',
|
||||
'daemonSFTP',
|
||||
'daemonBase',
|
||||
])->mapWithKeys(function ($value, $key) {
|
||||
$key = ($key === 'daemonSFTP') ? 'daemonSftp' : $key;
|
||||
|
||||
'upload_size',
|
||||
'daemon_base',
|
||||
])->mapWithKeys(function ($value, $key) {
|
||||
return [snake_case($key) => $value];
|
||||
})->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fields to rename for clarity in the API response.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function attributes(): array
|
||||
public function attributes()
|
||||
{
|
||||
return [
|
||||
'daemon_base' => 'Daemon Base Path',
|
||||
|
@ -56,15 +58,20 @@ class StoreNodeRequest extends ApplicationApiRequest
|
|||
/**
|
||||
* Change the formatting of some data keys in the validated response data
|
||||
* to match what the application expects in the services.
|
||||
*
|
||||
* @param string|null $key
|
||||
* @param string|array|null $default
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function validated($key = null, $default = null): array
|
||||
public function validated($key = null, $default = null)
|
||||
{
|
||||
$response = parent::validated();
|
||||
$response['daemonListen'] = $response['daemon_listen'];
|
||||
$response['daemonSFTP'] = $response['daemon_sftp'];
|
||||
$response['daemonBase'] = $response['daemon_base'] ?? (new Node())->getAttribute('daemonBase');
|
||||
$response['daemon_base'] = $response['daemon_base'] ?? Node::DEFAULT_DAEMON_BASE;
|
||||
|
||||
unset($response['daemon_base'], $response['daemon_listen'], $response['daemon_sftp']);
|
||||
if (!is_null($key)) {
|
||||
return Arr::get($response, $key, $default);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue