Restart After Upgrade

This commit is contained in:
SahrulGnwn 2022-08-11 20:50:33 +07:00
parent 5f006ce042
commit 69d9fe5fb0
2 changed files with 18 additions and 0 deletions

View file

@ -33,6 +33,14 @@ class Pterodactyl
])->baseUrl(config("SETTINGS::SYSTEM:PTERODACTYL:URL") . '/api');
}
public static function clientadmin()
{
return Http::withHeaders([
'Authorization' => 'Bearer ' . config("SETTINGS::SYSTEM:PTERODACTYL:ADMIN_USER_TOKEN"),
'Content-type' => 'application/json',
'Accept' => 'Application/vnd.pterodactyl.v1+json',
])->baseUrl(config("SETTINGS::SYSTEM:PTERODACTYL:URL") . '/api');
}
/**
* @return Exception
*/
@ -317,4 +325,11 @@ class Pterodactyl
]
]);
}
public static function powerAction(Server $server, $action)
{
return self::clientadmin()->post("/client/servers/{$server->identifier}/power", [
"signal" => $action
]);
}
}

View file

@ -289,6 +289,9 @@ class ServerController extends Controller
if ($response->failed()) return $this->serverCreationFailed($response, $server);
//update user balance
$user->decrement('credits', $priceupgrade);
//restart the server
$response = Pterodactyl::powerAction($server, "restart");
if ($response->failed()) return $this->serverCreationFailed($response, $server);
return redirect()->route('servers.show', ['server' => $server->id])->with('success', __('Server Successfully Upgraded'));
}
else