Skip to content

Commit

Permalink
fix objectUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
freyo committed Apr 8, 2019
1 parent 1bc6b8c commit 73dec73
Showing 1 changed file with 41 additions and 23 deletions.
64 changes: 41 additions & 23 deletions src/Adapter.php
Expand Up @@ -126,12 +126,7 @@ public function getUrl($path)
$this->getBucket(), $path, null, $options
);

$url = parse_url($objectUrl);

return sprintf(
'%s://%s%s',
$url['scheme'], $url['host'], rawurldecode($url['path'])
);
return $objectUrl;
}

/**
Expand All @@ -152,12 +147,7 @@ public function getTemporaryUrl($path, DateTimeInterface $expiration, array $opt
$this->getBucket(), $path, $expiration->format('c'), $options
);

$url = parse_url($objectUrl);

return sprintf(
'%s://%s%s?%s',
$url['scheme'], $url['host'], rawurldecode($url['path']), $url['query']
);
return $objectUrl;
}

/**
Expand Down Expand Up @@ -346,17 +336,9 @@ public function has($path)
public function read($path)
{
try {
if (isset($this->config['read_from_cdn']) && $this->config['read_from_cdn']) {
$response = $this->getHttpClient()
->get($this->applyPathPrefix($path))
->getBody()
->getContents();
} else {
$response = $this->client->getObject([
'Bucket' => $this->getBucket(),
'Key' => $path,
])->get('Body');
}
$response = $this->forceReadFromCDN()
? $this->readFromCDN($path)
: $this->readFromSource($path);

return ['contents' => (string) $response];
} catch (NoSuchKeyException $e) {
Expand All @@ -366,6 +348,42 @@ public function read($path)
}
}

/**
* @return bool
*/
protected function forceReadFromCDN()
{
return $this->config['cdn']
&& isset($this->config['read_from_cdn'])
&& $this->config['read_from_cdn'];
}

/**
* @param $path
*
* @return string
*/
protected function readFromCDN($path)
{
return $this->getHttpClient()
->get($this->applyPathPrefix($path))
->getBody()
->getContents();
}

/**
* @param $path
*
* @return string
*/
protected function readFromSource($path)
{
return $this->client->getObject([
'Bucket' => $this->getBucket(),
'Key' => $path,
])->get('Body');
}

/**
* @return \GuzzleHttp\Client
*/
Expand Down

0 comments on commit 73dec73

Please sign in to comment.