Add endpoint to pull a remote file down
This commit is contained in:
parent
5d03c0d2e5
commit
087c41d5ac
4 changed files with 68 additions and 13 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue