forked from Alex/Pterodactyl-Panel
Update API calls to Wings to only pass the required details with the changes to the installer system
This commit is contained in:
parent
869bc22103
commit
e96ead4c4d
@ -3,7 +3,6 @@
|
|||||||
namespace Pterodactyl\Http\Controllers\Api\Remote\Servers;
|
namespace Pterodactyl\Http\Controllers\Api\Remote\Servers;
|
||||||
|
|
||||||
use Carbon\CarbonImmutable;
|
use Carbon\CarbonImmutable;
|
||||||
use Illuminate\Support\Arr;
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
@ -87,20 +86,7 @@ class ServerTransferController extends Controller
|
|||||||
return $this->processFailedTransfer($server->transfer);
|
return $this->processFailedTransfer($server->transfer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We want to generate a new configuration using the new node_id value from the
|
$this->connection->transaction(function () use ($server) {
|
||||||
// transfer, and not the old node value.
|
|
||||||
$data = $this->configurationStructureService->handle($server, [
|
|
||||||
'node_id' => $server->transfer->new_node,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$allocations = $server->getAllocationMappings();
|
|
||||||
$primary = array_key_first($allocations);
|
|
||||||
Arr::set($data, 'allocations.default.ip', $primary);
|
|
||||||
Arr::set($data, 'allocations.default.port', $allocations[$primary][0]);
|
|
||||||
Arr::set($data, 'service.skip_scripts', true);
|
|
||||||
Arr::set($data, 'suspended', false);
|
|
||||||
|
|
||||||
$this->connection->transaction(function () use ($data, $server) {
|
|
||||||
// This token is used by the new node the server is being transferred to. It allows
|
// This token is used by the new node the server is being transferred to. It allows
|
||||||
// that node to communicate with the old node during the process to initiate the
|
// that node to communicate with the old node during the process to initiate the
|
||||||
// actual file transfer.
|
// actual file transfer.
|
||||||
@ -119,7 +105,7 @@ class ServerTransferController extends Controller
|
|||||||
$this->daemonTransferRepository
|
$this->daemonTransferRepository
|
||||||
->setServer($server)
|
->setServer($server)
|
||||||
->setNode($server->transfer->newNode)
|
->setNode($server->transfer->newNode)
|
||||||
->notify($server, $data, $server->node, $token->toString());
|
->notify($server, $token);
|
||||||
});
|
});
|
||||||
|
|
||||||
return new JsonResponse([], Response::HTTP_NO_CONTENT);
|
return new JsonResponse([], Response::HTTP_NO_CONTENT);
|
||||||
|
@ -35,18 +35,18 @@ class DaemonServerRepository extends DaemonRepository
|
|||||||
*
|
*
|
||||||
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
||||||
*/
|
*/
|
||||||
public function create(array $data): void
|
public function create(bool $startOnCompletion = true): void
|
||||||
{
|
{
|
||||||
Assert::isInstanceOf($this->server, Server::class);
|
Assert::isInstanceOf($this->server, Server::class);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->getHttpClient()->post(
|
$this->getHttpClient()->post('/api/servers', [
|
||||||
'/api/servers',
|
'json' => [
|
||||||
[
|
'uuid' => $this->server->uuid,
|
||||||
'json' => $data,
|
'start_on_completion' => $startOnCompletion,
|
||||||
]
|
],
|
||||||
);
|
]);
|
||||||
} catch (TransferException $exception) {
|
} catch (GuzzleException $exception) {
|
||||||
throw new DaemonConnectionException($exception);
|
throw new DaemonConnectionException($exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,28 +2,31 @@
|
|||||||
|
|
||||||
namespace Pterodactyl\Repositories\Wings;
|
namespace Pterodactyl\Repositories\Wings;
|
||||||
|
|
||||||
use Pterodactyl\Models\Node;
|
use Lcobucci\JWT\Token\Plain;
|
||||||
use Pterodactyl\Models\Server;
|
use Pterodactyl\Models\Server;
|
||||||
use GuzzleHttp\Exception\TransferException;
|
use GuzzleHttp\Exception\GuzzleException;
|
||||||
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
|
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
|
||||||
|
|
||||||
class DaemonTransferRepository extends DaemonRepository
|
class DaemonTransferRepository extends DaemonRepository
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @throws DaemonConnectionException
|
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
||||||
*/
|
*/
|
||||||
public function notify(Server $server, array $data, Node $node, string $token): void
|
public function notify(Server $server, Plain $token): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$this->getHttpClient()->post('/api/transfer', [
|
$this->getHttpClient()->post('/api/transfer', [
|
||||||
'json' => [
|
'json' => [
|
||||||
'server_id' => $server->uuid,
|
'server_id' => $server->uuid,
|
||||||
'url' => $node->getConnectionAddress() . sprintf('/api/servers/%s/archive', $server->uuid),
|
'url' => $server->node->getConnectionAddress() . sprintf('/api/servers/%s/archive', $server->uuid),
|
||||||
'token' => 'Bearer ' . $token,
|
'token' => 'Bearer ' . $token->toString(),
|
||||||
'server' => $data,
|
'server' => [
|
||||||
|
'uuid' => $server->uuid,
|
||||||
|
'start_on_completion' => false,
|
||||||
|
],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
} catch (TransferException $exception) {
|
} catch (GuzzleException $exception) {
|
||||||
throw new DaemonConnectionException($exception);
|
throw new DaemonConnectionException($exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -162,15 +162,10 @@ class ServerCreationService
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$this->daemonServerRepository->setServer($server)->create(
|
$this->daemonServerRepository->setServer($server)->create(
|
||||||
array_merge(
|
Arr::get($data, 'start_on_completion', false) ?? false
|
||||||
$this->configurationStructureService->handle($server),
|
|
||||||
[
|
|
||||||
'start_on_completion' => Arr::get($data, 'start_on_completion', false),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
} catch (DaemonConnectionException $exception) {
|
} catch (DaemonConnectionException $exception) {
|
||||||
$this->serverDeletionService->withForce(true)->handle($server);
|
$this->serverDeletionService->withForce()->handle($server);
|
||||||
|
|
||||||
throw $exception;
|
throw $exception;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user