2017-08-05 17:20:07 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Services\Nodes;
|
|
|
|
|
2020-04-16 20:47:53 -04:00
|
|
|
use Ramsey\Uuid\Uuid;
|
2020-04-10 15:15:38 -07:00
|
|
|
use Illuminate\Support\Str;
|
|
|
|
use Pterodactyl\Models\Node;
|
2020-06-24 21:54:56 -07:00
|
|
|
use Illuminate\Contracts\Encryption\Encrypter;
|
2017-08-05 17:20:07 -05:00
|
|
|
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
|
|
|
|
|
2017-08-27 15:10:51 -05:00
|
|
|
class NodeCreationService
|
2017-08-05 17:20:07 -05:00
|
|
|
{
|
|
|
|
/**
|
2022-10-14 10:59:20 -06:00
|
|
|
* NodeCreationService constructor.
|
2017-08-05 17:20:07 -05:00
|
|
|
*/
|
2022-10-14 10:59:20 -06:00
|
|
|
public function __construct(private Encrypter $encrypter, protected NodeRepositoryInterface $repository)
|
2017-08-05 17:20:07 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new node on the panel.
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
*/
|
2022-10-14 10:59:20 -06:00
|
|
|
public function handle(array $data): Node
|
2017-08-05 17:20:07 -05:00
|
|
|
{
|
2020-04-16 20:47:53 -04:00
|
|
|
$data['uuid'] = Uuid::uuid4()->toString();
|
2020-04-11 20:49:56 -06:00
|
|
|
$data['daemon_token'] = $this->encrypter->encrypt(Str::random(Node::DAEMON_TOKEN_LENGTH));
|
|
|
|
$data['daemon_token_id'] = Str::random(Node::DAEMON_TOKEN_ID_LENGTH);
|
2017-08-05 17:20:07 -05:00
|
|
|
|
2020-04-10 15:15:38 -07:00
|
|
|
return $this->repository->create($data, true, true);
|
2017-08-05 17:20:07 -05:00
|
|
|
}
|
|
|
|
}
|