Add endpoint to pull a remote file down

This commit is contained in:
Dane Everitt 2020-12-24 09:15:03 -08:00
parent 5d03c0d2e5
commit 087c41d5ac
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
4 changed files with 68 additions and 13 deletions

View file

@ -37,7 +37,7 @@ class DaemonFileRepository extends DaemonRepository
throw new DaemonConnectionException($exception);
}
$length = (int) $response->getHeader('Content-Length')[0] ?? 0;
$length = (int)$response->getHeader('Content-Length')[0] ?? 0;
if ($notLargerThan && $length > $notLargerThan) {
throw new FileSizeTooLargeException;
@ -297,4 +297,29 @@ class DaemonFileRepository extends DaemonRepository
throw new DaemonConnectionException($exception);
}
}
/**
* Pulls a file from the given URL and saves it to the disk.
*
* @param string $url
* @param string|null $directory
* @return \Psr\Http\Message\ResponseInterface
*
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
*/
public function pull(string $url, ?string $directory): ResponseInterface
{
Assert::isInstanceOf($this->server, Server::class);
try {
return $this->getHttpClient()->post(
sprintf('/api/servers/%s/files/pull', $this->server->uuid),
[
'json' => ['url' => $url, 'directory' => $directory ?? '/'],
]
);
} catch (TransferException $exception) {
throw new DaemonConnectionException($exception);
}
}
}