diff --git a/README.md b/README.md index 1a9a652..e3df7a9 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # Azure Storage Blob filesystem driver for Laravel -[![Latest Version on Packagist](https://img.shields.io/packagist/v/azure-oss/storage-blob-laravel.svg)](https://packagist.org/packages/azure-oss/storage-blob-laravel) -[![Packagist Downloads](https://img.shields.io/packagist/dm/azure-oss/storage-blob-laravel)](https://packagist.org/packages/azure-oss/storage-blob-laravel) +A fork of [Azure-OSS/azure-storage-php-adapter-laravel](https://github.com/Azure-OSS/azure-storage-php-adapter-laravel) with BIIGLE-specific modifications. ## Minimum Requirements @@ -11,7 +10,7 @@ Install the package using composer: ```shell -composer require azure-oss/storage-blob-laravel +composer require biigle/laravel-azure-storage ``` diff --git a/composer.json b/composer.json index 69bdbc4..7d3f875 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "azure-oss/storage-blob-laravel", + "name": "biigle/laravel-azure-storage", "description": "Azure Storage Blob filesystem driver for Laravel", "type": "library", "license": "MIT", @@ -17,6 +17,10 @@ { "name": "Brecht Vermeersch", "email": "brechtvermeersch@outlook.be" + }, + { + "name": "Martin Zurowietz", + "email": "m.zurowietz@uni-bielefeld.de" } ], "require": { diff --git a/src/AzureStorageBlobAdapter.php b/src/AzureStorageBlobAdapter.php index f3334e5..000c3c4 100644 --- a/src/AzureStorageBlobAdapter.php +++ b/src/AzureStorageBlobAdapter.php @@ -4,9 +4,11 @@ use AzureOss\FlysystemAzureBlobStorage\AzureBlobStorageAdapter; use AzureOss\Storage\Blob\BlobServiceClient; +use AzureOss\Storage\Common\Auth\StorageSharedKeyCredential; use Illuminate\Filesystem\FilesystemAdapter; use League\Flysystem\Config; use League\Flysystem\Filesystem; +use League\Flysystem\UnableToGenerateTemporaryUrl; /** * @internal @@ -15,14 +17,22 @@ */ final class AzureStorageBlobAdapter extends FilesystemAdapter { + /** + * Set to true to use the direct public URL instead of generating a temporary URL. + * If true, also acts as a fallback for new temporary URLs if no account credentials + * were provided. + */ + public bool $useDirectPublicUrl; + /** * @param array{connection_string: string, container: string, prefix?: string, root?: string} $config */ public function __construct(array $config) { + $useDirectPublicUrl = $config['use_direct_public_url'] ?? false; $serviceClient = BlobServiceClient::fromConnectionString($config['connection_string']); $containerClient = $serviceClient->getContainerClient($config['container']); - $adapter = new AzureBlobStorageAdapter($containerClient, $config['prefix'] ?? $config['root'] ?? ''); + $adapter = new AzureBlobStorageAdapter($containerClient, $config['prefix'] ?? $config['root'] ?? '', useDirectPublicUrl: $useDirectPublicUrl); parent::__construct( new Filesystem($adapter, $config), @@ -43,7 +53,7 @@ public function url($path) */ public function providesTemporaryUrls() { - return true; + return $this->adapter->containerClient->sharedKeyCredentials instanceof StorageSharedKeyCredential || $this->useDirectPublicUrl; } /** @@ -56,11 +66,19 @@ public function providesTemporaryUrls() /** @phpstan-ignore-next-line */ public function temporaryUrl($path, $expiration, array $options = []) { - return $this->adapter->temporaryUrl( - $path, - $expiration, - new Config(array_merge(['permissions' => 'r'], $options)) - ); + try { + return $this->adapter->temporaryUrl( + $path, + $expiration, + new Config(array_merge(['permissions' => 'r'], $options)) + ); + } catch (UnableToGenerateTemporaryUrl $e) { + if ($this->useDirectPublicUrl) { + return $this->url($path); + } else { + throw $e; + } + } } /**