Add base logic to support sending a request to restore a backup for a server

This commit is contained in:
Dane Everitt 2021-01-17 17:51:09 -08:00
parent 805952ac38
commit 87371901c0
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
9 changed files with 229 additions and 237 deletions

View file

@ -2,7 +2,6 @@
namespace Pterodactyl\Repositories\Wings;
use Illuminate\Support\Arr;
use Webmozart\Assert\Assert;
use Pterodactyl\Models\Backup;
use Pterodactyl\Models\Server;
@ -58,6 +57,36 @@ class DaemonBackupRepository extends DaemonRepository
}
}
/**
* Sends a request to Wings to begin restoring a backup for a server.
*
* @param \Pterodactyl\Models\Backup $backup
* @param string|null $url
* @param bool $truncate
* @return \Psr\Http\Message\ResponseInterface
*
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
*/
public function restore(Backup $backup, string $url = null, bool $truncate = false): ResponseInterface
{
Assert::isInstanceOf($this->server, Server::class);
try {
return $this->getHttpClient()->post(
sprintf('/api/servers/%s/backup/%s/restore', $this->server->uuid, $backup->uuid),
[
'json' => [
'adapter' => $backup->disk,
'truncate_directory' => $truncate,
'download_url' => $url ?? '',
],
]
);
} catch (TransferException $exception) {
throw new DaemonConnectionException($exception);
}
}
/**
* Deletes a backup from the daemon.
*