public static function getDirectFileUrl($path, $disk, $prioritizeSpeed = false)
{
$adapter = $disk->getAdapter();
$fullPath = $adapter->applyPathPrefix($path);
if ($adapter instanceof \League\Flysystem\AwsS3v3\AwsS3Adapter) {
$client = $adapter->getClient();
$command = $client->getCommand('GetObject', ['Bucket' => $adapter->getBucket(), 'Key' => $fullPath]);
return (string) $client->createPresignedRequest($command, '+10 minutes')->getUri();
} else {
if (!$prioritizeSpeed && $adapter instanceof \League\Flysystem\Rackspace\RackspaceAdapter) {
$secret = env('RACKSPACE_TEMP_URL_SECRET');
if ($secret) {
$object = $adapter->getContainer()->getObject($fullPath);
if (env('RACKSPACE_TEMP_URL_SECRET_SET')) {
// Go ahead and set the secret too
$object->getService()->getAccount()->setTempUrlSecret($secret);
}
$url = $object->getUrl();
$expiry = strtotime('+10 minutes');
$urlPath = urldecode($url->getPath());
$body = sprintf("%s\n%d\n%s", 'GET', $expiry, $urlPath);
$hash = hash_hmac('sha1', $body, $secret);
return sprintf('%s?temp_url_sig=%s&temp_url_expires=%d', $url, $hash, $expiry);
}
}
}
return null;
}