Proxy file downloads through the panel rather than having to get creative with download tokens

This commit is contained in:
Dane Everitt 2019-10-26 14:36:37 -07:00
parent 78ccdf93b6
commit 0b9c6bd21d
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
4 changed files with 78 additions and 43 deletions

View file

@ -57,6 +57,29 @@ class DaemonFileRepository extends DaemonRepository
return $response->getBody()->__toString();
}
/**
* Returns a stream of a file's contents back to the calling function to allow
* proxying the request through the Panel rather than needing a direct call to
* the Daemon in order to work.
*
* @param string $path
* @return \Psr\Http\Message\ResponseInterface
*/
public function streamContent(string $path): ResponseInterface
{
Assert::isInstanceOf($this->server, Server::class);
$response = $this->getHttpClient()->get(
sprintf('/api/servers/%s/files/contents', $this->server->uuid),
[
'query' => ['file' => $path, 'download' => true],
'stream' => true,
]
);
return $response;
}
/**
* Save new contents to a given file. This works for both creating and updating
* a file.